Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Function5Static

This is the type of the Function5 constant, which offers some helper functions to deal with Function5 including the ability to build Function5 from functions using Function5Static.of. It also offers some builtin functions like Function5Static.constant.

Hierarchy

  • Function5Static

Index

Methods

constant

  • constant<T1, T2, T3, T4, T5, R>(val: R): Function5<T1, T2, T3, T4, T5, R>
  • The constant function of five parameters: will always return the value you give, no matter the parameters it's given.

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • R

    Parameters

    • val: R

    Returns Function5<T1, T2, T3, T4, T5, R>

liftEither

  • liftEither<T1, T2, T3, T4, T5, L, R>(fn: function, witness?: L): Function5<T1, T2, T3, T4, T5, Either<L, R>>
  • Take a five-parameter partial function (may return undefined or throw), and lift it to return an Either instead.

    Note that unlike the Function5Static.liftOption version, if the function returns undefined, the liftEither version will throw (the liftOption version returns None()): if you want to do pure side-effects which may throw, you're better off just using javascript try blocks.

    When using typescript, to help the compiler infer the left type, you can either pass a second parameter like {} as <type>, or call with try_<L,R>(...).

    const add5 = Function5.liftEither(
        (x:number,y:number,z:number,a:number,b:number) => x+y+z+a+b, {} as string);
    add5(1,2,3,4,5);
    => Either.right(15)
    
    const undef = Function5.liftEither(
        (x:number,y:number,z:number,a:number,b:number) => undefined);
    undef(1,2,3,4,5);
    => throws
    
    const throws = Function5.liftEither(
        (x:number,y:number,z:number,a:number,b:number) => {throw "x"});
    throws(1,2,3,4,5);
    => Either.left("x")
    

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • L

    • R

    Parameters

    • fn: function
        • (x: T1, y: T2, z: T3, a: T4, b: T5): R
        • Parameters

          • x: T1
          • y: T2
          • z: T3
          • a: T4
          • b: T5

          Returns R

    • Optional witness: L

    Returns Function5<T1, T2, T3, T4, T5, Either<L, R>>

liftNullable

  • liftNullable<T1, T2, T3, T4, T5, R>(fn: function): Function5<T1, T2, T3, T4, T5, Option<R>>
  • Take a five-parameter partial function (may return undefined or throw), and lift it to return an Option instead. null and undefined become a None, everything else a Some

    const add5 = Function5.liftNullable(
        (x:number,y:number,z:number,a:number,b:number)=>x+y+z+a+b);
    add5(1,2,3,4,5);
    => Option.of(15)
    
    const undef = Function5.liftNullable(
        (x:number,y:number,z:number,a:number,b:number)=>undefined);
    undef(1,2,3,4,5);
    => Option.none()
    
    const nl = Function5.liftNullable(
        (x:number,y:number,z:number,a:number,b:number)=>null);
    nl(1,2,3,4,5);
    => Option.none()
    
    const throws = Function5.liftNullable(
        (x:number,y:number,z:number,a:number,b:number)=>{throw "x"});
    throws(1,2,3,4,5);
    => Option.none()
    

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • R

    Parameters

    • fn: function
        • (x: T1, y: T2, z: T3, a: T4, b: T5): R | null | undefined
        • Parameters

          • x: T1
          • y: T2
          • z: T3
          • a: T4
          • b: T5

          Returns R | null | undefined

    Returns Function5<T1, T2, T3, T4, T5, Option<R>>

liftOption

  • liftOption<T1, T2, T3, T4, T5, R>(fn: function): Function5<T1, T2, T3, T4, T5, Option<R>>
  • Take a five-parameter partial function (may return undefined or throw), and lift it to return an Option instead. undefined becomes a None, everything else a Some

    const add5 = Function5.liftOption(
        (x:number,y:number,z:number,a:number,b:number)=>x+y+z+a+b);
    add5(1,2,3,4,5);
    => Option.of(15)
    
    const undef = Function5.liftOption(
        (x:number,y:number,z:number,a:number,b:number)=>undefined);
    undef(1,2,3,4,5);
    => Option.none()
    
    const nl = Function5.liftOption(
        (x:number,y:number,z:number,a:number,b:number)=>null);
    nl(1,2,3,4,5);
    => Option.some(null)
    
    const throws = Function5.liftOption(
        (x:number,y:number,z:number,a:number,b:number)=>{throw "x"});
    throws(1,2,3,4,5);
    => Option.none()
    

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • R

    Parameters

    • fn: function
        • (x: T1, y: T2, z: T3, a: T4, b: T5): R | undefined
        • Parameters

          • x: T1
          • y: T2
          • z: T3
          • a: T4
          • b: T5

          Returns R | undefined

    Returns Function5<T1, T2, T3, T4, T5, Option<R>>

of

  • of<T1, T2, T3, T4, T5, R>(fn: function): Function5<T1, T2, T3, T4, T5, R>
  • Take a five-parameter function and lift it to become a Function5, enabling you to call Function5.andThen and other such methods on it.

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • R

    Parameters

    • fn: function
        • (x: T1, y: T2, z: T3, a: T4, b: T5): R
        • Parameters

          • x: T1
          • y: T2
          • z: T3
          • a: T4
          • b: T5

          Returns R

    Returns Function5<T1, T2, T3, T4, T5, R>

Generated using TypeDoc