Skip to content

Commit 0b1b32d

Browse files
Need that
1 parent affc14d commit 0b1b32d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/FSharp.Core/array.fs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2208,21 +2208,22 @@ module Array =
22082208
[<CompiledName("TryPick")>]
22092209
let tryPick chooser (array: _ array) =
22102210
checkNonNull "array" array
2211-
let mutable chosen = None
2211+
let allChosen = System.Collections.Concurrent.ConcurrentDictionary()
22122212

2213-
let _pResult =
2213+
let pResult =
22142214
Parallel.For(
22152215
0,
22162216
array.Length,
22172217
(fun i pState ->
22182218
match chooser array[i] with
22192219
| None -> ()
22202220
| chosenElement ->
2221-
ignore (Interlocked.Exchange(&chosen, chosenElement))
2221+
allChosen[i] <- chosenElement
22222222
pState.Break())
22232223
)
22242224

2225-
chosen
2225+
if pResult.LowestBreakIteration.HasValue then allChosen[int (pResult.LowestBreakIteration.GetValueOrDefault())]
2226+
else None
22262227

22272228
[<CompiledName("Choose")>]
22282229
let choose chooser (array: 'T array) =

0 commit comments

Comments
 (0)