Link to Snippet

Seq.groupAfter function

This snippet is basically the same as http://fssnip.net/6A, except that the element whose predicate holds ends the previous group and the element after it starts a new one.
Those two snippets (Seq.groupWhen, Seq.groupAfter) would be generally equivalent to the Haskell functions 'breakBefore' and 'breakAfter' from Data.List.Grouping.

moduleSeq=/// Iterates over the elements of the input sequence and groups adjacent/// elements. A new group is started after the specified predicate holds /// about the element of the sequence (and at the beginning of the iteration).letgroupAfterf (input:seq<_>) =useen=input.GetEnumerator()
letrecgroup() =
[ yielden.Currentifnot(fen.Current) &&en.MoveNext() thenyield!group() ]
seq{
whileen.MoveNext() doyieldgroup() |>Seq.ofList }

Iterates over the elements of the input sequence and groups adjacent elements. A new group is started after the specified predicate holds about the element of the sequence (and at the beginning of the iteration).