View Source Ark.Ok (ark v0.9.0)

Link to this section Summary

Functions

Mapping while ok. Takes an enumerable and applies the given callback to all values of the enumerable as long as the callback returns {:ok, mapped_value}.

Wrapping ok.

Questionning ok.

Reducing while ok. Takes an enumerable, an initial value for the accumulator and a reducer function. Calls the reducer for each value in the enumerable as long as the reducer returns {:ok, new_acc}.

uok(value) deprecated

Unwrapping ok.

Unwrapping ok with raise.

wok is an alias of wrapping function :ok.

Unwrapping ok, raising custom exceptions.

Link to this section Functions

Specs

map_ok(Enumerable.t(), (term() -> {:ok, term()} | {:error, term()})) ::
  {:ok, list()} | {:error, term()}

Mapping while ok. Takes an enumerable and applies the given callback to all values of the enumerable as long as the callback returns {:ok, mapped_value}.

Stops when the callback returns {:error, term} and returns that tuple.

Returns {:error, {:bad_return, {callback, [item]}, returned_value}} if the callback does not return a result tuple.

Returns {:ok, mapped_values} or {:error, term}

Wrapping ok.

Converts a value to an :ok tuple, except when the value is:

  • the single atom :ok or an :ok tuple
  • the single atom :error or an :error tuple

Questionning ok.

Returns true if the value is an {:ok, val} tuple or the single atom :ok.

Returns false otherwise.

Link to this function

reduce_ok(enum, initial, f)

View Source

Specs

reduce_ok(
  Enumerable.t(),
  term(),
  (term(), term() -> {:ok, term()} | {:error, term()})
) ::
  {:ok, term()} | {:error, term()}

Reducing while ok. Takes an enumerable, an initial value for the accumulator and a reducer function. Calls the reducer for each value in the enumerable as long as the reducer returns {:ok, new_acc}.

Stops when the reducer returns {:error, term} and returns that tuple.

Returns {:error, {:bad_return, {reducer, [item, acc]}, returned_value}} if the reducer does not return a result tuple.

This function is deprecated. Match on the values or use the raising version uok!/1.

Unwrapping ok.

Unwraps an {:ok, val} tuple, giving only the value, returning anything else as-is. Does not unwrap {:error, ...} tuples.

This function should not be used as it leads to ambiguous code where errors are still wrapped in tuples but values are "naked". A case pattern matching on that type would be very unusual in Elixir/Erlang. Match on the original value or use uok!/1.

Unwrapping ok with raise.

Unwraps an {:ok, val} tuple, giving only the value, or returns the single :ok atom as-is. Raises with any other value.

wok is an alias of wrapping function :ok.

Unwrapping ok, raising custom exceptions.

Much like uok!/1 but if an :error 2-tuple contains any exception as the second element, that exception will be raised.

Other values will lead to a generic Ark.Ok.UnwrapError exception to be reaised.