Skip to content

Instantly share code, notes, and snippets.

@iain17
Last active April 6, 2017 19:21
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 iain17/ec227b12ad1f0bdd234d0604adc04509 to your computer and use it in GitHub Desktop.
Save iain17/ec227b12ad1f0bdd234d0604adc04509 to your computer and use it in GitHub Desktop.
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