Created
April 16, 2015 23:08
-
-
Save brianium/bc1c9d416a5b7745c20f to your computer and use it in GitHub Desktop.
list span in elixir
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 MyList do | |
def span(from, to), do: _span(from, to, []) | |
defp _span(from, to, list) when from == to do | |
list ++ [to] | |
end | |
defp _span(from, to, list) do | |
list ++ [from | _span(from + 1, to, list) ] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment