4 ms·
Now in a Functional lang, that has good scoping and private functions, etc. defmodule Pizza do import Pizza.Pizza, only: [new: 0] import Pizza.
by weatherlight 3y ago
Now in a Functional lang, that has good scoping and private functions, etc.
defmodule Pizza do
import Pizza.Pizza, only: [new: 0]
import Pizza.Order, only: [new: 0]
def create_pizza(order, oven_temp) do
order
|> prepare_pizza()
|> bake_pizza(oven_temp)
|> box_pizza()
end
defp prepare_pizza(%Pizza.Order{size: size, sauce: sauce, kind: kind}) do
toppings =
case kind do
"Veg" -> ["Tomato", "Bell Pepper"]
"Meat" -> ["Pepperoni", "Sausage"]
_ -> []
end
%Pizza.Pizza{base: size, sauce: sauce, toppings: toppings}
end
defp bake_pizza(oven_temp, %Pizza.Pizza{baked: _baked} = pizza) when oven_temp >= 400 do
%Pizza.Pizza{pizza | baked: true}
end
defp bake_pizza(_, pizza), do: pizza
defp box_pizza(%Pizza.Pizza{boxed: _boxed, sliced: _sliced, ready: _ready} = pizza) do
%Pizza.Pizza{pizza | boxed: true, sliced: true, ready: true}
end
end