Last active
December 18, 2016 04:41
-
-
Save rsgrafx/d3103a4d7f7e3400fac24242192e5d87 to your computer and use it in GitHub Desktop.
Citrusbyte. list reduce 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 Citrusbyte do | |
@moduledoc """ | |
This module - demonstrates use of pattern matching in Elixir to modify a list. | |
[[1,2,[3]],4] -> [1,2,3,4] | |
Usage: | |
Citrusbyte.example [[1,2,[3]],4] #=> [1,2,3,4] | |
""" | |
def example([h|t], capture \\ []) when is_integer(h) do | |
example(t, capture ++ [h]) | |
end | |
def example([h|t], capture) do | |
example(h ++ t, capture) | |
end | |
# Exit function -> | |
def example([], capture) do | |
capture | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment