Gcode.Result (gcode v1.0.2)

Copy Markdown

A helper which represents a result type.

This is really just a wrapper around Erlang's ok/error tuples.

Summary

Functions

Initialise or match an error value

Is the result an error?

Convert a successful result another result.

Initialise or match an ok value

Is the result ok?

Attempt to unwrap a result and return the inner value. Raises an exception if the result contains an error.

Types

error(error)

@type error(error) :: {:error, error}

ok(result)

@type ok(result) :: {:ok, result}

t()

@type t() :: t(any(), any())

t(result)

@type t(result) :: t(result, any())

t(result, error)

@type t(result, error) :: ok(result) | error(error)

Functions

error(error)

(macro)
@spec error(any()) :: Macro.t()

Initialise or match an error value

error?(arg)

@spec error?(t()) :: boolean()

Is the result an error?

map(arg, mapper)

@spec map(t(), (any() -> t())) :: t()

Convert a successful result another result.

ok(result)

(macro)
@spec ok(any()) :: Macro.t()

Initialise or match an ok value

ok?(arg)

@spec ok?(t()) :: boolean()

Is the result ok?

unwrap!(arg)

@spec unwrap!(t()) :: any() | no_return()

Attempt to unwrap a result and return the inner value. Raises an exception if the result contains an error.