Raxol.Core.Utils.List (Raxol Core v2.4.0)

Copy Markdown View Source

Shared list and collection utilities.

Summary

Functions

Wraps a non-list value in a list. Returns lists unchanged.

Zips two lists, padding the shorter one with nil.

Functions

ensure_list(value)

@spec ensure_list(list()) :: list()
@spec ensure_list(term()) :: [term()]

Wraps a non-list value in a list. Returns lists unchanged.

Examples

iex> Raxol.Core.Utils.List.ensure_list([1, 2])
[1, 2]

iex> Raxol.Core.Utils.List.ensure_list(:foo)
[:foo]

zip_longest(list1, list2)

@spec zip_longest(list(), list()) :: [{term(), term()}]

Zips two lists, padding the shorter one with nil.

Unlike Enum.zip/2, this does not truncate to the shorter list.

Examples

iex> Raxol.Core.Utils.List.zip_longest([1, 2, 3], [:a, :b])
[{1, :a}, {2, :b}, {3, nil}]

iex> Raxol.Core.Utils.List.zip_longest([1], [2, 3])
[{1, 2}, {nil, 3}]