Skip to content

williamthome/maps_in

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

maps_in

An Erlang library to handle nested maps.

Table of contents

General info

Erlang does not provide functions to handle nested maps, so this lib has this purpose and always uses a list of keys to manipulate maps.

Usage

filter/3

1> Map = #{erlang => #{example => #{a => 2, b => 3, c => 4, "a" => 1, "b" => 2, "c" => 4}}}.
#{erlang =>
      #{example =>
            #{a => 2,b => 3,c => 4,"a" => 1,"b" => 2,"c" => 4}}}
2> Pred = fun(K, V) -> is_atom(K) andalso (V rem 2) =:= 0 end.
#Fun<erl_eval.41.3316493>
3> maps_in:filter([erlang, example], Pred, Map).
#{erlang => #{example => #{a => 2,c => 4}}}

filtermap/3 (OTP 24.0)

<!-- TODO -->

find/3

<!-- TODO -->

fold/4

<!-- TODO -->

foreach/3

<!-- TODO -->

get/2

1> Map = #{my => #{nested => map}}.
#{my => #{nested => map}}
2> maps_in:get([my, nested], Map).
map

get/3

1> Map = #{my => #{nested => map}}.
#{my => #{nested => map}}
2> maps_in:get([my, unknown_key], Map, default).
default

keys/2

<!-- TODO -->

is_key/3

<!-- TODO -->

iterator/2 (OTP 21)

<!-- TODO -->

map/3

<!-- TODO -->

merge/3

<!-- TODO -->

merge_with/4 (OTP 24.0)

<!-- TODO -->

put/3

1> Map = #{my => #{more => #{deep => #{}}}}.
#{my => #{more => #{deep => #{}}}}
2> maps_in:put([my, more, deep], #{nested => map}, Map).
#{my => #{more => #{deep => #{nested => map}}}}

remove/3

<!-- TODO -->

size/2

<!-- TODO -->

take/3

<!-- TODO -->

to_list/2

<!-- TODO -->

update/3

1> Map = #{my => #{more => #{deep => #{}}}}.
#{my => #{more => #{deep => #{}}}}
2> maps_in:update([my, unknown_key], error, Map).
** exception error: bad key: unknown_key
3> maps_in:update([my, more, deep], #{nested => map}, Map).
#{my => #{more => #{deep => #{nested => map}}}}

update_with/3

1> Map = #{someone => #{age => 17}}.
#{someone => #{age => 17}}
2> maps_in:update_with([someone, age], fun(Age) -> Age + 1 end, Map).
#{someone => #{age => 18}}

update_with/4

<!-- TODO -->

values/2

<!-- TODO -->

with/3

<!-- TODO -->

without/3

<!-- TODO -->

Build

$ rebar3 compile

Test

$ rebar3 eunit