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
Optionoperations that returnOptions. Unlikemapwhich wraps the result in a newOption,flatMapprevents nestedOptions likeSome(Some(value)).