~statianzo/sevenlangs

c079ef120d60b3abc5051f0dcbdc7d1a3d2c5a1d — Jason Staten 1 year, 10 months ago c1ca0d5
maps and records oh my
2 files changed, 18 insertions(+), 1 deletions(-)

A erlang/drivers.erl
M erlang/lookup.erl
A erlang/drivers.erl => erlang/drivers.erl +16 -0
@@ 0,0 1,16 @@
-module(drivers).

-record(person, {name, fastest_time = 0.0}).

-export([champion/1]).

fastest(A, B)
    when A#person.fastest_time < B#person.fastest_time ->
    A;
fastest(_, B) -> B.

champion(Drivers) ->
    lists:foldr(fun fastest/2,
		#person{name = "Ghost",
			fastest_time = 9.99989999999999963620e+3},
		Drivers).

M erlang/lookup.erl => erlang/lookup.erl +2 -1
@@ 4,7 4,8 @@

by_key(_, []) -> "unknown";
by_key(Key, [{Key, Val} | _]) -> Val;
by_key(Key, [_ | Tail]) -> by_key(Key, Tail).
by_key(Key, [_ | Tail]) -> by_key(Key, Tail);
by_key(Key, M) when is_map(M) -> maps:get(Key, M).

% lookup:by_key(birthday, [{ice, "cream"}, {birthday, "cake"}]).
% equivalent to proplists:get_value/2_