Skip to main content Link Search Menu Expand Document (external link)

Result overview

Added in v1.0.0


Table of contents


accessors

cause

Signature

export declare const cause: <A, E>(self: Result<A, E>) => Option.Option<Cause.Cause<E>>

Added in v1.0.0

getOrElse

Signature

export declare const getOrElse: {
  <B>(orElse: LazyArg<B>): <A, E>(self: Result<A, E>) => A | B
  <A, E, B>(self: Result<A, E>, orElse: LazyArg<B>): A | B
}

Added in v1.0.0

getOrThrow

Signature

export declare const getOrThrow: <A, E>(self: Result<A, E>) => A

Added in v1.0.0

value

Signature

export declare const value: <A, E>(self: Result<A, E>) => Option.Option<A>

Added in v1.0.0

combinators

map

Signature

export declare const map: {
  <A, B>(f: (a: A) => B): <E>(self: Result<A, E>) => Result<B, E>
  <E, A, B>(self: Result<A, E>, f: (a: A) => B): Result<B, E>
}

Added in v1.0.0

match

Signature

export declare const match: {
  <A, E, X, Y, Z>(options: {
    readonly onInitial: (_: Initial<A, E>) => X
    readonly onFailure: (_: Failure<A, E>) => Y
    readonly onSuccess: (_: Success<A, E>) => Z
  }): (self: Result<A, E>) => X | Y | Z
  <A, E, X, Y, Z>(
    self: Result<A, E>,
    options: {
      readonly onInitial: (_: Initial<A, E>) => X
      readonly onFailure: (_: Failure<A, E>) => Y
      readonly onSuccess: (_: Success<A, E>) => Z
    }
  ): X | Y | Z
}

Added in v1.0.0

matchWithError

Signature

export declare const matchWithError: {
  <A, E, W, X, Y, Z>(options: {
    readonly onInitial: (_: Initial<A, E>) => W
    readonly onError: (error: E, _: Failure<A, E>) => X
    readonly onDefect: (defect: unknown, _: Failure<A, E>) => Y
    readonly onSuccess: (_: Success<A, E>) => Z
  }): (self: Result<A, E>) => W | X | Y | Z
  <A, E, W, X, Y, Z>(
    self: Result<A, E>,
    options: {
      readonly onInitial: (_: Initial<A, E>) => W
      readonly onError: (error: E, _: Failure<A, E>) => X
      readonly onDefect: (defect: unknown, _: Failure<A, E>) => Y
      readonly onSuccess: (_: Success<A, E>) => Z
    }
  ): W | X | Y | Z
}

Added in v1.0.0

matchWithWaiting

Signature

export declare const matchWithWaiting: {
  <A, E, W, X, Y, Z>(options: {
    readonly onWaiting: (_: Result<A, E>) => W
    readonly onError: (error: E, _: Failure<A, E>) => X
    readonly onDefect: (defect: unknown, _: Failure<A, E>) => Y
    readonly onSuccess: (_: Success<A, E>) => Z
  }): (self: Result<A, E>) => W | X | Y | Z
  <A, E, W, X, Y, Z>(
    self: Result<A, E>,
    options: {
      readonly onWaiting: (_: Result<A, E>) => W
      readonly onError: (error: E, _: Failure<A, E>) => X
      readonly onDefect: (defect: unknown, _: Failure<A, E>) => Y
      readonly onSuccess: (_: Success<A, E>) => Z
    }
  ): W | X | Y | Z
}

Added in v1.0.0

toExit

Signature

export declare const toExit: <A, E>(self: Result<A, E>) => Exit.Exit<A, E | Cause.NoSuchElementException>

Added in v1.0.0

constructors

fail

Signature

export declare const fail: <A, E>(error: E, previousData?: Option.Option<A>, waiting?: boolean) => Failure<A, E>

Added in v1.0.0

failWithPrevious

Signature

export declare const failWithPrevious: <A, E>(
  error: E,
  previous: Option.Option<Result<A, E>>,
  waiting?: boolean
) => Failure<A, E>

Added in v1.0.0

failure

Signature

export declare const failure: <A, E>(
  cause: Cause.Cause<E>,
  previousValue?: Option.Option<A>,
  waiting?: boolean
) => Failure<A, E>

Added in v1.0.0

failureWithPrevious

Signature

export declare const failureWithPrevious: <A, E>(
  cause: Cause.Cause<E>,
  previous: Option.Option<Result<A, E>>,
  waiting?: boolean
) => Failure<A, E>

Added in v1.0.0

fromExit

Signature

export declare const fromExit: <A, E>(exit: Exit.Exit<A, E>) => Success<A, E> | Failure<A, E>

Added in v1.0.0

fromExitWithPrevious

Signature

export declare const fromExitWithPrevious: <A, E>(
  exit: Exit.Exit<A, E>,
  previous: Option.Option<Result<A, E>>
) => Success<A, E> | Failure<A, E>

Added in v1.0.0

initial

Signature

export declare const initial: <A, E>(waiting?: boolean) => Initial<A, E>

Added in v1.0.0

replacePrevious

Signature

export declare const replacePrevious: <R extends Result<any, any>, XE, A>(
  self: R,
  previous: Option.Option<Result<A, XE>>
) => Result.With<R, A, Result.InferE<R>>

Added in v1.0.0

success

Signature

export declare const success: <A, E>(value: A, waiting?: boolean) => Success<A, E>

Added in v1.0.0

waiting

Signature

export declare const waiting: <R extends Result<any, any>>(self: R) => R

Added in v1.0.0

waitingFrom

Signature

export declare const waitingFrom: <A, E>(previous: Option.Option<Result<A, E>>) => Result<A, E>

Added in v1.0.0

models

Failure (interface)

Signature

export interface Failure<A, E = never> extends Result.Proto<A, E> {
  readonly _tag: "Failure"
  readonly cause: Cause.Cause<E>
  readonly previousValue: Option.Option<A>
}

Added in v1.0.0

Initial (interface)

Signature

export interface Initial<A, E = never> extends Result.Proto<A, E> {
  readonly _tag: "Initial"
}

Added in v1.0.0

Result (type alias)

Signature

export type Result<A, E = never> = Initial<A, E> | Success<A, E> | Failure<A, E>

Added in v1.0.0

Result (namespace)

Added in v1.0.0

Proto (interface)

Signature

export interface Proto<A, E> extends Pipeable {
  readonly [TypeId]: {
    readonly E: (_: never) => E
    readonly A: (_: never) => A
  }
  readonly waiting: boolean
}

Added in v1.0.0

InferA (type alias)

Signature

export type InferA<R extends Result<any, any>> = R extends Result<infer A, infer _> ? A : never

Added in v1.0.0

InferE (type alias)

Signature

export type InferE<R extends Result<any, any>> = R extends Result<infer _, infer E> ? E : never

Added in v1.0.0

With (type alias)

Signature

export type With<R extends Result<any, any>, A, E> =
  R extends Initial<infer _A, infer _E>
    ? Initial<A, E>
    : R extends Success<infer _A, infer _E>
      ? Success<A, E>
      : R extends Failure<infer _A, infer _E>
        ? Failure<A, E>
        : never

Added in v1.0.0

Success (interface)

Signature

export interface Success<A, E = never> extends Result.Proto<A, E> {
  readonly _tag: "Success"
  readonly value: A
}

Added in v1.0.0

refinements

isFailure

Signature

export declare const isFailure: <A, E>(result: Result<A, E>) => result is Failure<A, E>

Added in v1.0.0

isInitial

Signature

export declare const isInitial: <A, E>(result: Result<A, E>) => result is Initial<A, E>

Added in v1.0.0

isInterrupted

Signature

export declare const isInterrupted: <A, E>(result: Result<A, E>) => result is Failure<A, E>

Added in v1.0.0

isNotInitial

Signature

export declare const isNotInitial: <A, E>(result: Result<A, E>) => result is Success<A, E> | Failure<A, E>

Added in v1.0.0

isSuccess

Signature

export declare const isSuccess: <A, E>(result: Result<A, E>) => result is Success<A, E>

Added in v1.0.0

type ids

TypeId

Signature

export declare const TypeId: typeof TypeId

Added in v1.0.0

TypeId (type alias)

Signature

export type TypeId = typeof TypeId

Added in v1.0.0