arrow-kt / arrow

Λrrow - Functional companion to Kotlin's Standard Library
http://arrow-kt.io
Other
6.13k stars 442 forks source link

Ior mapOrAccumulate #3472

Open sampengilly opened 1 month ago

sampengilly commented 1 month ago

Add support for mapOrAccumulate functions which when run inside an IorRaise scope accumulate errors into a Both case with the combined errors and any successfully mapped items.

This change adds the basic mapOrAccumulate functions, it doesn't provide any additional convenience functions like those which take an Iterable<T> receiver such as those found in Iterable.kt. As I see it, in order to provide those functions we'd either need to wait for context parameters, or move each of those existing functions into the Raise interface and define the new ones in the IorRaise class.

I also haven't included the zipOrAccumulate functions in this change. I intend to do those as it feels like a use case which makes sense (carry out N operations, collect the errors, but if some succeeded then treat it as a success overall).

sampengilly commented 1 month ago

Looking at it again. I don't think that zipOrAccumulate makes sense for IorRaise as it's essentially an applicative, the final builder block only makes sense if all of the inputs have succeeded, there doesn't seem to be any room for a partial success that can be represented by an Ior in that case.