mapOrAccumulate
Returns Either a List containing the results of applying the given transform function to each element in the original collection, or accumulate all the logical errors that were raised while transforming the collection using the combine function is used to accumulate all the logical errors.
Within this DSL you can bind
both Either, and EitherNel values and invoke Raise based function of logical error type Error. Let's see an example of all the different cases:
fun test() {
listOf(1, 2, 3, 4).mapOrAccumulate({ a, b -> "$a, $b" }) { i ->
when(i) {
1 -> "Either - $i".left().bind()
2 -> "EitherNel - $i".leftNel().bindNel()
3 -> raise("Raise - $i")
else -> withNel { raise(nonEmptyListOf("RaiseNel - $i")) }
}
} shouldBe "Either - 1, EitherNel - 2, Raise - 3, RaiseNel - 4".left()
}
Returns Either a List containing the results of applying the given transform function to each element in the original collection, or accumulate all the logical errors into a NonEmptyList that were raised while applying the transform function.
Let's see an example of all the different cases:
fun test() {
listOf(1, 2, 3, 4).mapOrAccumulate { i ->
when(i) {
1 -> "Either - $i".left().bind()
2 -> "EitherNel - $i".leftNel().bindNel()
3 -> raise("Raise - $i")
else -> withNel { raise(nonEmptyListOf("RaiseNel - $i")) }
}
} shouldBe nonEmptyListOf("Either - 1", "EitherNel - 2", "Raise - 3", "RaiseNel - 4").left()
}
Deprecated
Deprecated to allow for future alignment with stdlib Map#map returning List
Replace with
mapValuesOrAccumulate(combine, transform)
Deprecated
Deprecated to allow for future alignment with stdlib Map#map returning List
Replace with
mapValuesOrAccumulate(transform)