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 
  1. you should not use parentheses when no arguments required in function.

  2. the pipeline operator (|>) 1 of idiomatic elixir features. says, take result evaluated , call following function passing result first argument.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -