Skip to content

Instantly share code, notes, and snippets.

@richard-gibson
Created January 11, 2021 09:25
Show Gist options
  • Save richard-gibson/e97e7824dfe80a658077f339730cfee7 to your computer and use it in GitHub Desktop.
Save richard-gibson/e97e7824dfe80a658077f339730cfee7 to your computer and use it in GitHub Desktop.
fun <T> queryUser(s: T?) =
Either.fromNullable(s).mapLeft { "unknown" }
data class Person(val name: String, val age: Int)
val ePerson: Either<String, Person> = Either.applicative<String>().mapN(
queryUser("name"),
queryUser(10)
) { (name, age) -> Person(name, age) }.fix()
val aPerson = Either.applicative<String>().just(Person("foo", 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment