Hi all, I'm stuck and hoping someone can point me...
# arrow
t
Hi all, I'm stuck and hoping someone can point me in the right direction 🙏 . I"m trying to do something like this:
Copy code
val numbers = listOf(1, 2, 3, 4)
val strings = numbers.map { somethingThatReturnsEither(it) }

// Here I'd like to map strings and put Lefts into one list and Rights into another list

return Tuple2(failures, successes)
Hopefully that makes sense. I could just do a forEach and put everything into lists manually, but I'm hoping there's an FP way here
r
you can use list.partition { it.isRight() } or perhaps foldMap
t
ahh partition sounds like what I need! thank you 🙂 too many functions lol
looks like the types don't come thorugh with partition as I get two lists with the same inferred types. I can manually cast, but is there a better way?
r
you can also just fold the list and accumulate on the desired result type
checking in each case