1 people like it.

Split sequences

Split sequences based on a predicate.

1: 
2: 
3: 
4: 
5: 
6: 
let split (selector:'a->bool) (source:seq<'a>) :seq<seq<'a>>=
  let i = ref 0
  source
  |> Seq.groupBy (fun elem -> if selector elem then incr i
                              !i)
  |> Seq.map snd
val split : selector:('a -> bool) -> source:seq<'a> -> seq<seq<'a>>

Full name: Script.split
val selector : ('a -> bool)
type bool = System.Boolean

Full name: Microsoft.FSharp.Core.bool
val source : seq<'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<_>
val i : int ref
Multiple items
val ref : value:'T -> 'T ref

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

--------------------
type 'T ref = Ref<'T>

Full name: Microsoft.FSharp.Core.ref<_>
module Seq

from Microsoft.FSharp.Collections
val groupBy : projection:('T -> 'Key) -> source:seq<'T> -> seq<'Key * seq<'T>> (requires equality)

Full name: Microsoft.FSharp.Collections.Seq.groupBy
val elem : 'a
val incr : cell:int ref -> unit

Full name: Microsoft.FSharp.Core.Operators.incr
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val snd : tuple:('T1 * 'T2) -> 'T2

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

More information

Link:http://fssnip.net/6z
Posted:12 years ago
Author:Ankur Dhama
Tags: sequences