Skip to content

Commit

Permalink
replicate creates n instances of the given element
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jul 29, 2015
1 parent 578a2a4 commit 0656124
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,17 @@ let ``reduceBack works like foldBack with given seed`` () =
Check.QuickThrowOnFailure reduceBack_and_foldBack<string>
Check.QuickThrowOnFailure reduceBack_and_foldBack<NormalFloat>

let replicate<'a when 'a : comparison> (x:'a) (count:NonNegativeInt) =
let count = int count
let xs = List.replicate count x
xs.Length = count && List.forall ((=) x) xs

[<Test>]
let ``replicate creates n instances of the given element`` () =
Check.QuickThrowOnFailure replicate<int>
Check.QuickThrowOnFailure replicate<string>
Check.QuickThrowOnFailure replicate<NormalFloat>

let mapFold_and_map_and_fold<'a when 'a : comparison> (xs : list<'a>) mapF foldF start =
let f s x =
let x' = mapF x
Expand Down

0 comments on commit 0656124

Please sign in to comment.