Nullable types give us the ability to have zero or one appearance of a value,
collections allow us to have any number of them. However, in some scenarios, we need to work with collections that should contain at least one element. Arrow provides both
One concrete example is given by error accumulation.
A type like
Either<List<Problem>, Result> may take us to the weird case in
which we end with
Left, but we have no
Problems in the
List. To avoid
this issue, Arrow makes
Either<NonEmptyList<Problem>, Result> instead.
The API of non-empty collections follows the conventions from
On top of that, some types become stronger to ensure or keep track of the
non-empty nature of the collection.
nonEmptySetOfrequire at least one value as argument.
zip, and similar operations which respect the size of the arguments return non-empty collections.
- Concatenation where one of the arguments is non-empty ensures that the result is also non-empty.