Function ifFn

  • Creates a one line true/false function

    const ifLongString = ifFn((s: string) => {
    return s.length > 10
    })

    ifLongString('short', 'yes', 'no') // 'no'
    ifLongString('Longer string that is long', 'yes', 'no') // 'yes'

    Returns

    A function which when called takes the single argument for the function and then returns the truthy or falsy value as needed

    Type Parameters

    • Argument

    Parameters

    • fn: ((argument: Argument) => boolean)

      A single argument function that returns a boolean value

        • (argument: Argument): boolean
        • Parameters

          • argument: Argument

          Returns boolean

    Returns (<TruthyResult, FalsyResult>(argument: Argument, truthy: TruthyResult, falsy: FalsyResult) => TruthyResult | FalsyResult)

      • <TruthyResult, FalsyResult>(argument: Argument, truthy: TruthyResult, falsy: FalsyResult): TruthyResult | FalsyResult
      • Type Parameters

        • TruthyResult

        • FalsyResult

        Parameters

        • argument: Argument
        • truthy: TruthyResult
        • falsy: FalsyResult

        Returns TruthyResult | FalsyResult

Generated using TypeDoc