Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JustWrapper<T>

Type parameters

  • T

Hierarchy

Implements

Index

Constructors

constructor

Properties

Protected value

value: T

Accessors

@@__TSFP_RECORD__@@

  • get @@__TSFP_RECORD__@@(): boolean

get

  • get get(): T

isEmpty

  • get isEmpty(): boolean
  • Return true if this is not a Just instance, or the contained value is null or undefined. Otherwise, return false.

    Returns boolean

isJust

  • get isJust(): boolean
  • Return true if this is a Just instance.

    Returns boolean

    Returns true if this is a Just instance

isNothing

  • get isNothing(): boolean
  • Return true if this is a Nothing instance.

    Returns boolean

    Returns true if this is a Nothing instance

Static Nothing

Methods

chain

  • chain<F>(fn: function): function
  • Transforms the value of this Maybe using an unary function to monads.

    • if this is a Just, then return a function that applying the given function with the value of this Maybe

    • if this is a Nothing, then return an identity function of this Maybe

    Type parameters

    • F

    Parameters

    • fn: function
        • Parameters

          • T: any

          Returns Maybe<F>

    Returns function

equals

  • equals(that: any): boolean

flatMap

  • flatMap<F>(fn: function): Maybe<F>
  • Returns the result of applying fn to the value of this Maybe if this is a Just. Returns Nothing if this is a Nothing.

    Slightly different from map is that fn is expected to return a Maybe (which could be Nothing).

    Type parameters

    • F

    Parameters

    • fn: function

      the function to apply

        • Parameters

          • t: T

          Returns Maybe<F>

    Returns Maybe<F>

fold

  • fold<F>(ifEmpty: function, f: function): F
  • Return the result of applying f to the value of this Maybe if this is a Just. Otherwise, evaluates expression ifEmpty.

    Type parameters

    • F

    Parameters

    • ifEmpty: function

      the expression to evaluete if this is a Nothing

        • (): F
        • Returns F

    • f: function

      the function to apply if this is a Just

        • (t: T): F
        • Parameters

          • t: T

          Returns F

    Returns F

getOrElse

  • getOrElse(or: T): T
  • Returns the maybe's value if the maybe is a Just, otherwise return the default value or.

    Parameters

    • or: T

      the default expression

    Returns T

getOrThrow

  • getOrThrow(err: Error): T
  • Returns the maybe's value if the maybe is a Just, otherwise throw the given err which can be either custom error or any object.

    Parameters

    • err: Error

      Rubbish to throw :)

    Returns T

map

  • map<F>(fn: function): Maybe<F>
  • Returns a Just containing the result of applying fn to this Maybe value if this Maybe is a Just. Otherwise return Nothing.

    Type parameters

    • F

    Parameters

    • fn: function

      the function to apply

        • (t: T): F
        • Parameters

          • t: T

          Returns F

    Returns Maybe<F>

orElse

  • orElse<F>(alt: function): Maybe<T>
  • Returns this Maybe if it is a Just, otherwise return the result of evaluating alt.

    Type parameters

    • F: T

    Parameters

    • alt: function

      the alternative expression

    Returns Maybe<T>

toLeft

  • toLeft<G>(right: G): Either<T, G>
  • Return a Left containing this maybe's value if this is a Nothing, or a Right containing the given right if this is a Just.

    Type parameters

    • G

    Parameters

    • right: G

      the value to return if this is a Nothing

    Returns Either<T, G>

toRight

  • toRight<G>(left: G): Either<G, T>
  • Return a Right containing this maybe's value if this is a Just, or a Left containing the given left if this is a Nothing.

    Type parameters

    • G

    Parameters

    • left: G

      the value to return if this is a Nothing

    Returns Either<G, T>

toString

  • toString(): string

Static Just

  • Returns a Just instance with the given value.

    Type parameters

    • F

    Parameters

    • value: F

      The value to wrap.

    Returns JustWrapper<F>

    Returns a Just

Static eval

  • eval<F>(fn: function): Maybe<F>
  • Constructs a new Maybe instance with the evaluated value of the given function.

    Type parameters

    • F

    Parameters

    • fn: function

      the function to be evaluated

        • (): F
        • Returns F

    Returns Maybe<F>

Static isEmpty

  • isEmpty(value: Maybe<any>): boolean
  • Check if value is Just, and the contained value is defined.

    Parameters

    • value: Maybe<any>

      The value to check.

    Returns boolean

Static isJust

  • isJust(value: any): boolean
  • Check if value is Just.

    Parameters

    • value: any

      The value to check.

    Returns boolean

Static isMaybe

  • isMaybe(value: any): boolean
  • Check if value is subtype of Maybe, either Just or Nothing.

    Parameters

    • value: any

      the value to check.

    Returns boolean

    Returns true if value is subtype of Maybe

Static isNothing

  • isNothing(value: any): boolean

Static lift2

  • Apply given function to values wrapped in Maybe, and wrap the result in another Maybe. If any of the argument is a Nothing, return Nothing.

    Type parameters

    • A

    • B

    • C

    Parameters

    • f: function
        • (A: any, B: any): C
        • Parameters

          • A: any
          • B: any

          Returns C

    • a: Maybe<A>
    • b: Maybe<B>

    Returns Maybe<C>

Static lift3

  • Apply given function to values wrapped in Maybe, and wrap the result in another Maybe. If any of the argument is a Nothing, return Nothing.

    Type parameters

    • A

    • B

    • C

    • D

    Parameters

    • f: function
        • (A: any, B: any, C: any): D
        • Parameters

          • A: any
          • B: any
          • C: any

          Returns D

    • a: Maybe<A>
    • b: Maybe<B>
    • c: Maybe<C>

    Returns Maybe<D>

Static of

  • of<F>(value: F): Maybe<F>
  • Constructs a new Maybe instance.

    If the value is either null or undefined, the function returns a Nothing, otherwise the value is wrapped in a Just(val)

    Type parameters

    • F

    Parameters

    • value: F

      the value to wrap

    Returns Maybe<F>

    Returns Nothing if value is null or undefined, else Just

Static run

  • run<F>(gen: IterableIterator<Maybe<F>>): Maybe<F>
  • Do notation for working with ES6 generator.

    Note: the given generator must yield a Maybe at every iteration.

    Type parameters

    • F

    Parameters

    • gen: IterableIterator<Maybe<F>>

      a generator

    Returns Maybe<F>

Generated using TypeDoc