Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

  • fromMaybe<T, E>(errValue: E, maybe: Maybe<T>): Result<T, E>
  • fromMaybe<T, E>(errValue: E): (maybe: Maybe<T>) => Result<T, E>
  • Transform a {@linkcode Maybe.Maybe Maybe} into a Result.

    If the Maybe is a {@linkcode Maybe.Just Just}, its value will be wrapped in the Ok variant; if it is a {@linkcode Maybe.Nothing Nothing} the errValue will be wrapped in the Err variant.

    Type parameters

    • T

    • E

    Parameters

    • errValue: E

      A value to wrap in an Err if maybe is a Nothing.

    • maybe: Maybe<T>

      The Maybe to convert to a Result.

    Returns Result<T, E>

  • Type parameters

    • T

    • E

    Parameters

    • errValue: E

    Returns (maybe: Maybe<T>) => Result<T, E>

  • Construct a Maybe from a {@linkcode Result.Result Result<T, E>}.

    If the Result is an {@linkcode Result.Ok Ok}, wrap its value in Just. If the Result is an {@linkcode Result.Err Err}, throw away the wrapped E and transform to a Nothing.

    Type parameters

    • T

      The type of the value wrapped in a Result.Ok and in the Just of the resulting Maybe.

    Parameters

    • result: Result<T, unknown>

      The Result to construct a Maybe from.

    Returns Maybe<T>

    Just if result was Ok or Nothing if it was Err.

  • Convert a Result to a {@linkcode Maybe.Maybe Maybe}.

    The converted type will be {@linkcode Maybe.Just Just} if the Result is Ok or {@linkcode Maybe.Nothing Nothing} if the Result is Err; the wrapped error value will be discarded.

    Type parameters

    • T

    Parameters

    • result: Result<T, unknown>

      The Result to convert to a Maybe

    Returns Maybe<T>

    Just the value in result if it is Ok; otherwise Nothing

  • toOkOrElseErr<T, E>(elseFn: () => E, maybe: Maybe<T>): Result<T, E>
  • toOkOrElseErr<T, E>(elseFn: () => E): (maybe: Maybe<T>) => Result<T, E>
  • Transform the Maybe into a {@linkcode Result.Result Result}, using the wrapped value as the {@linkcode Result.Ok Ok} value if Just; otherwise using elseFn to generate {@linkcode Result.Err Err}.

    Type parameters

    • T

      The wrapped value.

    • E

      The error type to in the Result.

    Parameters

    • elseFn: () => E

      The function which generates an error of type E.

        • (): E
        • Returns E

    • maybe: Maybe<T>

      The Maybe instance to convert.

    Returns Result<T, E>

    A Result containing the value wrapped in maybe in an Ok, or the value generated by elseFn in an Err.

  • Type parameters

    • T

    • E

    Parameters

    • elseFn: () => E
        • (): E
        • Returns E

    Returns (maybe: Maybe<T>) => Result<T, E>

  • toOkOrErr<T, E>(error: E, maybe: Maybe<T>): Result<T, E>
  • toOkOrErr<T, E>(error: E): (maybe: Maybe<T>) => Result<T, E>
  • Transform the Maybe into a {@linkcode Result.Result Result}, using the wrapped value as the {@linkcode Result.Ok Ok} value if Just; otherwise using the supplied error value for {@linkcode Result.Err Err}.

    Type parameters

    • T

      The wrapped value.

    • E

      The error type to in the Result.

    Parameters

    • error: E

      The error value to use if the Maybe is Nothing.

    • maybe: Maybe<T>

      The Maybe instance to convert.

    Returns Result<T, E>

    A Result containing the value wrapped in maybe in an Ok, or error in an Err.

  • Type parameters

    • T

    • E

    Parameters

    • error: E

    Returns (maybe: Maybe<T>) => Result<T, E>

  • Transposes a Maybe of a Result into a Result of a Maybe.

    Input Output
    Just(Ok(T)) Ok(Just(T))
    Just(Err(E)) Err(E)
    Nothing Ok(Nothing)

    Type parameters

    • T

    • E

    Parameters

    • maybe: Maybe<Result<T, E>>

      a Maybe<Result<T, E>> to transform to a Result<Maybe<T>, E>>.

    Returns Result<Maybe<T>, E>

  • Transposes a Result of a Maybe into a Maybe of a Result.

    Input Output
    Ok(Just(T)) Just(Ok(T))
    Err(E) Just(Err(E))
    Ok(Nothing) Nothing

    Type parameters

    • T

    • E

    Parameters

    • result: Result<Maybe<T>, E>

      a Result<Maybe<T>, E> to transform to a Maybe<Result<T, E>>.

    Returns Maybe<Result<T, E>>

Generated using TypeDoc