Updating a map

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Updating a map

Donald Steven
The documentation for maps:update states:  update(Key, Value, Map1) ->
Map2, but since update has an arity of 3, this doesn't work: 
update(Key1, Value1, Key2, Value2, Map1) -> Map2.  Is there an
other-than one-by-one-sequential-update to update more than one
key-value in one shot?

Thanks.


Don


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Updating a map

Oliver Korpilla
Hello, Donald.

You could use lists:foldr/3 to insert a list of key values into a map.

You would use the map itself as a the accumulator.

Best regards,
Oliver 

Gesendet: Mittwoch, 30. Januar 2019 um 13:27 Uhr
Von: "Donald Steven" <[hidden email]>
An: "Erlang Questions" <[hidden email]>
Betreff: [erlang-questions] Updating a map
The documentation for maps:update states:  update(Key, Value, Map1) ->
Map2, but since update has an arity of 3, this doesn't work: 
update(Key1, Value1, Key2, Value2, Map1) -> Map2.  Is there an
other-than one-by-one-sequential-update to update more than one
key-value in one shot?

Thanks.


Don


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Updating a map

Oliver Korpilla

PS - maps:from_list/1 might be also what you are looking for. 

Gesendet: Mittwoch, 30. Januar 2019 um 13:47 Uhr
Von: "Oliver Korpilla" <[hidden email]>
An: "Donald Steven" <[hidden email]>
Cc: "Erlang Questions" <[hidden email]>
Betreff: Re: [erlang-questions] Updating a map
Hello, Donald.

You could use lists:foldr/3 to insert a list of key values into a map.

You would use the map itself as a the accumulator.

Best regards,
Oliver 

Gesendet: Mittwoch, 30. Januar 2019 um 13:27 Uhr
Von: "Donald Steven" <[hidden email]>
An: "Erlang Questions" <[hidden email]>
Betreff: [erlang-questions] Updating a map
The documentation for maps:update states:  update(Key, Value, Map1) ->
Map2, but since update has an arity of 3, this doesn't work: 
update(Key1, Value1, Key2, Value2, Map1) -> Map2.  Is there an
other-than one-by-one-sequential-update to update more than one
key-value in one shot?

Thanks.


Don


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions[http://erlang.org/mailman/listinfo/erlang-questions]
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Updating a map

Guilherme Andrade
In reply to this post by Donald Steven
Hello Donald,

Ever since Erlang/OTP 18 (or 19? I don't recall which), you can use the shorter map update syntax like this:

Map = #{foo => bar, hello => world},
UpdatedMap = Map#{foo := barbar, hello := moon}.



On Wed, 30 Jan 2019 at 12:27, Donald Steven <[hidden email]> wrote:
The documentation for maps:update states:  update(Key, Value, Map1) ->
Map2, but since update has an arity of 3, this doesn't work: 
update(Key1, Value1, Key2, Value2, Map1) -> Map2.  Is there an
other-than one-by-one-sequential-update to update more than one
key-value in one shot?

Thanks.


Don


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


--
Guilherme

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Updating a map

Fred Youhanaie-2
In reply to this post by Donald Steven
You can use the maps:fold/3, e.g.

M = #{one => 1, two => 2, three => 3}.

maps:fold(fun maps:update/3, M, #{one=>11, two=>22}).
#{one => 11,three => 3,two => 22}

Cheers,
Fred

On 30/01/2019 12:27, Donald Steven wrote:

> The documentation for maps:update states:  update(Key, Value, Map1) -> Map2, but since update has an arity of 3, this doesn't work: update(Key1, Value1, Key2, Value2, Map1) -> Map2.  Is there an
> other-than one-by-one-sequential-update to update more than one key-value in one shot?
>
> Thanks.
>
>
> Don
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Updating a map

Donald Steven
In reply to this post by Guilherme Andrade
Wow!  Thanks.

On 1/30/2019 8.13 AM, Guilherme Andrade wrote:
Hello Donald,

Ever since Erlang/OTP 18 (or 19? I don't recall which), you can use the shorter map update syntax like this:

Map = #{foo => bar, hello => world},
UpdatedMap = Map#{foo := barbar, hello := moon}.



On Wed, 30 Jan 2019 at 12:27, Donald Steven <[hidden email]> wrote:
The documentation for <a class="moz-txt-link-freetext" href="maps:update">maps:update states:  update(Key, Value, Map1) ->
Map2, but since update has an arity of 3, this doesn't work: 
update(Key1, Value1, Key2, Value2, Map1) -> Map2.  Is there an
other-than one-by-one-sequential-update to update more than one
key-value in one shot?

Thanks.


Don


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


--
Guilherme


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions