Skip to content

VAVR

Last update: 7 Oct 2022

EITHER

Either.sequence

Reduces many Eithers into a single Either by transforming an Iterable> into a Either, Seq\>.

If any of the given Eithers is a Either.Left then sequence returns a Either.Left containing a non-empty Seq of all left values.

If none of the given Eithers is a Either.Left then sequence returns a Either.Right containing a (possibly empty) Seq of all right values.

Either<Integer, String> e1 = Either.right("ok1");
Either<Integer, String> e2 = Either.right("ok2");
Either<Integer, String> e3 = Either.left(3);
Either<Integer, String> e4 = Either.left(4);

Either<Seq<Integer>,Seq<String> e10 = Either.sequence(List.of(e1, e2)); // e10 = rigth(Seq("ok1", "ok2")

Either<Seq<Integer>,Seq<String> e11 = Either.sequence(List.of(e1, e2, e3, e4)); // e10 = left(Seq(3, 4)

Either.sequenceRigth

Works like Either.sequence if there are no left either.

If there is at least one left, it returns the first one, not all of them as Either.sequence does.