logo
Tags down

shadow

maps:put(Key,Value,Map) not working in erlang


By : Manel Palau Roig
Date : August 01 2020, 09:00 PM
wish of those help The maps:put/3 function returns a new map. You can see that it doesn't alter Map if you look at the variable again after the first maps:put/3 call:
code :
1> Map = #{"a" => 1}.
#{"a" => 1}.
2> maps:put("a", 42, Map).
#{"a" => 42}
3> Map.
#{"a" => 1}
4> Map1 = maps:put("a", 42, Map).
#{"a" => 42}
5> Map2 = maps:put("b", 1337, Map1).
#{"a" => 42,"b" => 1337}


Share : facebook icon twitter icon

Practical difference between Erlang maps:remove/2 and maps:without/2


By : David
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The first thing about maps is that, the implementation may change. As Fred Hébert wrote in learn you some Erlang maps Chapter: "The OTP team is respecting the old slogan: first make it work, then make it beautiful, and only if you need to, make it fast." So don't depend on this answer too heavily.
Currently the maps:without/2 function is implemented like this:
code :
without(Ks, M) when is_list(Ks), is_map(M) ->
    maps:from_list([{K,V}||{K,V} <- maps:to_list(M), not lists:member(K, Ks)]).

Pid as erlang maps key?


By : bia
Date : March 29 2020, 07:55 AM
it helps some times Support for arbitrary keys in map patterns is already available in "Erlang 18 (release candidate 2)".
code :
$ erl
Erlang/OTP 18 [RELEASE CANDIDATE 2] [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V7.0  (abort with ^G)
1> Pid = self().
<0.33.0>
2> #{Pid => 1}.
#{<0.33.0> => 1}

Erlang - merging maps


By : Rui Daniel
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , There's no builtin function in Erlang that does exactly this but it can be done with maps:fold/3 and maps:update_with/4 like this:
code :
1> A = #{"Ala" => 1,"kota" => 3}.
#{"Ala" => 1,"kota" => 3}
2> B = #{"kota" => 4}.
#{"kota" => 4}
3> maps:fold(fun(K, V, Map) -> maps:update_with(K, fun(X) -> X + V end, V, Map) end, A, B).
#{"Ala" => 1,"kota" => 7}

Erlang Maps : get keys that has the same value


By : reecebisel
Date : March 29 2020, 07:55 AM
Any of those help The function you're passing to maps:map/2 does not handle the H key nor any value not equal to VV. Try this instead:

Why is data sharing in Elixir / Erlang not working for the same tuple in two maps


By : Paul Ryan
Date : March 29 2020, 07:55 AM
I wish this help you modern era update: seems like it was fixed in ≈v1.7.
This is true for Elixir only; in Erlang the tuple is shared:
code :
1> Tuple = {1, 2},
1> Key1 = 1,
1> Key2 = 2,
1> Map1 = #{1 => Tuple, 2 => Tuple},
1> erts_debug:same(maps:get(Key1,Map1), maps:get(Key2,Map1)).
true

2> Key3 = 3,
2> Map2 = #{3 => Tuple},
2> erts_debug:same(maps:get(Key1,Map1), maps:get(Key3,Map2)).
true
Related Posts Related Posts :
shadow
Privacy Policy - Terms - Contact Us © voile276.org