Options
All
  • Public
  • Public/Protected
  • All
Menu

Module function/when

Index

References

Functions

References

Renames and re-exports when

Functions

  • when<T, U>(pred: Pred1<T>, whenTrueFn: (a: T) => U, x: T): T | U
  • when<T, U>(pred: Pred1<T>, whenTrueFn: (a: T) => U): (x: T) => T | U
  • when<T>(pred: Pred1<T>): { <U>(whenTrueFn: (a: T) => U, x: T): T | U; <U>(whenTrueFn: (a: T) => U): (x: T) => T | U }
  • Tests the final argument by passing it to the given predicate function. If the predicate is satisfied, the function will return the result of calling the onTrue function with the same argument. If the predicate is not satisfied, the argument is returned as is.

    example
     // truncate :: String -> String
    var truncate = when(
    x => x.length > 10,
    x => x.slice(0, 10) + '…'
    );
    truncate('12345'); //=> '12345'
    truncate('0123456789ABC'); //=> '0123456789…'

    Type parameters

    • T

    • U

    Parameters

    • pred: Pred1<T>

      A predicate function

    • whenTrueFn: (a: T) => U
        • (a: T): U
        • Parameters

          • a: T

          Returns U

    • x: T

      An object to test with the pred function and pass to onTrue if necessary.

    Returns T | U

    Either x or the result of applying x to onTrue.

  • Tests the final argument by passing it to the given predicate function. If the predicate is satisfied, the function will return the result of calling the onTrue function with the same argument. If the predicate is not satisfied, the argument is returned as is.

    example
     // truncate :: String -> String
    var truncate = when(
    x => x.length > 10,
    x => x.slice(0, 10) + '…'
    );
    truncate('12345'); //=> '12345'
    truncate('0123456789ABC'); //=> '0123456789…'

    Type parameters

    • T

    • U

    Parameters

    • pred: Pred1<T>

      A predicate function

    • whenTrueFn: (a: T) => U
        • (a: T): U
        • Parameters

          • a: T

          Returns U

    Returns (x: T) => T | U

    Either x or the result of applying x to onTrue.

      • (x: T): T | U
      • Parameters

        • x: T

        Returns T | U

  • Tests the final argument by passing it to the given predicate function. If the predicate is satisfied, the function will return the result of calling the onTrue function with the same argument. If the predicate is not satisfied, the argument is returned as is.

    example
     // truncate :: String -> String
    var truncate = when(
    x => x.length > 10,
    x => x.slice(0, 10) + '…'
    );
    truncate('12345'); //=> '12345'
    truncate('0123456789ABC'); //=> '0123456789…'

    Type parameters

    • T

    Parameters

    • pred: Pred1<T>

      A predicate function

    Returns { <U>(whenTrueFn: (a: T) => U, x: T): T | U; <U>(whenTrueFn: (a: T) => U): (x: T) => T | U }

    Either x or the result of applying x to onTrue.

      • <U>(whenTrueFn: (a: T) => U, x: T): T | U
      • <U>(whenTrueFn: (a: T) => U): (x: T) => T | U
      • Type parameters

        • U

        Parameters

        • whenTrueFn: (a: T) => U
            • (a: T): U
            • Parameters

              • a: T

              Returns U

        • x: T

        Returns T | U

      • Type parameters

        • U

        Parameters

        • whenTrueFn: (a: T) => U
            • (a: T): U
            • Parameters

              • a: T

              Returns U

        Returns (x: T) => T | U

          • (x: T): T | U
          • Parameters

            • x: T

            Returns T | U

Generated using TypeDoc