Class Optional<T>

optional implementation, an optional is basically an implementation of a Monad with additional syntactic sugar on top (Sideeffect free, since value assignment is not allowed)

Type Parameters

  • T

Hierarchy

Constructors

Properties

absent: Optional<any> = ...

Accessors

  • get value(): T
  • Returns T

Methods

  • Type Parameters

    • R

    Parameters

    • Optional fn: ((data: T) => R)
        • (data: T): R
        • Parameters

          • data: T

          Returns R

    Returns Optional<any>

  • convenience function to flatmap the internal value and replace it with a default in case of being absent

    Returns

    Type Parameters

    • R

    Parameters

    • defaultVal: any = Optional.absent

    Returns Optional<R>

  • additional syntactic sugar which is not part of the usual optional implementation but makes life easier, if you want to sacrifice typesafety and refactoring capabilities in typescript

    Type Parameters

    • R

    Parameters

    • key: string

    Returns Optional<R>

  • Parameters

    • presentRunnable: ((val?: Monad<T>) => void) = ...
        • (val?: Monad<T>): void
        • Parameters

          Returns void

    Returns Monad<T>

  • Returns boolean

  • any value present

    Parameters

    • Optional presentRunnable: ((val?: Monad<T>) => void)
        • (val?: Monad<T>): void
        • Parameters

          Returns void

    Returns boolean

  • Type Parameters

    • R

    Parameters

    • Optional fn: ((data: T) => R)
        • (data: T): R
        • Parameters

          • data: T

          Returns R

    Returns Monad<R>

  • simple match, if the first order function call returns true then there is a match, if the value is not present it never matches

    Parameters

    • fn: ((item: T) => boolean)

      the first order function performing the match

        • (item: T): boolean
        • Parameters

          • item: T

          Returns boolean

    Returns boolean

  • lazy, passes a function which then is lazily evaluated instead of a direct value

    Parameters

    • func: (() => any)
        • (): any
        • Returns any

    Returns Optional<any>

  • elvis like typesafe functional save resolver a typesafe option for getIfPresent

    usage myOptional.resolve(value => value.subAttr.subAttr2).orElseLazy(....) if this is resolvable without any errors an Optional with the value is returned if not, then an Optional absent is returned, also if you return Optional absent it is flatmapped into absent

    Type Parameters

    • V

    Parameters

    • resolver: ((item: T) => V)

      the resolver function, can throw any arbitrary errors, int the error case the resolution goes towards absent

        • (item: T): V
        • Parameters

          • item: T

          Returns V

    Returns Optional<V>

Generated using TypeDoc