[Proposal] Keyword.update_values/3

33 views
Skip to first unread message

casam...@gmail.com

unread,
Apr 13, 2018, 10:40:16 AM4/13/18
to elixir-lang-core
In a little sandbox project I wanted to update all the values associated to a key in a keyword and I haven't found a function in the Keyword module so I implemented it with the following specification:

@spec update_values(t, key, (value -> value)) :: t

If you think it'd be added to the module, I'll do a PR with the code.

José Valim

unread,
Apr 13, 2018, 12:25:35 PM4/13/18
to elixir-l...@googlegroups.com
The issue is that we don't have a update/3 function. So should we add Map.update/3, Keyword.update/3 as well as Keyword.update_values/3?

The issue though is that I don't fully recall which semantics we wanted for Keyword.update/3. Does it return a data structure? Or does it return :ok/:error? What happens if the value does not exist in the data-structure? Do we invoke the function with nil, mirroring get_and_update, or we don't invoke the anonymous function at all?

How does our choice mirror other functions such as Keyword.update/4 and Keyword.update!/3?



José Valim
Founder and 
Director of R&D

--
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 elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/62683691-c36c-4c2c-977e-55232e24c346%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages