@metreeca/core - v0.9.22
    Preparing search index...

    Function given

    Applies a mapper to a value, short-circuiting an undefined one.

    • Applies a mapper to a defined value.

      Binds a value to a mapper of its own, so a computation reads as a scoped expression rather than as a temporary variable followed by a statement. The value is known to be defined, so the mapper is always called and its result is reported unchanged.

      Type Parameters

      • V extends {} | null

        The type of the value to map, known to exclude undefined

      Parameters

      • value: V

        The value to hand on to the mapper

      Returns <R>(mapper: (value: V) => R) => R

      A function reporting the value computed from value by its mapper argument; errors raised by the mapper propagate to the caller unchanged

      given(8080)(port => `localhost:${port}`); // "localhost:8080"
      
    • Applies a mapper to a possibly undefined value.

      Extends the mapper with a tolerance for undefined values: a defined value is handed on to it stripped of undefined, while an undefined one short-circuits to undefined without calling it, so an optional value flows through a chain of total functions without a guard at every step. Definedness is about assignment rather than emptiness, so null is mapped like any other value.

      Type Parameters

      • V

        The type of the value to map, possibly including undefined

      Parameters

      • value: V

        The value to hand on to the mapper, if defined

      Returns <R>(mapper: (value: Defined<V>) => R) => R | undefined

      A function reporting undefined if value is undefined, and the value computed by its mapper argument otherwise; errors raised by the mapper propagate to the caller unchanged

      given(ports.get(name))(port => `localhost:${port}`); // string or undefined (the mapper is not called)