Skip to content

Instantly share code, notes, and snippets.

@rkellermeyer
Created November 12, 2014 19:32
Show Gist options
  • Save rkellermeyer/3e2130aceb25a765b338 to your computer and use it in GitHub Desktop.
Save rkellermeyer/3e2130aceb25a765b338 to your computer and use it in GitHub Desktop.
Erlang Crud
-module(richards_crud).
-compile(export_all).
new() ->
maps:new().
build(Key, Value, Map) ->
maps:put(Key, Value, Map).
show(Key, Map) ->
maps:get(Key, Map).
update(Key, Value, Map) ->
maps:update(Key,Value,Map).
destroy(Map) ->
maps:without(maps:keys(Map),Map).
1> c(richards_crud).
=> {ok,richards_crud}
2> M1 = richards_crud:new().
=> #{}
3> richards_crud:build("age", 37, M1).
=> {"age" => 37}
4> richards_crud:build("gender", "M", M1).
=> {"gender" => "M"}
Then if I tried to do a maps:find("gender",M1). I would get `error`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment