Last active
December 24, 2015 13:49
-
-
Save arturaz/6808298 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def extractEither[ | |
Key, TLeft, TRight, M[_] <: TraversableOnce[_] | |
] | |
(monad: M[(Key, Either[TLeft, TRight])]) | |
(implicit cbf: CanBuildFrom[ | |
M[(Key, Either[TLeft, TRight])], | |
(Key, TRight), | |
M[(Key, TRight)] | |
]): Either[TLeft, M[(Key, TRight)]] = { | |
val builder = cbf(monad) | |
builder.sizeHint(monad.size) | |
monad.foreach { x => | |
// ^___ missing parameter type - why? | |
val (key, either) = x.asInstanceOf[(Key, Either[TLeft, TRight])] | |
either.fold( | |
leftVal => return Left(leftVal), | |
rightVal => builder += ((key, rightVal)) | |
) | |
} | |
Right(builder.result()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment