Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DecodeResultBase<In, Out, Err>

DecodeResult is a union type that has two possible constructors DecodeSuccess and DecodeFailure.

DecodeResultBase is abstract and should never be used directly. It is defined to provide a common signature to the only two possible constructors DecodeSuccess and DecodeFailure.

See <a href="../globals.html#decoderesult">DecodeResult</a>.

Type parameters

  • In

  • Out

  • Err

Hierarchy

Index

Constructors

constructor

  • Construct an instance of <a href="../globals.html#decoderesult">DecodeResult</a>. The only field that is shared between <a href="decodesuccess.html">DecodeSuccess</a> and <a href="decodefailure.html">DecodeFailure</a> is input: In.

    Parameters

    • input: In

    Returns DecodeResultBase

Properties

_E

_E: Err

These placeholder (_I, _O, _E) types are not expected to bring any value. They exist to allow inspecting the main types of a DecodeResult at compile time.

_I

_I: In

See _E.

_O

_O: Out

See _E.

input

input: In

Abstract kind

kind: "decode-success" | "decode-failure"

Type discriminator

Methods

Abstract flatMap

  • Transfom the result of a DecodeSuccess into a new DecodeResult by applying the function f to it.

    Type parameters

    • Out2

    Parameters

    Returns DecodeResult<In, Out2, Err>

Abstract flatMapError

  • flatMapError<Err2>(f: function): DecodeResult<In, Out, Err2>
  • Transfom the result of a DecodeFailure into a new DecodeResult by applying the function f to it. This operation allows to recover form a failed result.

    Type parameters

    • Err2

    Parameters

    Returns DecodeResult<In, Out, Err2>

Abstract getUnsafeFailures

  • getUnsafeFailures(): Err[]
  • Unwrap the result value of a DecodeFailure. If the current instance is of type DecodeSuccess then this function will throw an exception. Do not use unless you are protecting from exceptions.

    Returns Err[]

Abstract getUnsafeSuccess

  • getUnsafeSuccess(): Out
  • Unwrap the result value of a DecodeSuccess. If the current instance is of type DecodeFailure then this function will throw an exception. Do not use unless you are protecting from exceptions.

    Returns Out

Abstract isFailure

  • isFailure(): boolean
  • Return true if the current instance is of type DecodeFailure. It also provide a guard value so that properties of DecodeFailure can be used in the right conditional scope.

    Returns boolean

Abstract isSuccess

  • isSuccess(): boolean
  • Return true if the current instance is of type DecodeSuccess. It also provide a guard value so that properties of DecodeSuccess can be used in the right conditional scope.

    Returns boolean

Abstract map

  • Transfom the result of a DecodeSuccess into a new value of type Out2 by applying the function f to the original Out value.

    Type parameters

    • Out2

    Parameters

    • f: function
        • (r: Out): Out2
        • Parameters

          • r: Out

          Returns Out2

    Returns DecodeResult<In, Out2, Err>

Abstract mapError

  • Transfom the result of a DecodeFailure into a new value of type Err2 by applying the function f to the original Err value.

    Type parameters

    • Err2

    Parameters

    • f: function
        • (r: Err): Err2
        • Parameters

          • r: Err

          Returns Err2

    Returns DecodeResult<In, Out, Err2>

Abstract mapInput

  • Transform the input value associated with the current DecodeResult into a new input of type In2.

    Type parameters

    • In2

    Parameters

    • f: function
        • (i: In): In2
        • Parameters

          • i: In

          Returns In2

    Returns DecodeResult<In2, Out, Err>

Abstract match

  • match<O>(o: object): O
  • Transform an instance of <a href="../globals.html#decoderesult">DecodeResult</a> into any type O. To perform the transformation an object is passed with 2 fields success and failure. Both fields must be populated with a function.

    • success will take a function DecodeSuccess -> O
    • failure will take a function DecodeFailure -> O

    Type parameters

    • O

    Parameters

    Returns O

Abstract toString

  • toString(): string
  • Provides a human readable representation of the value. Mostly for debugging.

    Returns string