Skip to content

Commit

Permalink
pick works like find
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jul 29, 2015
1 parent 3af2b4e commit defeca2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ let ``filter and except work similar`` () =
Check.QuickThrowOnFailure filter_and_except<string>
Check.QuickThrowOnFailure filter_and_except<NormalFloat>

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

[<Test>]
let ``pick works like find`` () =
Check.QuickThrowOnFailure find_and_pick<int>
Check.QuickThrowOnFailure find_and_pick<string>
Check.QuickThrowOnFailure find_and_pick<NormalFloat>

let choose_and_pick<'a when 'a : comparison> (xs : list<'a>) predicate =
let a = runAndCheckIfAnyError (fun () -> List.choose predicate xs |> List.head)
Expand Down

0 comments on commit defeca2

Please sign in to comment.