Chains Option operations that return Options. Unlike map which wraps the result in a new Option, flatMap prevents nested Options like Some(Some(value)).
Option
map
flatMap
Some(Some(value))
A function that returns an Option
The Option returned by the function if the input is Some, None otherwise
Some
None
Chains
Option
operations that returnOption
s. Unlikemap
which wraps the result in a newOption
,flatMap
prevents nestedOption
s likeSome(Some(value))
.