Exit (exit v0.3.0)

Various iteration utilities

Description

Mostly wrappers for common patterns using Enum module

Summary

Functions

Convert a list of maps to a map of keys to the maps

Convert a list of maps to a map of items keyed by a given field

Given a list of maps with an id field, return a list of the ids

Given a list, reject any that are nil

Rotate a list by moving the first item from the beginning to the end

Rotate a list n times

Rotate through items until the item is true for f

Rotate through items while each item is true for f

Given 2 maps. zip them where the value is a tuple with the first and second elements belonging to the first and second maps, respectively. If a map does not have an element, the tuple will contain a nil.

Functions

key_by(items, key_f)

@spec key_by([map()], term()) :: map()

Convert a list of maps to a map of keys to the maps

key_on!(items, key_name)

@spec key_on!([map() | tuple()], term()) :: map()

Convert a list of maps to a map of items keyed by a given field

Will raise an exception if the given field does not exist. Also works on a list of enums with an element index.

map_to_id(items)

@spec map_to_id([%{id: a :: term()}]) :: [a :: term()]

Given a list of maps with an id field, return a list of the ids

reject_nil(items)

@spec reject_nil([term()]) :: [term()]

Given a list, reject any that are nil

rotate(items)

@spec rotate([a :: term()]) :: [a :: term()]

Rotate a list by moving the first item from the beginning to the end

rotate(items, n)

@spec rotate([a :: term()], integer()) :: [a :: term()]

Rotate a list n times

Move the first n items to the back of the list

rotate_until(items, f)

@spec rotate_until([a :: term()], (a :: term() -> as_boolean(term()))) :: [
  a :: term()
]

Rotate through items until the item is true for f

rotate_while(items, f)

@spec rotate_while([a :: term()], (a :: term() -> as_boolean(term()))) :: [
  a :: term()
]

Rotate through items while each item is true for f

zip_maps(m0, m1)

@spec zip_maps(map(), map()) :: %{required(any()) => tuple()}

Given 2 maps. zip them where the value is a tuple with the first and second elements belonging to the first and second maps, respectively. If a map does not have an element, the tuple will contain a nil.

zip_maps(m0, m1, m2)

@spec zip_maps(map(), map(), map()) :: %{required(any()) => tuple()}

Zip 3 maps

The same behavior as zip_maps/2 but with 3 maps.