Emil Kantis
val squares = (1..10).mapOrAccumulate { squareService.square(it).bind() } // EitherNel<E1, Square> val roots = (1..10).mapOrAccumulate { rootService.root(it).bind() } // EitherNel<E2, Root> zipOrAccumulate( { // check squares? }, { // check roots? }, { ensureSomethingElse() }, ) { validSquares, validRoots, somethingElse -> // ... }
simon.vergauwen
bind
data class InvalidOperation(val problems: List<String>) InvalidOperation(listOf(invalidRoots.map { "Invalid root: $it" } + invalidSquares.map { "Invalid square: $it }))
Either
mapLeft + bind
val squares = (1..10).mapOrAccumulate { squareService.square(it).bind() } // EitherNel<E1, Square> val roots = (1..10).mapOrAccumulate { rootService.root(it).bind() } // EitherNel<E2, Root> zipOrAccumulate( { squares.mapLeft { }.bind() }, { roots.mapLeft { }.bind() }, { ensureSomethingElse() }, ) { validSquares, validRoots, somethingElse -> // ... }
Either.zipOrAccumulate( squares.mapLeft { }, roots.mapLeft { }, either { ensure(...) { } } ) { a, b, c -> }
A modern programming language that makes developers happier.