For me the requirement does sound much more like `Map.update/4`…

https://hexdocs.pm/elixir/Map.html#update/4

```
Map.update(map, key, 1, &(&1 + 1))
```

But if this is really correct behaviour, we can't know, since the OP only
said what happens when `key` is not in the map, but not what he would have
expected instead…

Martin Svalin <[email protected]> schrieb am Di., 3. Okt. 2017 um
21:39 Uhr:

> I'm unclear what you want the proposed function to return when the key
> isn't present. The map, untouched? I think that behaviour would be a
> surprise to some. I like the explicitness of `Map.get_and_update/3`.
>
> `Map.get_and_update(map, key, fn
>   nil -> map
>   n -> n + 1
> end)`
>
> --
> - Martin
>
>
> tis 3 okt. 2017 kl 20:40 skrev Ary Borenszweig <[email protected]>:
>
>> I saw it, but it's different from what I want. There are two versions:
>> - get_and_update(map, key, fun): fun is called with the current value
>> under key in map (*or nil if key is not present in map*) -> I don't want
>> that nil, it will break my code
>> - get_and_update!(map, key, fun): raises if there's no key
>>
>> I want something like this:
>>
>> ~~~
>> Map.put_lazy(map, key, fun value -> value + 1 end)
>> ~~~
>>
>> Here, the function is only invoked if key is present in map.
>> `get_and_update` would invoke that function with `nil`.
>>
>>
>>
>> On Tuesday, October 3, 2017 at 3:00:43 PM UTC-3, Tallak Tveide wrote:
>>>
>>> https://hexdocs.pm/elixir/Map.html#get_and_update!/3
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/elixir-lang-core/1164ddd8-de7d-4e0d-b140-63db6b6b6646%40googlegroups.com
>> <https://groups.google.com/d/msgid/elixir-lang-core/1164ddd8-de7d-4e0d-b140-63db6b6b6646%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/CAAHw6C%2BLeJdT2d%3DgRUaQNMehrKhuY8ARb1Q-Opxoti3UxpMw4g%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAAHw6C%2BLeJdT2d%3DgRUaQNMehrKhuY8ARb1Q-Opxoti3UxpMw4g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CA%2BbCVsudD%2BQs%3DxHKmKruJQ%3DbC4h5p8H_CTb-Ng7nagNeJ33QuQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to