Flattens nested options in one level. This function is similar to Option.flatten but more typesafe.
Using this function is possible to ensure at compile time that the target is optional is actually a nested optional.
Any type
Optional to flatten
Flattened option
const opt1 = Option.Some(Option.Some(10))flatten(opt1).unwrap() // 10const opt2: Option<Option<string>> = Option.None()const flatten2: Option<string>= flatten(opt2)flatten2.isNone() // true Copy
const opt1 = Option.Some(Option.Some(10))flatten(opt1).unwrap() // 10const opt2: Option<Option<string>> = Option.None()const flatten2: Option<string>= flatten(opt2)flatten2.isNone() // true
Generated using TypeDoc
Flattens nested options in one level. This function is similar to Option.flatten but more typesafe.
Using this function is possible to ensure at compile time that the target is optional is actually a nested optional.