Skip to content

Instantly share code, notes, and snippets.

@lukestewart13
Last active May 28, 2018 14:45
Show Gist options
  • Save lukestewart13/27507e5082d8067ae5f2ace1553241f3 to your computer and use it in GitHub Desktop.
Save lukestewart13/27507e5082d8067ae5f2ace1553241f3 to your computer and use it in GitHub Desktop.
Either partition
@tailrec def partition[A, B](in: List[Either[A, B]], out: (List[A], List[B]) = (Nil, Nil)): (List[A], List[B]) = in match {
case Nil => out
case Left(a) :: tail => partition(tail, (a :: out._1, out._2))
case Right(b) :: tail => partition(tail, (out._1, b :: out._2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment