View Source AbsintheUtils.Helpers.Sort (absinthe_utils v0.0.2)

Generic sorting utils.

Link to this section Summary

Functions

Given an enumerable, returns a map of each element to the position in the original enumerable (zero based).

Sorts an unsorted_enumerable based on sorted_enumerable. unsorted_enumerable cannot contain duplicates and can only contain elements from sorted_enumerable.

Link to this section Functions

Link to this function

map_enum_to_index(enumerable)

View Source
@spec map_enum_to_index([any()]) :: map()

Given an enumerable, returns a map of each element to the position in the original enumerable (zero based).

examples

Examples

iex> Sort.map_enum_to_index([:a, :b, :c])
%{a: 0, b: 1, c: 2}
Link to this function

sort_alike(unsorted_enumerable, sorted_enumerable, unsorted_enumerable_mapper \\ & &1, sorted_enumerable_mapper \\ & &1)

View Source

Sorts an unsorted_enumerable based on sorted_enumerable. unsorted_enumerable cannot contain duplicates and can only contain elements from sorted_enumerable.

Use mappers to specify getters for each element in the enumerable.

examples

Examples

iex> Sort.sort_alike([:b, :c, :a], [:a, :b, :c])
[:a, :b, :c]