EnumExtras (enum_extras v0.1.0) View Source

Provides additional utility functions for working with enumerables.

Link to this section Summary

Functions

Calculates the average of the elements in the enumerable.

Partitions the elements of the enumerable according to the pairwise comparator.

Calculates the weighted average of the elements in the enumerable.

Link to this section Types

Link to this section Functions

Specs

average(t()) :: nil | integer()

Calculates the average of the elements in the enumerable.

It should return nil if the enumerable is empty.

Link to this function

chunk_by_pairwise(values, comparator)

View Source

Specs

chunk_by_pairwise(t(), (element(), element() -> boolean())) :: t()

Partitions the elements of the enumerable according to the pairwise comparator.

Examples

iex> EnumExtras.chunk_by_pairwise([1, 2, 3, 4, 1, 2, 3, 1, 2, 1], fn a, b -> a <= b end)
[[1, 2, 3, 4], [1, 2, 3], [1, 2], [1]]
Link to this function

weighted_average(list, weights)

View Source

Specs

weighted_average(t(), t()) :: nil | integer()

Calculates the weighted average of the elements in the enumerable.

It should return nil if the enumerable is empty or the weights sum to zero.