Skip to content

Instantly share code, notes, and snippets.

@takkkun
Created May 22, 2013 21:56
Show Gist options
  • Select an option

  • Save takkkun/5631277 to your computer and use it in GitHub Desktop.

Select an option

Save takkkun/5631277 to your computer and use it in GitHub Desktop.
-module(folder).
assign(Dict, [LastPart], Value) ->
Dict:store(LastPart, Value);
assign(Dict, [Part|Tail], Value) ->
NewDict = case Dict:exists(Part) of
ok -> assign(Dict:fetch(Part), Tail, Value);
error -> assign(dict:new(), Tail, Value)
end,
Dict:store(Part, NewDict).
sample() ->
Dict = dict:new(),
assign(Dict, ["a", "b", "c"], 1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment