starke
05/15/2019, 5:31 PMOption
values
val option1 = Option.just("foo")
val option2 = Option.just(1)
val option3 = Option.just(Bar())
val result: Option<FooBar> = option1.flatMap { unwrappedValue1 ->
option2.flatMap { unwrappedValue2 ->
option3.map { unwrappedValue3 ->
FooBar(unwrappedValue1, unwrappedValue2, unwrappedValue3)
}
}
}
}
what is a better way to handle the use case where you want to return an Option
that is, for example, a composite of multiple other types that are wrapped by Option
I would like the resulting Option
to be None
if any of the other values are None
, otherwise return Some
that is a composite of the data from the other `Option`s…if that makes sense?starke
05/15/2019, 5:33 PM