Skip to content

Instantly share code, notes, and snippets.

@taiansu
Last active March 29, 2018 18:42
Show Gist options
  • Save taiansu/a00c74f7cc8099359fbb04bf964a10b0 to your computer and use it in GitHub Desktop.
Save taiansu/a00c74f7cc8099359fbb04bf964a10b0 to your computer and use it in GitHub Desktop.
Food Functional
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