sandbox/pe/shop.erl

16 lines
345 B
Erlang
Raw Normal View History

2019-04-22 02:25:01 +00:00
-module(shop).
2019-04-22 14:01:00 +00:00
-export([cost/1, total/1]).
2019-04-22 02:25:01 +00:00
2019-04-22 14:01:00 +00:00
%% ShoppingList = [{oranges,4},{newspaper,1},{apples,10},{pears,6},{milk,3}]
cost (oranges) -> 5;
cost (newspaper) -> 8;
cost (apples) -> 2;
cost (pears) -> 9;
cost (milk) -> 7.
2019-04-22 02:25:01 +00:00
2019-04-22 23:49:46 +00:00
total(ShoppingList) ->
lists:sum(
lists:map(fun ({Item, Count}) ->
Count * cost(Item) end,
ShoppingList)).