Elixir Language Functional programming in Elixir Map

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Map is a function which will take an array and a function and return an array after applying that function to each element in that list

defmodule MyList do
  def map([], _func) do
    []
  end

  def map([head | tail], func) do
    [func.(head) | map(tail, func)]
  end
end

Copy paste in iex and execute:

MyList.map [1,2,3], fn a -> a * 5 end

Shorthand syntax is MyList.map [1,2,3], &(&1 * 5)



Got any Elixir Language Question?