grangerelixx
Passing list values to a function
I have a list of maps.
For example,
students = [%{ sid: 1, name: "Bob", score: 80}, %{ sid: 2, name: "Kelly", score: 60},.....]
I have a function that accepts a single student map as a parameter,
calculate_percentage(student) do
something
end
I want to be able to pass each map in students list to calculate_percentage function. I tried Enum.map but that returns a list again. Can I know how to pass each value in a list one by one to the calculate_percentage function? Any suggestions are appreciated.
Thanks! 
Most Liked
derek-zhou
I think you are confused about what is side-effect. A function converts inputs to outputs. If the function does only this and nothing else, it is called a pure function, or a function without side effect. A side effect is something you want to achieve in addition to the conversion: Writing databases, sending some data to the network, etc.
If you don’t want side effect and don’t care about the return value, then there is really no point calling the function.
The :ok is just a place holder for the return value. In Elixir there is no void function. You are welcomed to discard the meaningless return value.
derek-zhou
If you want side effect only, then use Enum.each/2







