antikythera v0.4.0 Antikythera.EnumUtil View Source

Utility functions to work with enumerables.

Link to this section Summary

Functions

A variant of Enum.find/2 that raises an exception when no matching element is found.

A variant of Enum.find_value/2 that raises an exception when no matching element is found.

Updates items of an enumerable with the given function, depending on context. Context can be any.

Link to this section Types

Specs

context() :: any()

Specs

element() :: Enum.element()

Link to this section Functions

Specs

find!(Enum.t(), (element() -> any())) :: element()

A variant of Enum.find/2 that raises an exception when no matching element is found.

Specs

find_value!(Enum.t(), (element() -> any())) :: any()

A variant of Enum.find_value/2 that raises an exception when no matching element is found.

Link to this function

map_with_context(e, c, fun)

View Source

Specs

map_with_context(
  Enum.t(),
  context(),
  (element(), context() -> {element(), context()})
) :: [element()]

Updates items of an enumerable with the given function, depending on context. Context can be any.

The function fun takes item and context as arguments, and must achieve 2 purposes:

  1. Update an item according to current context
  2. Produces new context for next item

then, return both as tuple {new_item, new_context}.