Created
November 17, 2014 23:38
-
-
Save eiriktsarpalis/85176c2b9e40f418c378 to your computer and use it in GitHub Desktop.
groupwhile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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