Shameless plug... In case someone missed it :smile...
# arrow
s
Shameless plug... In case someone missed it 😄 https://www.47deg.com/blog/functional-domain-modeling-part-2/
👏 20
t
Really interesting article @simon.vergauwen I miss out on how to use the equivalent
mapOrNull
Iterable operator with arrow operators, sometimes I wanna just drop errors during a computation, exist some
traverseXXX
or a combination of method to archive that?
s
Most types are not able to implement
mapNotNull
like
Iterable
since it requires an empty container like
emptyList
for
Iterable
. i.e.
Copy code
val either: Either<MyError, List<Int>> = emptyList<Int>().right()
val res: Either<MyError, Int> = either.mapNotNull { list -> list.firstOrNull() } // <-- Should become MyError inside Left
// Which value for MyError should we return???
t
Sorry, yesterday I was out of PC and could not write code correctly, mi idea it's more close to this
Copy code
val list: List<Either<Error, Int>> = listOf(left(Error),right(1),left(Error),right(3),right(5))
val result = List<User> = ... // I want to transforms list and store into result [1,3,5]
If list was List<Int?> I could use simple
result = list.mapNotNull { it }
but what could I do with Either or Validated?
👍 1
s
list.mapNotNull { it.orNull() }
😅 1