Hi guys, We're starting to use arrow on my project...
# arrow
j
Hi guys, We're starting to use arrow on my project but I'm realizing I'm seriously rusty with my eithers 😞 Trying to transform a result of type
Either<Error, List<A>>
into
Either<Error, List<B>>
So far I have :
call.map { it.map { B(a.value) } }
Seems to me like there should be something simpler but I can't for the life of me find it 😅
y
That's probably the easiest way, but you can also do
Copy code
either {
  call.bind().map { B(it.value) }
}
j
oh ok 🤔 I've seen that syntax before but not used to it yet... not sure why I thought there would be something else 🤔 anyway, thanks! 🙏 will submit to the team to see which one they find the easier to read 🙂
s
There is nothing specific for drilling into a nested List, using Optics it's should also possible... Not entirely sure on the syntax..
Copy code
Either.right<List<A>>().every.modify(original, f)
j
Thanks for the final alternative! 🙂 Submitted to a vote, 100% of the team went for the double map since it's completely explicit and easier to understand at first sight
👍 1
🔝 3
s
the
either {}
block +
bind()
enables you to work with the right side of the
Either
and short-circuits on left.
Copy code
either {
    call.bind() // the result of this is `List<A>`
}
IMO this scales better if you do multiple ops with the right value. I'd argue it's also explicit, but maybe less familiar
s
@Jérémy CROS I also vote for the other solution 😂 Double map is the way to go IMO. Easy and explicit 👍 Just wanted to give an alternative ☺️
🙏 1