Skip to content
Menu
Contents

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.

Result

1 type4 functions

Working with Results, the [Ok(a) | Err(e)] variant that fallible functions return. The ? operator unwraps an Ok and returns an Err early; these functions transform one without leaving the function.

Int.fromString("41")
  |> Result.map(\(n) -> n + 1)
  |> Result.withDefault(0)
Returns
42

At a glance

  • Result

    Shorthand for [Ok(a) | Err(e)].

  • map

    f applied to an Ok's value; an Err passes through unchanged.

  • mapErr

    f applied to an Err's error; an Ok passes through unchanged.

  • andThen

    f applied to an Ok's value, whose own Result is the answer; an Err passes through unchanged.

  • withDefault

    An Ok's value, or d for an Err.

Types

Result

Result(a, e) = [Ok(a) | Err(e)]

Shorthand for [Ok(a) | Err(e)].

Functions

map

(Result(a, e), (a) -> b) -> Result(b, e)pure if arg2 is

f applied to an Ok's value; an Err passes through unchanged.

mapErr

(Result(a, e), (e) -> f) -> Result(a, f)pure if arg2 is

f applied to an Err's error; an Ok passes through unchanged.

andThen

(Result(a, e), (a) -> Result(b, e)) -> Result(b, e)pure if arg2 is

f applied to an Ok's value, whose own Result is the answer; an Err passes through unchanged. Chains steps that can each fail.

withDefault

(Result(a, e), a) -> apure

An Ok's value, or d for an Err.

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.