Another option are streams:
list = [1, 2, 3, 4]
stream =
Stream.transform(list, list, fn _, [cur | rest] ->
{Enum.map(rest, &{cur, &1}), rest}
end)
Enum.into(stream, [])
# [{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}]
Another option are streams:
list = [1, 2, 3, 4]
stream =
Stream.transform(list, list, fn _, [cur | rest] ->
{Enum.map(rest, &{cur, &1}), rest}
end)
Enum.into(stream, [])
# [{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}]