Hello! First of all we introduced arrow-core into ...
# arrow
a
Hello! First of all we introduced arrow-core into my team when creating a new service, and we’re having a great time and love it! Sorry to bother with a question, and maybe it’s my lack of knowledge, but if I have something as follows in my domain as a value object
Copy code
data class FooList(val values: Set<Foo>) : Set<Foo> by values {
    companion object {
        fun bar(fooValues: Set<String>): EitherNel<Foo.FooError, FooList> = either {
            FooList(
                fooValues.mapOrAccumulate { Foo.fromUser(it).bind() }.bind().toSet()
            )
        }
    }
}
Where
Foo.fromUser
returns an
Either<FooError, Foo>
I’m trying to iterate through the fooValues and while creating Foo Objects, validating them and adding up the errors. (Have to do it inside Foo for reasons) My question is, is there a cleaner way to implement this? I thought I could use map and then bindAll() here but it wasn’t possible, seems like this mapOrAccumulate with two binds is the best option? Sorry if it’s a stupid question, but thank you in advance for the response! arrow
😍 1
c
I'm on mobile so I can't provide the full example, but one way to simplify this would be to switch overloads. You're currently using https://apidocs.arrow-kt.io/arrow-core/arrow.core/map-or-accumulate.html, but if you were using https://apidocs.arrow-kt.io/arrow-core/arrow.core.raise/-raise-accumulate/map-or-accumulate.html then you wouldn't need the
.bind
today i learned 1
1
Also, if you switch Foo.fromUser from returning Either to having a receiver in Raise, then you can remove the other Raise
👀 1
a
Thank you Ivan! This is exactly what I was looking for, I appreciate it Still learning arrow day by day 😅
c
In the future, programs will change from using Either everywhere to just declaring a Raise receiver everywhere and rarely using Either at all. Right now, it's a bit awkward in some situations because we can only have a single receiver, but it's going to be more and more natural as context parameters arrive.
arrow 1
K 1
a
I saw that in Ricardo Cardin’s blog in rockthejvm, Can’t wait for context receivers to stop being experimental
❤️ 1
c
Same. But don't be too impatient, it's at the very least 1 or 2 years away 😅
🥲 2