Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 列表理解与长生不老药计数器_Elixir - Fatal编程技术网

Elixir 列表理解与长生不老药计数器

Elixir 列表理解与长生不老药计数器,elixir,Elixir,有没有办法在理解中添加循环计数器 例如,不带计数器的理解: for c <- ["a", "b"], do: c # => ["a", "b"] c[“a”,“b”] 我怎样才能加上计数器呢?大概是这样的: for c <- ["a", "b"], do: {counter, c} # => [{0, "a"}, {1, "b"}] 对于c[{0,“a”},{1,“b”}] 使用: iex(1)>用于{c,counter} iex(1)>

有没有办法在理解中添加循环计数器

例如,不带计数器的理解:

for c <- ["a", "b"], do: c            # => ["a", "b"]
c[“a”,“b”] 我怎样才能加上计数器呢?大概是这样的:

for c <- ["a", "b"], do: {counter, c} # => [{0, "a"}, {1, "b"}]
对于c[{0,“a”},{1,“b”}]
使用:

iex(1)>用于{c,counter}
iex(1)> for {c, counter} <- Enum.with_index(["a", "b"]), do: {counter, c}
[{0, "a"}, {1, "b"}]