Last active
March 29, 2018 18:42
-
-
Save taiansu/a00c74f7cc8099359fbb04bf964a10b0 to your computer and use it in GitHub Desktop.
Food Functional
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 Food do | |
def reduce([], _), do: "π΅" | |
def reduce(foods, f), do: Enum.reduce(foods, f) | |
def eat(_, "π"), do: "π" | |
def eat(stuff, _) do | |
if is_food(stuff), do: "π©", else: "π" | |
end | |
def is_food(_), do: true # implement yourself | |
end | |
# Usage | |
import Food | |
reduce([], &eat/2) #=> "π΅" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment