Created
April 23, 2018 13:12
-
-
Save gbersac/14114f8bf8d0b1c6ea455aacdee0fcd8 to your computer and use it in GitHub Desktop.
cats sequence on either list #scala #cats
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
/* for ammonite users | |
interp.load.ivy("org.typelevel" %% "cats-core" % "1.0.1") | |
interp.configureCompiler(_.settings.YpartialUnification.value = true) | |
@ | |
*/ | |
import cats.instances.list._ | |
import cats.instances.either._ | |
import cats.syntax.traverse._ | |
val seqCorrect: List[Either[String, Int]] = List(Right(1), Right(2), Right(3)) | |
assert(seqCorrect.sequence == Right(List(1, 2, 3))) | |
val seqError: List[Either[String, Int]] = List(Right(1), Right(2), Left("pas glop")) | |
assert(seqError.sequence == Left("pas glop")) | |
val seqError2: List[Either[String, Int]] = List(Right(1), Right(2), Left("pas glop"), Left("pas glop2")) | |
assert(seqError2.sequence == Left("pas glop")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Бля мужик от души спасибо