ExAequoBase.Fn (ExAequoBase v0.1.6)

View Source

Functional Helpers

Summary

Functions

Runs the first function that does not return nil

Types

atoms()

@type atoms() :: [atom()]

binaries()

@type binaries() :: [binary()]

either(lt, rt)

@type either(lt, rt) :: ok_t(lt) | error_t(rt)

error_t()

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

error_t(t)

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

input_source_t()

@type input_source_t() :: Enumerable.t() | binary() | binaries()

maybe(t)

@type maybe(t) :: nil | t

natural()

@type natural() :: non_neg_integer()

numbered(t)

@type numbered(t) :: {t, number()}

numbered_line_t()

@type numbered_line_t() :: numbered(binary())

numbered_lines_t()

@type numbered_lines_t() :: [numbered_line_t()]

ok_t()

@type ok_t() :: {:ok, any()}

ok_t(t)

@type ok_t(t) :: {:ok, t}

pair_t()

@type pair_t() :: {any(), any()}

pair_t(t)

@type pair_t(t) :: {t, t}

pair_t(lt, rt)

@type pair_t(lt, rt) :: {lt, rt}

pairs_t()

@type pairs_t() :: [pair_t()]

pairs_t(t)

@type pairs_t(t) :: [pair_t(t)]

pairs_t(lt, rt)

@type pairs_t(lt, rt) :: [pair_t(lt, rt)]

parser_fn()

@type parser_fn() :: (binary() -> any())

reducer_result_t()

@type reducer_result_t() :: {:halt, error_t()} | {:cont, ok_t()}

result_fun_t()

@type result_fun_t() :: (any() -> result_t())

result_fun_t(t)

@type result_fun_t(t) :: (any() -> result_t(t))

result_t()

@type result_t() :: either(any(), binary())

result_t(t)

@type result_t(t) :: either(t, binary())

rgx_pair()

@type rgx_pair() :: {Regex.t(), ExAequoFn.NamedFn.t()}

rgx_pairs()

@type rgx_pairs() :: [rgx_pair()]

stream_t()

@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()
    }

zero_fn_t()

@type zero_fn_t() :: (-> any())

zero_fn_t(t)

@type zero_fn_t(t) :: (-> t)

Functions

select(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"}