Skip to content

Commit 556bd25

Browse files
Improve wording in Map module (#10318)
1 parent 4b9a2bb commit 556bd25

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

lib/elixir/lib/map.ex

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ defmodule Map do
244244
@doc """
245245
Fetches the value for a specific `key` in the given `map`.
246246
247-
If `map` contains the given `key` with value `value`, then `{:ok, value}` is
248-
returned. If `map` doesn't contain `key`, `:error` is returned.
247+
If `map` contains the given `key` then its value is returned in the shape of `{:ok, value}`.
248+
If `map` doesn't contain `key`, `:error` is returned.
249249
250250
Inlined by the compiler.
251251
@@ -264,7 +264,7 @@ defmodule Map do
264264
Fetches the value for a specific `key` in the given `map`, erroring out if
265265
`map` doesn't contain `key`.
266266
267-
If `map` contains the given `key`, the corresponding value is returned. If
267+
If `map` contains `key`, the corresponding value is returned. If
268268
`map` doesn't contain `key`, a `KeyError` exception is raised.
269269
270270
Inlined by the compiler.
@@ -439,7 +439,7 @@ defmodule Map do
439439
@doc """
440440
Gets the value for a specific `key` in `map`.
441441
442-
If `key` is present in `map` with value `value`, then `value` is
442+
If `key` is present in `map` then its value `value` is
443443
returned. Otherwise, `default` is returned.
444444
445445
If `default` is not provided, `nil` is used.
@@ -473,7 +473,7 @@ defmodule Map do
473473
@doc """
474474
Gets the value for a specific `key` in `map`.
475475
476-
If `key` is present in `map` with value `value`, then `value` is
476+
If `key` is present in `map` then its value `value` is
477477
returned. Otherwise, `fun` is evaluated and its result is returned.
478478
479479
This is useful if the default value is very expensive to calculate or
@@ -601,8 +601,8 @@ defmodule Map do
601601
@doc """
602602
Updates the `key` in `map` with the given function.
603603
604-
If `key` is present in `map` with value `value`, `fun` is invoked with
605-
argument `value` and its result is used as the new value of `key`. If `key` is
604+
If `key` is present in `map` then the existing value is passed to `fun` and its result is
605+
used as the updated value of `key`. If `key` is
606606
not present in `map`, `default` is inserted as the value of `key`. The default
607607
value will not be passed through the update function.
608608
@@ -630,10 +630,10 @@ defmodule Map do
630630
end
631631

632632
@doc """
633-
Returns and removes the value associated with `key` in `map`.
633+
Removes the value associated with `key` in `map` and returns the value and the updated map.
634634
635-
If `key` is present in `map` with value `value`, `{value, new_map}` is
636-
returned where `new_map` is the result of removing `key` from `map`. If `key`
635+
If `key` is present in `map`, it returns `{value, new_map}` where `value` is the value of
636+
the key and `new_map` is the result of removing `key` from `map`. If `key`
637637
is not present in `map`, `{default, map}` is returned.
638638
639639
## Examples
@@ -646,7 +646,7 @@ defmodule Map do
646646
{3, %{a: 1}}
647647
648648
"""
649-
@spec pop(map, key, value) :: {value, map}
649+
@spec pop(map, key, value) :: {value, new_map :: map}
650650
def pop(map, key, default \\ nil) do
651651
case :maps.take(key, map) do
652652
{_, _} = tuple -> tuple
@@ -682,8 +682,8 @@ defmodule Map do
682682
@doc """
683683
Lazily returns and removes the value associated with `key` in `map`.
684684
685-
If `key` is present in `map` with value `value`, `{value, new_map}` is
686-
returned where `new_map` is the result of removing `key` from `map`. If `key`
685+
If `key` is present in `map`, it returns `{value, new_map}` where `value` is the value of
686+
the key and `new_map` is the result of removing `key` from `map`. If `key`
687687
is not present in `map`, `{fun_result, map}` is returned, where `fun_result`
688688
is the result of applying `fun`.
689689
@@ -799,8 +799,8 @@ defmodule Map do
799799
@doc """
800800
Updates `key` with the given function.
801801
802-
If `key` is present in `map` with value `value`, `fun` is invoked with
803-
argument `value` and its result is used as the new value of `key`. If `key` is
802+
If `key` is present in `map` then the existing value is passed to `fun` and its result is
803+
used as the updated value of `key`. If `key` is
804804
not present in `map`, a `KeyError` exception is raised.
805805
806806
## Examples
@@ -812,7 +812,7 @@ defmodule Map do
812812
** (KeyError) key :b not found in: %{a: 1}
813813
814814
"""
815-
@spec update!(map, key, (current_value :: value -> new_value :: value)) :: map
815+
@spec update!(map, key, (existing_value :: value -> updated_value :: value)) :: map
816816
def update!(map, key, fun) when is_function(fun, 1) do
817817
value = fetch!(map, key)
818818
put(map, key, fun.(value))

0 commit comments

Comments
 (0)