Skip to content

Instantly share code, notes, and snippets.

@akr4
Created August 31, 2011 13:09
Show Gist options
  • Save akr4/1183503 to your computer and use it in GitHub Desktop.
Save akr4/1183503 to your computer and use it in GitHub Desktop.
flatMapSublists?
def flatMapSublists[A,B](ls: List[A])(f: (List[A]) => List[B]): List[B] = {
def sublists[A](ls: List[A]): List[List[A]] = {
ls match {
case Nil => List(List())
case x :: xs => ls :: sublists(xs)
}
}
sublists(ls).flatMap(f)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment