View Source Moar.Tuple (Moar v1.4.0)

Link to this section Summary

Functions

Converts a list of tuples to a single tuple where the first element is the first element of the first tuple, and the second element is a list of the second elements of each tuple. Raises if the first element in each tuple is not homogeneous.

Link to this section Functions

@spec from_list!([any()]) :: {any(), [any()]}

Converts a list of tuples to a single tuple where the first element is the first element of the first tuple, and the second element is a list of the second elements of each tuple. Raises if the first element in each tuple is not homogeneous.

iex> Moar.Tuple.from_list!([{:ok, :a}, {:ok, :b}])
{:ok, [:a, :b]}

iex> Moar.Tuple.from_list!([{:a, 1}, {:a, 2}, {:a, 3}])
{:a, [1, 2, 3]}

iex> Moar.Tuple.from_list!([{:a, 1}, {:b, 2}, {:a, 3}])
** (RuntimeError) Expected all items in the list to have have the same first element, but got: [:a, :b]