ts-data-forge
    Preparing search index...
    • Returns the Optional if it is Some, otherwise returns the alternative.

      Provides a way to chain Optional operations with fallback values. This is particularly useful for implementing default behavior or cascading lookups. Supports both direct usage and curried form for functional composition.

      Type Parameters

      Parameters

      • optional: O

        The Optional to check.

      • alternative: O2

        The alternative Optional to return if the first is None.

      Returns O | O2

      The first Optional if Some, otherwise the alternative.

      const preferred = Optional.some('primary');
      const fallback = Optional.some('secondary');
      const noneValue = Optional.none as Optional<string>;

      assert.deepStrictEqual(Optional.orElse(preferred, fallback), preferred);
      assert.deepStrictEqual(Optional.orElse(noneValue, fallback), fallback);

      const orElseFallback = Optional.orElse(Optional.some('default'));

      assert.deepStrictEqual(orElseFallback(Optional.none), Optional.some('default'));
      assert.deepStrictEqual(
      orElseFallback(Optional.some('value')),
      Optional.some('value'),
      );
    • Returns the Optional if it is Some, otherwise returns the alternative.

      Provides a way to chain Optional operations with fallback values. This is particularly useful for implementing default behavior or cascading lookups. Supports both direct usage and curried form for functional composition.

      Type Parameters

      • S
      • S2

      Parameters

      • alternative: Optional<S2>

        The alternative Optional to return if the first is None.

      Returns (
          optional: Optional<S>,
      ) => Readonly<{}> | Readonly<{ value: S2 }> | Readonly<{ value: S }>

      The first Optional if Some, otherwise the alternative.

      const preferred = Optional.some('primary');
      const fallback = Optional.some('secondary');
      const noneValue = Optional.none as Optional<string>;

      assert.deepStrictEqual(Optional.orElse(preferred, fallback), preferred);
      assert.deepStrictEqual(Optional.orElse(noneValue, fallback), fallback);

      const orElseFallback = Optional.orElse(Optional.some('default'));

      assert.deepStrictEqual(orElseFallback(Optional.none), Optional.some('default'));
      assert.deepStrictEqual(
      orElseFallback(Optional.some('value')),
      Optional.some('value'),
      );