Options
All
  • Public
  • Public/Protected
  • All
Menu

Maybe describes a value that is optional. It is safer to use then null and undefined.

Type parameters

  • A

Hierarchy

Index

Methods

Abstract andThen

  • andThen<B>(fn: function): Maybe<B>
  • Chain Maybe computations together. If any computation returns a Nothing, then Nothing is the result of the computation.

    Type parameters

    • B

    Parameters

    • fn: function
        • Parameters

          • a: A

          Returns Maybe<B>

    Returns Maybe<B>

Abstract assign

  • assign<K, B>(k: K, other: Maybe<B> | function): Maybe<A & object>
  • Encapsulates a common pattern of needing to build up an Object from a series of Maybe values. This is often solved by nesting andThen calls and then completing the chain with a call to success.

    This feature was inspired (and the code lifted from) this article: https://medium.com/@dhruvrajvanshi/simulating-haskells-do-notation-in-typescript-e48a9501751c

    Wrapped values are converted to an Object using the Object constructor before assigning. Primitives won't fail at runtime, but results may be unexpected.

    Type parameters

    • K: string

    • B

    Parameters

    • k: K
    • other: Maybe<B> | function

    Returns Maybe<A & object>

Abstract cata

Abstract do

  • do(fn: function): Maybe<A>
  • Inject a side-effectual operation into a chain of maybe operations.

    The primary use case for do is to perform logging in the middle of a flow of Maybe computations.

    The side effect only runs when there is a value (Just).

    The value will (should) remain unchanged during the do operation.

    just({}) .assign('foo', just(42)) .assign('bar', just('hello')) .do(scope => console.log('Scope: ', JSON.stringify(scope))) .map(doSomethingElse)

    Parameters

    • fn: function
        • (a: A): void
        • Parameters

          • a: A

          Returns void

    Returns Maybe<A>

Abstract getOrElse

  • getOrElse(fn: function): A
  • Returns the maybe value if it is nonempty. Otherwise returns the result of evaluating fn.

    Parameters

    • fn: function
        • (): A
        • Returns A

    Returns A

Abstract getOrElseValue

  • getOrElseValue(defaultValue: A): A
  • Returns the maybe value if it is nonempty. Otherwise returns the defaultValue.

    Parameters

    • defaultValue: A

    Returns A

Abstract map

  • map<B>(fn: function): Maybe<B>
  • If there's a value, apply the function and return a new Maybe. Mapping over Nothing returns Nothing.

    Type parameters

    • B

    Parameters

    • fn: function
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    Returns Maybe<B>

Abstract orElse

  • orElse(fn: function): Maybe<A>
  • Like a boolean OR. Returns the dereferenced Maybe if it is Just. Otherwise it returns the Maybe from the evaluated function.

    Parameters

    Returns Maybe<A>

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc