Skip to content

Instantly share code, notes, and snippets.

@eiriktsarpalis
Created November 17, 2014 23:38
Show Gist options
  • Save eiriktsarpalis/85176c2b9e40f418c378 to your computer and use it in GitHub Desktop.
Save eiriktsarpalis/85176c2b9e40f418c378 to your computer and use it in GitHub Desktop.
groupwhile
type Stream<'T> = ('T -> unit) -> unit
module Stream =
let inline groupWhile (pred : 'T -> bool) (source : Stream<'T>) : Stream<'T []> =
fun k ->
let ra = new ResizeArray<'T> ()
let iter (t : 'T) =
if not <| pred t then
k <| ra.ToArray()
ra.Clear()
ra.Add t
source iter
[|1 .. 1000|]
|> Streams.ofArray
|> Streams.groupWhile (fun i -> i % 10 <> 0)
|> Streams.toArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment