1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 

#light

open System.Collections.Generic

let take_while p (ie :> IEnumerable<'a>) =
  seq
    { use e = ie.GetEnumerator()
      while e.MoveNext() && p e.Current do 
        yield e.Current
    }

let Fib = (1,1) |> Seq.unfold (fun (a, b) -> Some (a, (b, (a + b)))) 

let FibBelow n = take_while (fun x -> x < n) Fib ;;

Hope this helps.

By on 4/26/2008 5:50 AM ()

Julien -- sweet!

A nice definition of take_while ~and~ a good demonstration of unfold :)

By on 4/30/2008 5:38 PM ()

Excellent! That's excalty what I need, thank you very much.

By on 4/26/2008 8:26 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper