Skip to content

Commit

Permalink
Use :lists.zipwith/4 in Enumerable impl for Xandra.Page
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Oct 24, 2023
1 parent 994a33d commit 9c9ce9b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/xandra/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,18 @@ defmodule Xandra.Page do
end

defp reduce([values | rest], columns, {:cont, acc}, fun) do
row = zip(values, columns, []) |> :maps.from_list()
# With :fail, this fails if the lists are not the same length, which is what we want.
row =
fn val, {_, _, name, _} = _col -> {name, val} end
|> :lists.zipwith(values, columns, _how = :fail)
|> :maps.from_list()

reduce(rest, columns, fun.(row, acc), fun)
end

defp reduce([], _columns, {:cont, acc}, _fun) do
{:done, acc}
end

defp zip([], [], acc), do: acc

defp zip([value | values], [{_, _, name, _} | columns], acc) do
zip(values, columns, [{name, value} | acc])
end
end

defimpl Inspect do
Expand Down

0 comments on commit 9c9ce9b

Please sign in to comment.