Function flatten

  • 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.

    Type Parameters

    • T

      Any type

    Parameters

    Returns Option<T>

    Flattened option

    Example

    const opt1 = Option.Some(Option.Some(10))
    flatten(opt1).unwrap() // 10

    const opt2: Option<Option<string>> = Option.None()
    const flatten2: Option<string>= flatten(opt2)
    flatten2.isNone() // true

Generated using TypeDoc