Thanks to visit codestin.com
Credit goes to hexdocs.pm

Exit (exit v0.4.2)

Various iteration utilities

Description

Mostly wrappers for common patterns using Enum module

Summary

Functions

Find an object with fields that match

Find where a given field matches the given value

Find an object with fields that match

Find where a given field matches the given value

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

Key an enumerable on the id field

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

find(items, match)

Find an object with fields that match

find(items, fld, val)

Find where a given field matches the given value

find!(items, match)

Find an object with fields that match

find!(items, fld, val)

Find where a given field matches the given value

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_by_id(items)

Key an enumerable on the id field

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.