[英]F# array flatmap
I have the following function: 我有以下功能:
let fetchTickerGroup (tickers: string[]) (sqlServer:SQLServerClient) (schema: string) =
tickers |> Array.map(fun x -> sqlServer.FetchTimeSerie(schema,x))
The function takes an array of strings and, through sqlServer
fetches data which is returned by sqlServer.FetchTimeSerie
as a List<b>
where b
is a custom defined object. 该函数接受一个字符串数组,并通过sqlServer
获取由sqlServer.FetchTimeSerie
作为List<b>
返回的数据,其中b
是自定义对象。 Now, mapping the array means that the function fetchTickerGroup
returns List<b>[]
. 现在,映射数组意味着函数fetchTickerGroup
返回List<b>[]
。
I was wondering if it would be possible to flatMap
the result, rather than just mapping the array values. 我想知道是否可以flatMap
结果,而不仅仅是映射数组值。
I have no Idea what Flatmap
is but I think you want to use *.collect
. 我不知道Flatmap
是什么,但我认为你想使用*.collect
。
I think the best solution would be something like 我认为最好的解决方案就是这样
tickers |> Array.toList |> List.collect (fun x -> sqlServer.FetchTimeSerie(schema,x))
you need to convert so that you have only list or array types 您需要转换,以便您只有列表或数组类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.