simon.vergauwen
04/14/2021, 5:15 PMthanerian
04/15/2021, 5:23 AMmapOrNull 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?simon.vergauwen
04/15/2021, 6:49 AMmapNotNull like Iterable since it requires an empty container like emptyList for Iterable.
i.e.
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???thanerian
04/16/2021, 5:27 AMval 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?simon.vergauwen
04/16/2021, 8:23 AMlist.mapNotNull { it.orNull() }