defmodule MyList do def map([], _func), do: [] def map([head|tail], func), do: [func.(head) | map(tail, func)] def reduce([], value, _func) do value end def reduce([head|tail], value, func) do reduce(tail, func.(head, value), func) end def span(from, to) when from == to, do: [to] def span(from, to), do: [from | span(from + 1, to)] end
^o^ > iex practice_7_4.exs Eshell V8.0 (abort with ^G) Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> MyList.span(3, 7) [3, 4, 5, 6, 7]
map
も reduce
も使ってないな。