Skip to content

Commit b87ca33

Browse files
authored
Array.Parallel - search functions (tryFindIndex,tryFind,tryPick) (#14827)
* Searching functions for Array.Parallel added * with [<Experimental("Experimental library feature, requires '--langversion:preview'")>] annotation to give us space to change/remove this API in the future if needed
1 parent efe9476 commit b87ca33

File tree

9 files changed

+192
-23
lines changed

9 files changed

+192
-23
lines changed

src/FSharp.Core/array.fs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,46 @@ module Array =
19341934
module Parallel =
19351935
open System.Threading.Tasks
19361936

1937+
[<CompiledName("TryFindIndex")>]
1938+
let tryFindIndex predicate (array: _[]) =
1939+
checkNonNull "array" array
1940+
1941+
let pResult =
1942+
Parallel.For(
1943+
0,
1944+
array.Length,
1945+
(fun i pState ->
1946+
if predicate array[i] then
1947+
pState.Break())
1948+
)
1949+
1950+
pResult.LowestBreakIteration |> Option.ofNullable |> Option.map int
1951+
1952+
[<CompiledName("TryFind")>]
1953+
let tryFind predicate (array: _[]) =
1954+
array |> tryFindIndex predicate |> Option.map (fun i -> array[i])
1955+
1956+
[<CompiledName("TryPick")>]
1957+
let tryPick chooser (array: _[]) =
1958+
checkNonNull "array" array
1959+
let allChosen = new System.Collections.Concurrent.ConcurrentDictionary<_, _>()
1960+
1961+
let pResult =
1962+
Parallel.For(
1963+
0,
1964+
array.Length,
1965+
(fun i pState ->
1966+
match chooser array[i] with
1967+
| None -> ()
1968+
| chosenElement ->
1969+
allChosen[i] <- chosenElement
1970+
pState.Break())
1971+
)
1972+
1973+
pResult.LowestBreakIteration
1974+
|> Option.ofNullable
1975+
|> Option.bind (fun i -> allChosen[int i])
1976+
19371977
[<CompiledName("Choose")>]
19381978
let choose chooser (array: 'T[]) =
19391979
checkNonNull "array" array

src/FSharp.Core/array.fsi

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,102 @@ module Array =
30943094
/// <summary>Provides parallel operations on arrays </summary>
30953095
module Parallel =
30963096

3097+
/// <summary>Returns the first element for which the given function returns <c>True</c>.
3098+
/// Returns None if no such element exists.</summary>
3099+
///
3100+
/// <param name="predicate">The function to test the input elements.</param>
3101+
/// <param name="array">The input array.</param>
3102+
///
3103+
/// <returns>The first element that satisfies the predicate, or None.</returns>
3104+
///
3105+
/// <exception cref="T:System.ArgumentNullException">Thrown when the input array is null.</exception>
3106+
///
3107+
/// <example id="para-tryfind-1">Try to find the first even number:
3108+
/// <code lang="fsharp">
3109+
/// let inputs = [| 1; 2; 3 |]
3110+
///
3111+
/// inputs |> Array.Parallel.tryFind (fun elm -> elm % 2 = 0)
3112+
/// </code>
3113+
/// Evaluates to <c>Some 2</c>.
3114+
/// </example>
3115+
///
3116+
/// <example id="para-tryfind-2">Try to find the first even number:
3117+
/// <code lang="fsharp">
3118+
/// let inputs = [| 1; 5; 3 |]
3119+
///
3120+
/// inputs |> Array.Parallel.tryFind (fun elm -> elm % 2 = 0)
3121+
/// </code>
3122+
/// Evaluates to <c>None</c>
3123+
/// </example>
3124+
[<CompiledName("TryFind")>]
3125+
[<Experimental("Experimental library feature, requires '--langversion:preview'")>]
3126+
val tryFind: predicate:('T -> bool) -> array:'T[] -> 'T option
3127+
3128+
3129+
/// <summary>Returns the index of the first element in the array
3130+
/// that satisfies the given predicate.
3131+
/// Returns <c>None</c> if no such element exists.</summary>
3132+
/// <param name="predicate">The function to test the input elements.</param>
3133+
/// <param name="array">The input array.</param>
3134+
///
3135+
/// <exception cref="T:System.ArgumentNullException">Thrown when the input array is null.</exception>
3136+
///
3137+
/// <returns>The index of the first element that satisfies the predicate, or None.</returns>
3138+
///
3139+
/// <example id="para-tryfindindex-1">Try to find the index of the first even number:
3140+
/// <code lang="fsharp">
3141+
/// let inputs = [| 1; 2; 3; 4; 5 |]
3142+
///
3143+
/// inputs |> Array.Parallel.tryFindIndex (fun elm -> elm % 2 = 0)
3144+
/// </code>
3145+
/// Evaluates to <c>Some 1</c>
3146+
/// </example>
3147+
///
3148+
/// <example id="para-tryfindindex-2">Try to find the index of the first even number:
3149+
/// <code lang="fsharp">
3150+
/// let inputs = [| 1; 3; 5; 7 |]
3151+
///
3152+
/// inputs |> Array.Parallel.tryFindIndex (fun elm -> elm % 2 = 0)
3153+
/// </code>
3154+
/// Evaluates to <c>None</c>
3155+
/// </example>
3156+
[<CompiledName("TryFindIndex")>]
3157+
[<Experimental("Experimental library feature, requires '--langversion:preview'")>]
3158+
val tryFindIndex : predicate:('T -> bool) -> array:'T[] -> int option
3159+
3160+
/// <summary>Applies the given function to successive elements, returning the first
3161+
/// result where the function returns <c>Some(x)</c> for some <c>x</c>. If the function
3162+
/// never returns <c>Some(x)</c> then <c>None</c> is returned.</summary>
3163+
///
3164+
/// <param name="chooser">The function to transform the array elements into options.</param>
3165+
/// <param name="array">The input array.</param>
3166+
///
3167+
/// <returns>The first transformed element that is <c>Some(x)</c>.</returns>
3168+
///
3169+
/// <exception cref="T:System.ArgumentNullException">Thrown when the input array is null.</exception>
3170+
///
3171+
/// <example id="para-trypick-1">
3172+
/// <code lang="fsharp">
3173+
/// let input = [| 1; 2; 3 |]
3174+
///
3175+
/// input |> Array.Parallel.tryPick (fun n -> if n % 2 = 0 then Some (string n) else None)
3176+
/// </code>
3177+
/// Evaluates to <c>Some 2</c>.
3178+
/// </example>
3179+
///
3180+
/// <example id="para-trypick-2">
3181+
/// <code lang="fsharp">
3182+
/// let input = [| 1; 2; 3 |]
3183+
///
3184+
/// input |> Array.Parallel.tryPick (fun n -> if n > 3 = 0 then Some (string n) else None)
3185+
/// </code>
3186+
/// Evaluates to <c>None</c>.
3187+
/// </example>
3188+
///
3189+
[<CompiledName("TryPick")>]
3190+
[<Experimental("Experimental library feature, requires '--langversion:preview'")>]
3191+
val tryPick: chooser:('T -> 'U option) -> array:'T[] -> 'U option
3192+
30973193
/// <summary>Apply the given function to each element of the array. Return
30983194
/// the array comprised of the results <c>x</c> for each element where
30993195
/// the function returns <c>Some(x)</c>.</summary>

tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard20.debug.bsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Microsoft.FSharp.Collections.Array4DModule: T[,,,] Create[T](Int32, Int32, Int32
4040
Microsoft.FSharp.Collections.Array4DModule: T[,,,] Initialize[T](Int32, Int32, Int32, Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T]]]])
4141
Microsoft.FSharp.Collections.Array4DModule: T[,,,] ZeroCreate[T](Int32, Int32, Int32, Int32)
4242
Microsoft.FSharp.Collections.Array4DModule: Void Set[T](T[,,,], Int32, Int32, Int32, Int32, T)
43+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] TryFindIndex[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
44+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[TResult] TryPick[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[])
45+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[T] TryFind[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
4346
Microsoft.FSharp.Collections.ArrayModule+Parallel: System.Tuple`2[T[],T[]] Partition[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
4447
Microsoft.FSharp.Collections.ArrayModule+Parallel: TResult[] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[])
4548
Microsoft.FSharp.Collections.ArrayModule+Parallel: TResult[] Collect[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult[]], T[])

tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard20.release.bsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Microsoft.FSharp.Collections.Array4DModule: T[,,,] Create[T](Int32, Int32, Int32
4040
Microsoft.FSharp.Collections.Array4DModule: T[,,,] Initialize[T](Int32, Int32, Int32, Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T]]]])
4141
Microsoft.FSharp.Collections.Array4DModule: T[,,,] ZeroCreate[T](Int32, Int32, Int32, Int32)
4242
Microsoft.FSharp.Collections.Array4DModule: Void Set[T](T[,,,], Int32, Int32, Int32, Int32, T)
43+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] TryFindIndex[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
44+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[TResult] TryPick[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[])
45+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[T] TryFind[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
4346
Microsoft.FSharp.Collections.ArrayModule+Parallel: System.Tuple`2[T[],T[]] Partition[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
4447
Microsoft.FSharp.Collections.ArrayModule+Parallel: TResult[] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[])
4548
Microsoft.FSharp.Collections.ArrayModule+Parallel: TResult[] Collect[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult[]], T[])

tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.debug.bsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Microsoft.FSharp.Collections.Array4DModule: T[,,,] Create[T](Int32, Int32, Int32
4040
Microsoft.FSharp.Collections.Array4DModule: T[,,,] Initialize[T](Int32, Int32, Int32, Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T]]]])
4141
Microsoft.FSharp.Collections.Array4DModule: T[,,,] ZeroCreate[T](Int32, Int32, Int32, Int32)
4242
Microsoft.FSharp.Collections.Array4DModule: Void Set[T](T[,,,], Int32, Int32, Int32, Int32, T)
43+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] TryFindIndex[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
44+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[TResult] TryPick[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[])
45+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[T] TryFind[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
4346
Microsoft.FSharp.Collections.ArrayModule+Parallel: System.Tuple`2[T[],T[]] Partition[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
4447
Microsoft.FSharp.Collections.ArrayModule+Parallel: TResult[] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[])
4548
Microsoft.FSharp.Collections.ArrayModule+Parallel: TResult[] Collect[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult[]], T[])

tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Microsoft.FSharp.Collections.Array4DModule: T[,,,] Create[T](Int32, Int32, Int32
4040
Microsoft.FSharp.Collections.Array4DModule: T[,,,] Initialize[T](Int32, Int32, Int32, Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T]]]])
4141
Microsoft.FSharp.Collections.Array4DModule: T[,,,] ZeroCreate[T](Int32, Int32, Int32, Int32)
4242
Microsoft.FSharp.Collections.Array4DModule: Void Set[T](T[,,,], Int32, Int32, Int32, Int32, T)
43+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] TryFindIndex[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
44+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[TResult] TryPick[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[])
45+
Microsoft.FSharp.Collections.ArrayModule+Parallel: Microsoft.FSharp.Core.FSharpOption`1[T] TryFind[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
4346
Microsoft.FSharp.Collections.ArrayModule+Parallel: System.Tuple`2[T[],T[]] Partition[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
4447
Microsoft.FSharp.Collections.ArrayModule+Parallel: TResult[] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[])
4548
Microsoft.FSharp.Collections.ArrayModule+Parallel: TResult[] Collect[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult[]], T[])

tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -955,17 +955,16 @@ type ArrayModule() =
955955
let intArr = [| 1..10 |]
956956
let seq = Array.toSeq intArr
957957
let sum = Seq.sum seq
958-
Assert.AreEqual(55, sum)
959-
960-
[<Fact>]
961-
member this.TryPick() =
958+
Assert.AreEqual(55, sum)
959+
960+
member private _.TryPickTester tryPickInt tryPickString =
962961
// integer array
963962
let intArr = [| 1..10 |]
964963
let funcInt x =
965964
match x with
966965
| _ when x % 3 = 0 -> Some (x.ToString())
967966
| _ -> None
968-
let resultInt = Array.tryPick funcInt intArr
967+
let resultInt = tryPickInt funcInt intArr
969968
if resultInt <> Some "3" then Assert.Fail()
970969

971970
// string array
@@ -974,20 +973,26 @@ type ArrayModule() =
974973
match x with
975974
| "good" -> Some (x.ToString())
976975
| _ -> None
977-
let resultStr = Array.tryPick funcStr strArr
976+
let resultStr = tryPickString funcStr strArr
978977
if resultStr <> None then Assert.Fail()
979978

980979
// empty array
981980
let emptyArr:int[] = [| |]
982-
let resultEpt = Array.tryPick funcInt emptyArr
981+
let resultEpt = tryPickInt funcInt emptyArr
983982
if resultEpt <> None then Assert.Fail()
984983

985984
// null array
986985
let nullArr = null:string[]
987-
CheckThrowsArgumentNullException (fun () -> Array.tryPick funcStr nullArr |> ignore)
986+
CheckThrowsArgumentNullException (fun () -> tryPickString funcStr nullArr |> ignore)
988987

989988
()
990989

990+
[<Fact>]
991+
member this.TryPick() = this.TryPickTester Array.tryPick Array.tryPick
992+
993+
[<Fact>]
994+
member this.ParallelTryPick() = this.TryPickTester Array.Parallel.tryPick Array.Parallel.tryPick
995+
991996
[<Fact>]
992997
member this.Fold() =
993998
// integer array

tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -972,25 +972,31 @@ type ArrayModule2() =
972972

973973
()
974974

975-
[<Fact>]
976-
member this.TryFind() =
975+
member private _.TryFindTester tryFindInts tryFindStrings =
977976
// integer array
978-
let resultInt = [|1..10|] |> Array.tryFind (fun x -> x%7 = 0)
977+
let resultInt = [|1..10|] |> tryFindInts (fun x -> x%7 = 0)
979978
if resultInt <> Some 7 then Assert.Fail()
980979

981980
// string array
982-
let resultStr = [|"Lists"; "are"; "commonly" ; "list" |] |> Array.tryFind (fun (x:string) -> x.Length > 4)
981+
let resultStr = [|"Lists"; "are"; "commonly" ; "list" |] |> tryFindStrings (fun (x:string) -> x.Length > 4)
983982
if resultStr <> Some "Lists" then Assert.Fail()
984983

985984
// empty array
986-
let resultEpt =[||] |> Array.tryFind (fun x -> x%7 = 0)
985+
let resultEpt =[||] |> tryFindInts (fun x -> x%7 = 0)
987986
if resultEpt <> None then Assert.Fail()
988987

989988
// null array
990989
let nullArr = null:string[]
991-
CheckThrowsArgumentNullException (fun () -> Array.tryFind (fun (x:string) -> x.Length > 4) nullArr |> ignore)
990+
CheckThrowsArgumentNullException (fun () -> tryFindStrings (fun (x:string) -> x.Length > 4) nullArr |> ignore)
992991

993992
()
993+
994+
[<Fact>]
995+
member this.TryFind() = this.TryFindTester Array.tryFind Array.tryFind
996+
997+
[<Fact>]
998+
member this.ParallelTryFind() = this.TryFindTester Array.Parallel.tryFind Array.Parallel.tryFind
999+
9941000

9951001
[<Fact>]
9961002
member this.TryFindBack() =
@@ -1016,26 +1022,30 @@ type ArrayModule2() =
10161022

10171023
()
10181024

1019-
[<Fact>]
1020-
member this.TryFindIndex() =
1025+
member private _.TryFindIndexTester tryFindIdxInt tryFindIdxString =
10211026
// integer array
1022-
let resultInt = [|1..10|] |> Array.tryFindIndex (fun x -> x%7 = 0)
1027+
let resultInt = [|1..10|] |> tryFindIdxInt (fun x -> x%7 = 0)
10231028
if resultInt <> Some 6 then Assert.Fail()
10241029

10251030
// string array
1026-
let resultStr = [|"Lists"; "are"; "commonly" ; "list" |] |> Array.tryFindIndex (fun (x:string) -> x.Length > 4)
1031+
let resultStr = [|"Lists"; "are"; "commonly" ; "list" |] |> tryFindIdxString (fun (x:string) -> x.Length > 4)
10271032
if resultStr <> Some 0 then Assert.Fail()
10281033

10291034
// empty array
1030-
let resultEpt =[||] |> Array.tryFindIndex (fun x -> x % 7 = 0)
1035+
let resultEpt =[||] |> tryFindIdxInt (fun x -> x % 7 = 0)
10311036
if resultEpt <> None then Assert.Fail()
10321037

10331038
// null array
10341039
let nullArr = null:string[]
1035-
CheckThrowsArgumentNullException (fun () -> Array.tryFindIndex (fun (x:string) -> x.Length > 4) nullArr |> ignore)
1040+
CheckThrowsArgumentNullException (fun () -> tryFindIdxString (fun (x:string) -> x.Length > 4) nullArr |> ignore)
10361041

10371042
()
10381043

1044+
[<Fact>]
1045+
member this.TryFindIndex() = this.TryFindIndexTester Array.tryFindIndex Array.tryFindIndex
1046+
1047+
[<Fact>]
1048+
member this.ParallelTryFindIndex() = this.TryFindIndexTester Array.Parallel.tryFindIndex Array.Parallel.tryFindIndex
10391049
[<Fact>]
10401050
member this.TryFindIndexBack() =
10411051
// integer array

tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/CollectionModulesConsistency.fs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ let consistency name sqs ls arr =
1414
(sqs = arr) |@ (sprintf "Seq.%s = '%A', Array.%s = '%A'" name sqs name arr) .&.
1515
(ls = arr) |@ (sprintf "List.%s = '%A', Array.%s = '%A'" name ls name arr)
1616

17+
let consistencyIncludingParallel name sqs ls arr paraArr =
18+
consistency name sqs ls arr .&.
19+
(paraArr = arr) |@ (sprintf "Parallel.%s = '%A', Array.%s = '%A'" name paraArr name arr)
1720

1821
let allPairs<'a when 'a : equality> (xs : list<'a>) (xs2 : list<'a>) =
1922
let s = xs |> Seq.allPairs xs2 |> Seq.toArray
@@ -1104,7 +1107,8 @@ let tryFind<'a when 'a : equality> (xs : 'a []) predicate =
11041107
let s = xs |> Seq.tryFind predicate
11051108
let l = xs |> List.ofArray |> List.tryFind predicate
11061109
let a = xs |> Array.tryFind predicate
1107-
consistency "tryFind" s l a
1110+
let pa = xs |> Array.Parallel.tryFind predicate
1111+
consistencyIncludingParallel "tryFind" s l a pa
11081112

11091113
[<Fact>]
11101114
let ``tryFind is consistent`` () =
@@ -1128,7 +1132,8 @@ let tryFindIndex<'a when 'a : equality> (xs : 'a []) predicate =
11281132
let s = xs |> Seq.tryFindIndex predicate
11291133
let l = xs |> List.ofArray |> List.tryFindIndex predicate
11301134
let a = xs |> Array.tryFindIndex predicate
1131-
consistency "tryFindIndex" s l a
1135+
let pa = xs |> Array.Parallel.tryFindIndex predicate
1136+
consistencyIncludingParallel "tryFindIndex" s l a pa
11321137

11331138
[<Fact>]
11341139
let ``tryFindIndex is consistent`` () =
@@ -1188,7 +1193,8 @@ let tryPick<'a when 'a : comparison> (xs : 'a []) f =
11881193
let s = xs |> Seq.tryPick f
11891194
let l = xs |> List.ofArray |> List.tryPick f
11901195
let a = xs |> Array.tryPick f
1191-
consistency "tryPick" s l a
1196+
let pa = xs |> Array.Parallel.tryPick f
1197+
consistencyIncludingParallel "tryPick" s l a pa
11921198

11931199
[<Fact>]
11941200
let ``tryPick is consistent`` () =

0 commit comments

Comments
 (0)