A collection of utility functions for working with lists, maps, keyword lists, and strings. This module is a convenience wrapper around the various Algo submodules, providing a single namespace for importing functions.

Summary

Enumerable functions

Returns whether every element in an enumerable is unique.

Returns whether all elements are unique after applying a function.

Higher-order functions

Returns a comparator that checks equality after applying a function.

List functions

Map and keyword list functions

Enumerable functions

all_different?(enumerable)

@spec all_different?(Enumerable.t()) :: boolean()

Returns whether every element in an enumerable is unique.

Examples

iex> Algo.all_different?([1, 2, 3])
true

iex> Algo.all_different?([1, 2, 1])
false

all_different_by?(enumerable, fun)

@spec all_different_by?(Enumerable.t(), (any() -> any())) :: boolean()

Returns whether all elements are unique after applying a function.

Examples

iex> Algo.all_different_by?(["a", "bb", "ccc"], &String.length/1)
true

iex> Algo.all_different_by?(["a", "b"], &String.length/1)
false

Higher-order functions

eq_by?(fun)

@spec eq_by?((any() -> any())) :: (any(), any() -> boolean())

Returns a comparator that checks equality after applying a function.

Examples

iex> same_length? = Algo.eq_by?(&String.length/1)
iex> same_length?.("a", "b")
true

iex> same_length? = Algo.eq_by?(&String.length/1)
iex> same_length?.("a", "bb")
false

iex> Algo.unique_with(["a", "bb", "c"], Algo.eq_by?(&String.length/1))
["a", "bb"]

List functions

chunk_while_adjacent(list, fun)

See Algo.List.chunk_while_adjacent/2.

difference_by(left, right, key_fun)

See Algo.List.difference_by/3.

difference_with(left, right, fun)

See Algo.List.difference_with/3.

get_cartesian_product(list1, list2, output_as)

See Algo.List.get_cartesian_product/3.

get_permutations(list)

See Algo.List.get_permutations/1.

get_subsequences(list)

See Algo.List.get_subsequences/1.

get_symmetric_difference_by(left, right, key_fun)

See Algo.List.get_symmetric_difference_by/3.

get_symmetric_difference_with(left, right, fun)

See Algo.List.get_symmetric_difference_with/3.

get_unique_pairs(list, output_as)

See Algo.List.get_unique_pairs/2.

index_by(enumerable, fun)

See Algo.List.index_by/2.

inner_join(left, right, fun)

See Algo.List.inner_join/3.

intersect_by(left, right, key_fun)

See Algo.List.intersect_by/3.

intersect_with(left, right, fun)

See Algo.List.intersect_with/3.

interweave(list1, list2)

See Algo.List.interweave/2.

map_accum(list, acc, fun)

See Algo.List.map_accum/3.

map_accum_right(list, acc, fun)

See Algo.List.map_accum_right/3.

move_at(list, from_index, to_index)

See Algo.List.move_at/3.

partition_map(enumerable, fun)

See Algo.List.partition_map/2.

reduce_by(enumerable, key_fun, initial_acc, reduce_fun)

See Algo.List.reduce_by/4.

split_whenever(list, fun)

See Algo.List.split_whenever/2.

transpose(rows)

See Algo.List.transpose/1.

unique_with(enumerable, fun)

See Algo.List.unique_with/2.

unwind(enumerable, field)

See Algo.List.unwind/2.

Map and keyword list functions

as_keyword_list(map)

See Algo.Assoc.as_keyword_list/1.

as_map(kw_list)

See Algo.Assoc.as_map/1.

atomise_keys_with(map, key_fun)

See Algo.Assoc.atomise_keys_with/2.

atomize_keys_with(map, key_fun)

See Algo.Assoc.atomize_keys_with/2.

deep_merge_left(left_map, right_map)

See Algo.Assoc.deep_merge_left/2.

deep_merge_right(left_map, right_map)

See Algo.Assoc.deep_merge_right/2.

deep_merge_with(left_map, right_map, fun)

See Algo.Assoc.deep_merge_with/3.

delete_path(map, path)

See Algo.Assoc.delete_path/2.

each_breadth_first(map, fun)

See Algo.Assoc.each_breadth_first/2.

each_depth_first(map, fun)

See Algo.Assoc.each_depth_first/2.

equivalent?(map, kw_list)

See Algo.Assoc.equivalent?/2.

evolve(map, evolution_map)

See Algo.Assoc.evolve/2.

fetch_path(map, path)

See Algo.Assoc.fetch_path/2.

fetch_path!(map, path)

See Algo.Assoc.fetch_path!/2.

get_depth(map)

See Algo.Assoc.get_depth/1.

get_path(map, path, default \\ nil)

See Algo.Assoc.get_path/3.

get_paths(map)

See Algo.Assoc.get_paths/1.

get_values_at_paths(map, paths)

See Algo.Assoc.get_values_at_paths/2.

has_path?(map, path)

See Algo.Assoc.has_path?/2.

invert(map)

See Algo.Assoc.invert/1.

merge_left(left_map, right_map)

See Algo.Assoc.merge_left/2.

merge_right(left_map, right_map)

See Algo.Assoc.merge_right/2.

path_satisfies?(map, path, fun)

See Algo.Assoc.path_satisfies?/3.

project(list_of_maps, keys)

See Algo.Assoc.project/2.

prop(name)

See Algo.Assoc.prop/1.

props(names)

See Algo.Assoc.props/1.

put_new_path(map, path, value)

See Algo.Assoc.put_new_path/3.

put_path(map, path, value)

See Algo.Assoc.put_path/3.

rename_keys(map, renames)

See Algo.Assoc.rename_keys/2.

replace_path(map, path, value)

See Algo.Assoc.replace_path/3.

replace_path!(map, path, value)

See Algo.Assoc.replace_path!/3.

stringify_keys(map)

See Algo.Assoc.stringify_keys/1.

unnest_keys(map)

See Algo.Assoc.unnest_keys/1.

update_path(map, path, initial, fun)

See Algo.Assoc.update_path/4.

update_path!(map, path, fun)

See Algo.Assoc.update_path!/3.

where_all?(map, condition_map)

See Algo.Assoc.where_all?/2.

where_any?(map, condition_map)

See Algo.Assoc.where_any?/2.

where_eq?(map, condition_map)

See Algo.Assoc.where_eq?/2.

String functions

humanise(str)

See Algo.String.humanise/1.

humanize(str)

See Algo.String.humanise/1.