Skip to content

Instantly share code, notes, and snippets.

@gbersac
Created April 23, 2018 13:12
Show Gist options
  • Save gbersac/14114f8bf8d0b1c6ea455aacdee0fcd8 to your computer and use it in GitHub Desktop.
Save gbersac/14114f8bf8d0b1c6ea455aacdee0fcd8 to your computer and use it in GitHub Desktop.
cats sequence on either list #scala #cats
/* 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"))
@arseny-stoyalov
Copy link

Бля мужик от души спасибо

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment