Skip to content

Commit

Permalink
mapFold is consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jul 29, 2015
1 parent 2673074 commit b7780de
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,19 @@ let ``map3 looks at every element exactly once and in order - consistenly over a
Check.QuickThrowOnFailure map3<string>
Check.QuickThrowOnFailure map3<NormalFloat>

let mapFold<'a when 'a : equality> (xs : 'a []) f start =
let s,sr = xs |> Seq.mapFold f start
let l,lr = xs |> List.ofArray |> List.mapFold f start
let a,ar = xs |> Array.mapFold f start
Seq.toArray s = a && List.toArray l = a &&
sr = lr && sr = ar

[<Test>]
let ``mapFold is consistent`` () =
Check.QuickThrowOnFailure mapFold<int>
Check.QuickThrowOnFailure mapFold<string>
Check.QuickThrowOnFailure mapFold<NormalFloat>

let sort<'a when 'a : comparison> (xs : 'a []) =
let s = xs |> Seq.sort
let l = xs |> List.ofArray |> List.sort
Expand Down

0 comments on commit b7780de

Please sign in to comment.