Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active August 18, 2017 06:05
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 shankardevy/141eedd7ec9bc61c5bc948a1c6fd043e to your computer and use it in GitHub Desktop.
Save shankardevy/141eedd7ec9bc61c5bc948a1c6fd043e to your computer and use it in GitHub Desktop.
defmodule Mango.Catalog do
alias Mango.Catalog.Product
def list_products do
product1 = %Product{ name: "Tomato", price: 50, is_seasonal: false, category: "vegetables" }
product2 = %Product{ name: "Apple", price: 100, is_seasonal: true, category: "fruits" }
[product1, product2]
end
def list_seasonal_products do
list_products()
|> Enum.filter(fn(product) -> product.is_seasonal == true end)
end
def get_category_products(name) do
list_products()
|> Enum.filter(fn(product) -> product.category == name end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment