Created
January 30, 2017 11:36
-
-
Save ghatighorias/ecc0bed1770fcfb2e809e58b3cd4449e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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