Dan*_*ter 1 parallel-processing f#
在标准F#库中并行运行以下代码的最轻量级,简洁方法是什么?或者没有任何广泛使用的额外库?
let newlist = oldlist |> List.map myComplexFunction
Run Code Online (Sandbox Code Playgroud)
我能找到的最好的是
let newlist = oldlist |> List.map (fun x -> async { return myComplexFunction x }
|> Async.Parallel
|> Async.RunSynchronously
|> Array.toList
Run Code Online (Sandbox Code Playgroud)
我不喜欢这个,因为它长4行并构造一个数组,然后我必须回到列表中.如果我正在使用Arrays,它将很简单,Array.parallel,但我想保持那个可爱的不可变列表功能纯度.我简直无法相信没有列表替代品,但到目前为止一直无法找到.有什么好建议吗?
使用PSeq模块:
open Microsoft.FSharp.Collections
let newlist =
oldlist
|> PSeq.map myComplexFunction
|> PSeq.toList
Run Code Online (Sandbox Code Playgroud)