Skip to content

Instantly share code, notes, and snippets.

@okomok
Created February 1, 2009 15:49
Show Gist options
  • Save okomok/55884 to your computer and use it in GitHub Desktop.
Save okomok/55884 to your computer and use it in GitHub Desktop.
fold using reduce
private[mada] object Fold {
def apply[A](v: Vector[A], z: A, op: (A, A) => A): A = {
(Vector.single(z) ++ v).reduce(op)
}
}
private[mada] object Folder {
def apply[A](v: Vector[A], z: A, op: (A, A) => A): Vector[A] = {
(Vector.single(z) ++ v).reducer(op)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment