Skip to content
zvozin edited this page Apr 13, 2017 · 3 revisions

An ad-hoc Either can be created the usual way:

    val left: Either<Int, String> = left("wrong")
    val right: Either<Int, String> = right(1)

An Either can be converted into a Validation:

    val valid: Validation<Int, String> = right(1).validation()
    val invalid: Validation<Int, String> = left("your value still sucks").validation()

A Kotlin Iterable of Eithers can be sequenced as follows:

    val eitherOfSeq: Either<List<Int>, Seq<String>> = listOf(left("still does"), right(1)).sequence() 
Clone this wiki locally