Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Function3Static

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

Hierarchy

  • Function3Static

Index

Methods

constant

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

    Type parameters

    • T1

    • T2

    • T3

    • R

    Parameters

    • val: R

    Returns Function3<T1, T2, T3, R>

liftEither

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

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

    Type parameters

    • T1

    • T2

    • T3

    • L

    • R

    Parameters

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

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

          Returns R

    • Optional witness: L

    Returns Function3<T1, T2, T3, Either<L, R>>

liftNullable

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

    Type parameters

    • T1

    • T2

    • T3

    • R

    Parameters

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

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

          Returns R | null | undefined

    Returns Function3<T1, T2, T3, Option<R>>

liftOption

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

    Type parameters

    • T1

    • T2

    • T3

    • R

    Parameters

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

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

          Returns R | undefined

    Returns Function3<T1, T2, T3, Option<R>>

of

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

    Type parameters

    • T1

    • T2

    • T3

    • R

    Parameters

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

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

          Returns R

    Returns Function3<T1, T2, T3, R>

Generated using TypeDoc