What is the most lightweight, terse way to run the following code in parallel within the standard F# libs? Or failing that any widely used additional libs?
let newlist = oldlist |> List.map myComplexFunction
The best I could find was
let newlist = oldlist |> List.map (fun x -> async { return myComplexFunction x }
|> Async.Parallel
|> Async.RunSynchronously
|> Array.toList
I don't like this because it's 4 lines long and constructs an array that I then have to make back into a list. If I were working with Arrays it would be simple, Array.parallel, but I want to keep that lovely Immutable list functional purity. I just can't believe there is no list alternative, but so far have been unable to find one. Any good suggestions?
Use the PSeq module:
open Microsoft.FSharp.Collections
let newlist =
oldlist
|> PSeq.map myComplexFunction
|> PSeq.toList
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With