Last active
May 28, 2018 14:45
-
-
Save lukestewart13/27507e5082d8067ae5f2ace1553241f3 to your computer and use it in GitHub Desktop.
Either partition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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