Skip to content

Instantly share code, notes, and snippets.

@ghatighorias
Created January 30, 2017 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghatighorias/ecc0bed1770fcfb2e809e58b3cd4449e to your computer and use it in GitHub Desktop.
Save ghatighorias/ecc0bed1770fcfb2e809e58b3cd4449e to your computer and use it in GitHub Desktop.
defmodule MyMap do
def map_tco(list, function) do
Enum.reverse do_map_tco([], list, function)
end
defp do_map_tco(acc, [], _function) do
acc
end
defp do_map_tco(acc, [head | tail], func) do
do_map_tco([func.(head) | acc], tail, func)
end
def map_body([], _func), do: []
def map_body([head | tail], func) do
[func.(head) | map_body(tail, func)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment