簡體   English   中英

F#數組平面圖

[英]F# array flatmap

我有以下功能:

let fetchTickerGroup (tickers: string[])  (sqlServer:SQLServerClient) (schema: string) = 
tickers |> Array.map(fun x -> sqlServer.FetchTimeSerie(schema,x))

該函數接受一個字符串數組,並通過sqlServer獲取由sqlServer.FetchTimeSerie作為List<b>返回的數據,其中b是自定義對象。 現在,映射數組意味着函數fetchTickerGroup返回List<b>[]

我想知道是否可以flatMap結果,而不僅僅是映射數組值。

我不知道Flatmap是什么,但我認為你想使用*.collect

我認為最好的解決方案就是這樣

tickers |> Array.toList |> List.collect (fun x -> sqlServer.FetchTimeSerie(schema,x))

您需要轉換,以便您只有列表或數組類型

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM