View Source ExAequoBase.Fn (ExAequoBase v0.1.3)

Functional Helpers

Summary

Functions

Runs the first function that does not return nil

Types

@type atoms() :: [atom()]
@type binaries() :: [binary()]
@type either(lt, rt) :: ok_t(lt) | error_t(rt)
@type error_t() :: {:error, binary()}
@type error_t(t) :: {:error, t}
@type input_source_t() :: Enumerable.t() | binary() | binaries()
@type maybe(t) :: nil | t
@type natural() :: non_neg_integer()
@type numbered(t) :: {t, number()}
@type numbered_line_t() :: numbered(binary())
@type numbered_lines_t() :: [numbered_line_t()]
@type ok_t() :: {:ok, any()}
@type ok_t(t) :: {:ok, t}
@type reducer_result_t() :: {:halt, error_t()} | {:cont, ok_t()}
@type result_fun_t() :: (any() -> result_t())
@type result_fun_t(t) :: (any() -> result_t(t))
@type result_t() :: either(any(), binary())
@type result_t(t) :: either(t, binary())
@type stream_t() ::
  %IO.Stream{device: term(), line_or_bytes: term(), raw: term()}
  | %File.Stream{
      line_or_bytes: term(),
      modes: term(),
      node: term(),
      path: term(),
      raw: term()
    }
@type zero_fn_t() :: (-> any())
@type zero_fn_t(t) :: (-> t)

Functions

@spec select([zero_fn_t()]) :: any()

Runs the first function that does not return nil

iex(1)> fns = [
...(1)> fn -> nil end,
...(1)> fn -> 42 end,
...(1)> fn -> "not reached" end
...(1)> ]
...(1)> select(fns)
42

Returns an error if no function matched

iex(2)> select([fn -> nil end])
{:error, "No functions matched"}

Even if the input was empty

iex(3)> select([])
{:error, "No functions matched"}