~statianzo/sevenlangs

sevenlangs/erlang/lookup.erl -rw-r--r-- 309 bytes
2fcd4511Jason Staten day one logic style 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
-module(lookup).

-export([by_key/2]).

by_key(_, []) -> "unknown";
by_key(Key, [{Key, Val} | _]) -> Val;
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_