List comprehension with counter in Elixir

Viewed 7099

Is there a way to add loop counter to the comprehension?

For example, the comprehension without counter:

for c <- ["a", "b"], do: c            # => ["a", "b"]

How can I add counter to it? Something like this:

for c <- ["a", "b"], do: {counter, c} # => [{0, "a"}, {1, "b"}]
1 Answers
Related