• Creates a Maybe instance from a value, allowing safe and functional handling of potentially nullable or undefined values.

    Type Parameters

    • T

      The type of the value.

    Parameters

    • value: undefined | null | T

      The value to be wrapped in a Maybe instance.

    Returns Maybe<T>

    A Maybe instance representing the provided value.

    Function

    maybe

    Example: Using maybe to check if an environment variable is defined and convert it to a number

    const port = maybe(process.env.PORT)
    .map(value => Number(value))
    .map(value => Number.isNaN(value) ? 3000 : value)
    .unwrap();

Generated using TypeDoc