Skip to content

Instantly share code, notes, and snippets.

@iain17 iain17/Bill.erl
Last active Apr 6, 2017

Embed
What would you like to do?
Assignment: Consider a shopping list that looks like [{item quantity price}, ...]. Write a list comprehension that builds a list of items of the form [{item total_price}, ...], where total_price is quantity times price.
[{"Beer", 2.50, 8}, {"Snacks", 1.99, 4}]
-module(total_price).
-export([calc_bill/1]).
%Assignment: Consider a shopping list that looks like [{item quantity price}, ...]. Write a list comprehension that builds a list of items of the form [{item total_price}, ...], where total_price is quantity times price.
% Using a pipe, go through each part of the list and do the calculation. Then return this.
calc_bill(Bill) ->
[{Item, Quantity * Price} || {Item, Quantity, Price} <- Bill].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.