https://kotlinlang.org logo
#arrow
Title
# arrow
c

conner

10/05/2023, 6:51 PM
is it possible to use
bind
with
Ior
to accumulate an error (on the left) but otherwise continue building the value (and end up with a
Both
)?
@Sam Pengilly did you end up finding a good solution here? 🙂
a

Alejandro Serrano.Mena

10/06/2023, 7:38 AM
There’s an open PR for this functionality https://github.com/arrow-kt/arrow/pull/3114 Maybe you can copy the implementation to your own code until that one is merged and released?
s

Sam Pengilly

10/06/2023, 8:13 AM
That'd be my PR haha. I need to revisit it. It just hasn't been high on my priority list lately. Thinking about it I feel that until we have context receivers, we'll need a new specialised
IorNelRaise
or something, in order to support the sorts of operations necessary to make it comfortable to accumulate errors from different sources inside a builder DSL
Oh, I see this is a different thread to the one I raised a while ago asking about this
The difficulty is in working out the semantics. What makes sense when mapping an Either to an Ior or vice versa. Bind is semantically attached to the short circuit behaviour. So we want to provide a simple right-biased way to bind an either inside an IorRaise block, and maybe a way to bind an Ior inside a normal Raise block for and either DSL. The latter is more challenging because what does it mean if the Ior is in a Both state? Do we right bias still and just discard the error info?
I'll take another stab at it, but from memory I couldn't find a way to easily build a temporary version of it outside of arrow. Since it needs to integrate more closely with types that aren't extendable or visible
5 Views