Jeff
09/15/2021, 6:17 AMval someIterable : List<Validated<MyError, String>> // from a map or something similar
someIterable.zip(Semigroup.nonEmptyList<MyError>()} {array -> ... }
//or
Validated.zip(someIterable, se) {array -> ... }
I’m borrowing Rx’s api for zips / FuncN for f.
Is this a JVM optimization? (I’ve seen Clojure do similar overloading instead of a single vararg form)simon.vergauwen
09/15/2021, 7:07 AMzip on Iterable I think you’re looking for traverseXXX.
In case of validated traverseValidated. There is also parTraverseValidated inside Arrow Fx Coroutines in case you want to run validation code in parallel.simon.vergauwen
09/15/2021, 7:09 AMval someIterable: List<String> = ...
fun validate(str: String): ValidatedNel<MyError, String>
someIterable.traverseValidated { str ->
validate(str)
} // ValidatedNel<MyError, String>simon.vergauwen
09/15/2021, 7:10 AMvararg here is because there is a different type in every param.
So you can combine A, B, C into D.
Where with vararg all params have to be of the same type, so you’re restricted to A, A, A into D.simon.vergauwen
09/15/2021, 7:11 AMzip and traverse. With zip you can combine values that of different types, while traverse works on a container (Iterable) which holds values of the same type.Jeff
09/15/2021, 4:20 PM