Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Function4Static

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

Hierarchy

  • Function4Static

Index

Methods

constant

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

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • R

    Parameters

    • val: R

    Returns Function4<T1, T2, T3, T4, R>

liftEither

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

    Note that unlike the Function4Static.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 add4 = Function4.liftEither((x:number,y:number,z:number,a:number) => x+y+z+a, {} as string);
    add4(1,2,3,4);
    => Either.right(10)
    
    const undef = Function4.liftEither((x:number,y:number,z:number,a:number) => undefined);
    undef(1,2,3,4);
    => throws
    
    const throws = Function4.liftEither((x:number,y:number,z:number,a:number) => {throw "x"});
    throws(1,2,3,4);
    => Either.left("x")
    

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • L

    • R

    Parameters

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

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

          Returns R

    • Optional witness: L

    Returns Function4<T1, T2, T3, T4, Either<L, R>>

liftNullable

  • liftNullable<T1, T2, T3, T4, R>(fn: function): Function4<T1, T2, T3, T4, Option<R>>
  • Take a four-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 add4 = Function4.liftNullable(
        (x:number,y:number,z:number,a:number)=>x+y+z+a);
    add4(1,2,3,4);
    => Option.of(10)
    
    const undef = Function4.liftNullable(
        (x:number,y:number,z:number,a:number)=>undefined);
    undef(1,2,3,4);
    => Option.none()
    
    const nl = Function4.liftNullable(
        (x:number,y:number,z:number,a:number)=>null);
    nl(1,2,3,4);
    => Option.none()
    
    const throws = Function4.liftNullable(
        (x:number,y:number,z:number,a:number)=>{throw "x"});
    throws(1,2,3,4);
    => Option.none()
    

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • R

    Parameters

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

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

          Returns R | null | undefined

    Returns Function4<T1, T2, T3, T4, Option<R>>

liftOption

  • liftOption<T1, T2, T3, T4, R>(fn: function): Function4<T1, T2, T3, T4, Option<R>>
  • Take a four-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 add4 = Function4.liftOption(
        (x:number,y:number,z:number,a:number)=>x+y+z+a);
    add4(1,2,3,4);
    => Option.of(10)
    
    const undef = Function4.liftOption(
        (x:number,y:number,z:number,a:number)=>undefined);
    undef(1,2,3,4);
    => Option.none()
    
    const nl = Function4.liftOption(
        (x:number,y:number,z:number,a:number)=>null);
    nl(1,2,3,4);
    => Option.some(null)
    
    const throws = Function4.liftOption(
        (x:number,y:number,z:number,a:number)=>{throw "x"});
    throws(1,2,3,4);
    => Option.none()
    

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • R

    Parameters

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

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

          Returns R | undefined

    Returns Function4<T1, T2, T3, T4, Option<R>>

of

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

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • R

    Parameters

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

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

          Returns R

    Returns Function4<T1, T2, T3, T4, R>

Generated using TypeDoc