Wilson
Wilson

Reputation: 23

iterate over two list simultaneously in elixir

I have 2 list (can be another data type also) that represent 2 vector clocks. How can I iterate over the two list simultaneously and verified this condition: w[k] <= v[k] for each k != j, where j is a parameter?

Upvotes: 1

Views: 1460

Answers (1)

Dogbert
Dogbert

Reputation: 222118

You're looking for Enum.zip/2:

def check(w, v, j) do
  Enum.zip(w, v)
  |> Enum.with_index
  |> Enum.all?(fn {{ww, vv}, k} -> k == j || ww <= vv end)
end

Upvotes: 7

Related Questions