Last active
June 15, 2016 18:53
-
-
Save PragTob/546d586fb000cc80c08d564c65235dfd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 _map_tco([], list, function) | |
end | |
defp _map_tco(acc, [head | tail], function) do | |
_map_tco([function.(head) | acc], tail, function) | |
end | |
defp _map_tco(acc, [], _function) do | |
acc | |
end | |
def map_tco_concat(acc \\ [], list, function) | |
def map_tco_concat(acc, [head | tail], function) do | |
map_tco_concat(acc ++ [function.(head)], tail, function) | |
end | |
def map_tco_concat(acc, [], _function) do | |
acc | |
end | |
def map_body([], _func), do: [] | |
def map_body([head | tail], func) do | |
[func.(head) | map_body(tail, func)] | |
end | |
def map_tco_no_reverse(list, function) do | |
_map_tco([], list, function) | |
end | |
end |
This file contains hidden or 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
pllsss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment