Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now tired of having everything in the same file.
Scrolling! Boo!
- Loading branch information
Showing
2 changed files
with
31 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
defmodule HillelBudget do | ||
@moduledoc """ | ||
Documentation for `HillelBudget`. | ||
""" | ||
def remaining_total_after_bill(limit, bill) do | ||
item_charges = for item <- bill do | ||
count = Map.get(item, :count, 1) | ||
item.cost * count | ||
end | ||
|
||
limit - Enum.sum(item_charges) | ||
end | ||
|
||
def can_afford?(budget, bill) do | ||
remaining_total_after_bill(budget.total_limit, bill) >= 0 | ||
end | ||
|
||
@doc """ | ||
Hello world. | ||
def budget(total_limit) do | ||
%{total_limit: total_limit} | ||
end | ||
|
||
# I noticed that I'd gotten my terminology messed up, using "bills and bill" | ||
# instead of "bill and item" | ||
|
||
## Examples | ||
def normalize(item) when is_map(item) do | ||
cost = item.cost | ||
categories = Map.get(item, :categories, []) | ||
count = Map.get(item, :count, 1) | ||
|
||
iex> HillelBudget.hello() | ||
:world | ||
Enum.map(1..count, fn _ -> | ||
%{cost: cost, categories: categories} | ||
end) | ||
end | ||
|
||
""" | ||
def hello do | ||
:world | ||
def normalize(bill) when is_list(bill) do | ||
Enum.flat_map(bill, &normalize/1) | ||
end | ||
end |
This file contains 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