Created
October 10, 2023 18:43
-
-
Save rlipscombe/868bbde6990e5ba4fbecb1d101b6e7ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(kvl). | |
-export([from_list/1]). | |
from_list(KVs) -> | |
from_list(KVs, #{}). | |
from_list([K, V | KVs], Acc) -> | |
from_list(KVs, Acc#{K => V}); | |
from_list([], Acc) -> | |
Acc. | |
-ifdef(TEST). | |
-include_lib("eunit/include/eunit.hrl"). | |
from_list_test() -> | |
?assertEqual(#{k1 => v1, k2 => v2}, from_list([k1, v1, k2, v2])). | |
-endif. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Response to question posed at https://hachyderm.io/@[email protected]/111212077552255802