@mikuroxina/mini-fn
    Preparing search index...

    Function mapOrElse

    • Maps the optional value with a default value fn().

      Type Parameters

      • U

      Parameters

      • fn: () => U

        The function to provide a default value.

      Returns <T>(f: (t: T) => U) => (opt: Option.Option<T>) => U

      The mapped value or init.

      Examples

      const strLenOrCalc = mapOrElse(() => 6 ** 4)((str: string) => str.length);

      expect(strLenOrCalc(some("Hello, World!"))).toStrictEqual(13);
      expect(strLenOrCalc(none())).toStrictEqual(1296);