Skip to content

Instantly share code, notes, and snippets.

@thinktainer
Created March 5, 2014 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinktainer/9365834 to your computer and use it in GitHub Desktop.
Save thinktainer/9365834 to your computer and use it in GitHub Desktop.
module Seq =
let private spill (n:int) (s:seq<'a>) =
let en = s.GetEnumerator()
let pos = ref 0
let lst = [ while !pos < n && en.MoveNext() do
pos := !pos+1
yield en.Current]
if lst |> List.isEmpty then None else
Some((lst, seq { while en.MoveNext() do yield en.Current}))
[<CompiledName("Batch")>]
let batch (batchSize :int) =
Seq.unfold (spill batchSize)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment