Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "result"

module

Result

Index

Type aliases

Functions

Type aliases

Result

Result<TError, TValue>: { type: "Ok"; value: TValue } | { error: TError; type: "Err" }

A Result is either Ok meaning the computation succeeded, or it is an Err meaning that there was some failure.

Type parameters

  • TError

  • TValue

Functions

Err

  • Err<TError>(error: TError): Result<TError, never>
  • Type parameters

    • TError

    Parameters

    • error: TError

    Returns Result<TError, never>

Ok

  • Ok<TValue>(value: TValue): Result<never, TValue>
  • Type parameters

    • TValue

    Parameters

    • value: TValue

    Returns Result<never, TValue>

mapError

  • mapError<x, y, a>(f: (x: x) => y, result: Result<x, a>): Result<y, a>
  • Transform an Err value. For example, say the errors we get have too much information: parseInt : String -> Result ParseError Int type alias ParseError = { message : String , code : Int , position : (Int,Int) } mapError .message (parseInt "123") == Ok 123 mapError .message (parseInt "abc") == Err "char 'a' is not a number"

    Type parameters

    • x

    • y

    • a

    Parameters

    • f: (x: x) => y
        • (x: x): y
        • Parameters

          • x: x

          Returns y

    • result: Result<x, a>

    Returns Result<y, a>

Generated using TypeDoc