调用IEnumerable.SelectMany [英] Calling IEnumerable.SelectMany

查看:68
本文介绍了调用IEnumerable.SelectMany的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为此:

open System.Linq

let iota n = [0..(n-1)]

以下内容会产生错误:

[2; 3; 4].SelectMany(fun n -> iota n)

是否可以将函数值传递给SelectMany?

Is there a way to pass function values to SelectMany?

推荐答案

您需要将结果转换为seq<int>:

[2; 3; 4].SelectMany(fun n -> iota n :> int seq)

或者您可以使用List.collect:

[2; 3; 4] |> List.collect iota

这篇关于调用IEnumerable.SelectMany的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆