From defeca2f9dbebfb1c892731836678458680d6972 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 23 Jun 2015 12:14:43 +0200 Subject: [PATCH] pick works like find --- src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs b/src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs index 71f9f99bf0d..55cce3e80c4 100644 --- a/src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs +++ b/src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs @@ -104,6 +104,16 @@ let ``filter and except work similar`` () = Check.QuickThrowOnFailure filter_and_except Check.QuickThrowOnFailure filter_and_except +let find_and_pick<'a when 'a : comparison> (xs : list<'a>) predicate = + let a = runAndCheckIfAnyError (fun () -> List.find predicate xs) + let b = runAndCheckIfAnyError (fun () -> List.pick (fun x -> if predicate x then Some x else None) xs) + a = b + +[] +let ``pick works like find`` () = + Check.QuickThrowOnFailure find_and_pick + Check.QuickThrowOnFailure find_and_pick + Check.QuickThrowOnFailure find_and_pick let choose_and_pick<'a when 'a : comparison> (xs : list<'a>) predicate = let a = runAndCheckIfAnyError (fun () -> List.choose predicate xs |> List.head)