Hi Kensei,

Here is a bit of context :)

There was a Map.replace/3 (with a different behavior) that was deprecated
in favor of Map.fetch/2 + Map.put/3. Here is a link to the code:
https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/map.ex#L304

Here is the rationale behind the deprecation:
https://github.com/elixir-lang/elixir/commit/a81a17b3b09b267883383bdb8a00fe00ab2724a8

Hope this helps :)

On Sat, 22 Feb 2020 at 10:49, Kensei N <[email protected]> wrote:

> Hi !
>
> I propose Map.replace/3.
>
> Map.replace!/3 already exists.
> However, it is difficult to use pattern match with Map.replace!/3  because
> it raise error when key is not present in map.
>
> So, I think it is a good idea make Map.replace/3  and it return
> :error
> when key is not present in map, and it return
> {:ok, %{hoge: "hoge"}}
> when key is present and work correctly.
>
> Example:
>  iex> ex_map = %{a: 1, b: 2}
> %{a: 1, b: 2}
>
>  iex>Map.replace(ex_map, :a, 3)
> {:ok, %{a: 3, b: 2}}
>
>  iex>Map.replace(ex_map, :hoge, 3)
> :error
>
> --
> 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/812de3be-6088-41ff-b9fa-6387d86ab1df%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/812de3be-6088-41ff-b9fa-6387d86ab1df%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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%2Bm6x%3DS3GgohB_v7R3y0FOy9%2B6LvUWk4XqJxs5jDPWAYfy%3DggQ%40mail.gmail.com.

Reply via email to