Passing a function to Enum.map in Elixir -
i'm learning elixir , wonder if there better way pass function pointer enum.map. have code:
defmodule mymodule defp greet(person) io.puts "hello " <> person end def main() people = ["manuel bartual", "el hijo de la tomasa"] enum.map(people, &greet/1) end end
it works fine, wonder if there way instead of using &greet/1
more idiomatic be:
def main ["manuel bartual", "el hijo de la tomasa"] |> enum.map(&greet/1) end
you should not use parentheses when no arguments required in function.
the pipeline operator (
|>
) 1 of idiomatic elixir features. says, take result evaluated , call following function passing result first argument.
wiki
Comments
Post a Comment