Skip to content

Instantly share code, notes, and snippets.

@taiansu
Last active March 29, 2018 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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