Skip to content

Commit

Permalink
iter looks at every element exactly once and in order - consistenly o…
Browse files Browse the repository at this point in the history
…ver all collections
  • Loading branch information
forki committed Jul 29, 2015
1 parent 14abd70 commit af9ef84
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,25 @@ let ``item is consistent`` () =
Check.QuickThrowOnFailure item<string>
Check.QuickThrowOnFailure item<NormalFloat>

let iter<'a when 'a : equality> (xs : 'a []) f' =
let list = System.Collections.Generic.List<'a>()
let f x =
list.Add x
f' x

let s = xs |> Seq.iter f
let l = xs |> List.ofArray |> List.iter f
let a = xs |> Array.iter f

let xs = Seq.toList xs
list |> Seq.toList = (xs @ xs @ xs)

[<Test>]
let ``iter looks at every element exactly once and in order - consistenly over all collections`` () =
Check.QuickThrowOnFailure iter<int>
Check.QuickThrowOnFailure iter<string>
Check.QuickThrowOnFailure iter<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 af9ef84

Please sign in to comment.