Skip to content

Instantly share code, notes, and snippets.

@hugobenichi
Created February 27, 2014 03:52
Show Gist options
  • Save hugobenichi/9244047 to your computer and use it in GitHub Desktop.
Save hugobenichi/9244047 to your computer and use it in GitHub Desktop.
accum
def accum[X,Y](seed: X, seq: Seq[Y])(fun: (X,Y) => X) =
seq.foldLeft(List[List[X]]()) {
case (Nil, y) => (fun(seed, y) :: Nil) :: Nil
case (buf, y) => (fun(buf.head.head, y) :: buf.head ) :: buf
}
(accum(0, (0 to 10)) { _ + _ }) foreach println
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment