Skip to content

Instantly share code, notes, and snippets.

@japaz
Created November 23, 2011 21:39
Show Gist options
  • Save japaz/1390002 to your computer and use it in GitHub Desktop.
Save japaz/1390002 to your computer and use it in GitHub Desktop.
7L7W Erlang - Day2
% 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.
-module(comprehesion).
ShoppingList = [{apple, 4, 0.2}, {orange, 3, 1.1}, {peach, 4, 1}].
Total = [{Product, Quantity * Price} || {Product, Quantity, Price} <- ShoppingList].
% Consider a list of keyword-value tuples, such as [{erlang, "a functional
% language"}, {ruby, "an OO language"}]. Write a function that accepts
% the list and a keyword and returns the associated value for
% the keyword.
-module(map).
-export([get/2]).
get([], _) -> "";
get([{Key, Value}|_], Key) -> Value;
get([_|Tail], Key) -> get(Tail, Key).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment