View Source ExAequoFn.Transformer (ExAequoFn v0.1.2)

Implements functional transformation helpers

many

many takes a list and a list of transsformers. A transformer is simply a function that returns either {:ok, value} or :error

The list is traversed by calling all transformers on each element of the list until the first transformer returns an {:ok, value} tuple in which case the element is replaced by value. If a transformer returning an :ok value is found for all elements, then the tuple {:ok, [transformed values,...]} is returned, otherwise :error is returned

iex(1)> ft = %{a: 1, b: 2}
...(1)> st = %{a: 2, x: 3}
...(1)> ff = &Map.fetch(ft, &1)
...(1)> sf = &Map.fetch(st, &1)
...(1)> assert many([:a, :x], [ff, sf]) == {:ok, [1, 3]}
...(1)> assert many([:a, :z], [ff, sf]) == :error

Summary

Types

@type binary?() :: maybe(binary())
Link to this type

either_t(error_t, ok_t)

View Source
@type either_t(error_t, ok_t) :: {:ok, ok_t} | {:error, error_t}
@type function_t() :: (... -> any())
@type maybe(t) :: nil | t
@type result_t(t) :: {:ok, t} | :error
@type stream_t() :: %Stream{accs: term(), done: term(), enum: term(), funs: term()}
@type transformer_t() :: (any() -> result_t(any()))
@type transformers_t() :: [transformer_t()]

Functions

Link to this function

many(values, transformers)

View Source
@spec many(list(), transformers_t()) :: result_t(list())