203 people like it.

Haskell function : iterate

Implements iterate function from Haskell's Prelude. The function generates an infinite sequence by applying a function to the initial value (first) and then to the result of previous application.

1: 
2: 
3: 
let rec iterate f value = seq { yield value; yield! iterate f (f value) }

Seq.take 10 (iterate ((*)2) 1) // seq [1; 2; 4; 8; ...]
val iterate : f:('a -> 'a) -> value:'a -> seq<'a>

Full name: Script.iterate
val f : ('a -> 'a)
val value : 'a
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
module Seq

from Microsoft.FSharp.Collections
val take : count:int -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.take
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/18
Posted:13 years ago
Author:Nick Palladinos
Tags: haskell functions , seq