-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Make spec clearer for update functions in Map #10223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make spec clearer for update functions in Map #10223
Conversation
d5417f3
to
e571ddb
Compare
* It removes the concept of the "get" value (which should have been "gotten" IMO). * Renames "initial" argument to "default" * Makes use of the concept of "current value" which was already present in some functions, and uses this in the examples and the specs consistently
%{a: 2} | ||
iex> Map.update(%{a: 1}, :b, 11, &(&1 * 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely prefer existing_value
, as it makes it clear it won't be called if there is no value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True! they are really good names for stressing the distinction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
corrected
@@ -845,7 +845,9 @@ defmodule Map do | |||
{nil, %{a: 1}} | |||
|
|||
""" | |||
@spec get_and_update(map, key, (value -> {get, value} | :pop)) :: {get, map} when get: term | |||
@spec get_and_update(map, key, (value -> {current_value, new_value :: value} | :pop)) :: | |||
{current_value, map} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for current_value
here, as it is also called if the value is nil. I also like new_value
!
💚 💙 💜 💛 ❤️ |
Inspired by c1a538e (elixir-lang#10223) * Fixes the spec of Keyword.get_and_update!/3 that was missing the :pop return value for the update function * It removes the concept of the "get" value and replaced it consistently with "current value" * Renames "initial" argument to "default" * Uses "existing value" when applicable
Inspired by c1a538e (#10223) * Fixes the spec of Keyword.get_and_update!/3 that was missing the :pop return value for the update function * It removes the concept of the "get" value and replaced it consistently with "current value" * Renames "initial" argument to "default" * Uses "existing value" when applicable
To be consistent with recently introduced changes: elixir-lang#10228, elixir-lang#10223
In the same fashion of PRs elixir-lang#10228 and elixir-lang#10223 Replaces: - `get_values` with `current_value` - `update_value` with `new_value` - `data` with `new_data` when suitable Adds nil as an argument term in the function spec.
Uh oh!
There was an error while loading. Please reload this page.