Skip to content

Commit

Permalink
tryHead and tail gives the list
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jul 29, 2015
1 parent 64a5fe9 commit aa0edff
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ let ``head and tail gives the list`` () =
Check.QuickThrowOnFailure head_and_tail<string>
Check.QuickThrowOnFailure head_and_tail<NormalFloat>

let tryHead_and_tail<'a when 'a : comparison> (xs : list<'a>) =
match xs with
| [] -> List.tryHead xs = None
| _ ->
let h = (List.tryHead xs).Value
let t = List.tail xs
xs = h :: t

[<Test>]
let ``tryHead and tail gives the list`` () =
Check.QuickThrowOnFailure tryHead_and_tail<int>
Check.QuickThrowOnFailure tryHead_and_tail<string>
Check.QuickThrowOnFailure tryHead_and_tail<NormalFloat>

let skip_and_take<'a when 'a : comparison> (xs : list<'a>) (count:NonNegativeInt) =
let count = int count
if xs <> [] && count <= xs.Length then
Expand Down

0 comments on commit aa0edff

Please sign in to comment.