pakoito
11/13/2019, 9:36 PMlist.map {
if (it.a == key) {
...
} else {
it
}
}
Greg Hibberd
11/13/2019, 9:42 PMGreg Hibberd
11/13/2019, 9:47 PMJannis
11/13/2019, 9:55 PMfilterMap
for option, and you can in general always use traverse
. traverse
is equal to map
followed by sequence
and sequence
can turn a List<Option<A>>
or List<Either<L, R>>
into Option<List<A>>
and Either<L, List<R>>
. (it short circuits as soon as it finds a None or a Left)Jannis
11/13/2019, 9:58 PMlist.traverse(Option.applicative()) {
if (it.a == key)
... (some computation that ends with Option)
else it.some()
}
should produce the same thingJannis
11/13/2019, 9:58 PMGreg Hibberd
11/13/2019, 10:01 PM