elixir - How to pipe Enum output to another Enum function that takes multiple arguments? -
i'm learning elixir , i'm trying this:
list = enum.with_index ~w[a n b e c r z b d] #=> [{"a", 0}, {"n", 1}, {"b", 2}, {"e", 3}, {"c", 4}, {"r", 5}, {"z", 6}, {"b", 7}, {"d", 8}] enum.into(list, %{}) #=> %{"a" => 0, "b" => 7, "c" => 4, "d" => 8, "e" => 3, "n" => 1, "r" => 5, "z" => 6}
i'd pipe... like:
enum.with_index ~w[a n b e c r z b d] |> enum.into(%{})
or
enum.with_index ~w[a n b e c r z b d] |> enum.into(&1, %{})
but neither of work. possible?
you missing parentheses:
enum.with_index(~w[a n b e c r z b d]) |> enum.into(%{})
or more idiomatically:
~w[a n b e c r z b d] |> enum.with_index() |> enum.into(%{})
your original version executed as:
enum.with_index(~w[a n b e c r z b d] |> enum.into(%{}))
you can see why can't chain string.replace? detailed explanation of this.
Comments
Post a Comment