@@ -99,16 +99,16 @@ defmodule Access do
99
99
@ type key :: any
100
100
@ type value :: any
101
101
102
- @ type get_fun ( data , get_value ) ::
102
+ @ type get_fun ( data , current_value ) ::
103
103
( :get , data , ( term -> term ) ->
104
- { get_value , new_data :: container } )
104
+ { current_value , new_data :: container } )
105
105
106
- @ type get_and_update_fun ( data , get_value ) ::
106
+ @ type get_and_update_fun ( data , current_value ) ::
107
107
( :get_and_update , data , ( term -> term ) ->
108
- { get_value , new_data :: container } | :pop )
108
+ { current_value , new_data :: container } | :pop )
109
109
110
- @ type access_fun ( data , get_value ) ::
111
- get_fun ( data , get_value ) | get_and_update_fun ( data , get_value )
110
+ @ type access_fun ( data , current_value ) ::
111
+ get_fun ( data , current_value ) | get_and_update_fun ( data , current_value )
112
112
113
113
@ doc """
114
114
Invoked in order to access the value stored under `key` in the given term `term`.
@@ -134,16 +134,16 @@ defmodule Access do
134
134
135
135
The implementation of this callback should invoke `fun` with the value under
136
136
`key` in the passed structure `data`, or with `nil` if `key` is not present in it.
137
- This function must return either `{get_value, update_value }` or `:pop`.
137
+ This function must return either `{current_value, new_value }` or `:pop`.
138
138
139
- If the passed function returns `{get_value, update_value }`,
140
- the return value of this callback should be `{get_value , new_data}`, where:
139
+ If the passed function returns `{current_value, new_value }`,
140
+ the return value of this callback should be `{current_value , new_data}`, where:
141
141
142
- * `get_value ` is the retrieved value (which can be operated on before being returned)
142
+ * `current_value ` is the retrieved value (which can be operated on before being returned)
143
143
144
- * `update_value ` is the new value to be stored under `key`
144
+ * `new_value ` is the new value to be stored under `key`
145
145
146
- * `new_data` is `data` after updating the value of `key` with `update_value `.
146
+ * `new_data` is `data` after updating the value of `key` with `new_value `.
147
147
148
148
If the passed function returns `:pop`, the return value of this callback
149
149
must be `{value, new_data}` where `value` is the value under `key`
@@ -152,8 +152,9 @@ defmodule Access do
152
152
See the implementations of `Map.get_and_update/3` or `Keyword.get_and_update/3`
153
153
for more examples.
154
154
"""
155
- @ callback get_and_update ( data , key , ( value -> { get_value , value } | :pop ) ) :: { get_value , data }
156
- when get_value: var , data: container | any_container
155
+ @ callback get_and_update ( data , key , ( value | nil -> { current_value , new_value :: value } | :pop ) ) ::
156
+ { current_value , new_data :: data }
157
+ when current_value: value , data: container | any_container
157
158
158
159
@ doc """
159
160
Invoked to "pop" the value under `key` out of the given data structure.
@@ -320,9 +321,9 @@ defmodule Access do
320
321
a struct that implements the `Access` behaviour).
321
322
322
323
The `fun` argument receives the value of `key` (or `nil` if `key` is not
323
- present in `container`) and must return a two-element tuple `{get_value, update_value }`:
324
- the "get" value `get_value ` (the retrieved value, which can be operated on before
325
- being returned) and the new value to be stored under `key` (`update_value `).
324
+ present in `container`) and must return a two-element tuple `{current_value, new_value }`:
325
+ the "get" value `current_value ` (the retrieved value, which can be operated on before
326
+ being returned) and the new value to be stored under `key` (`new_value `).
326
327
`fun` may also return `:pop`, which means the current value
327
328
should be removed from the container and returned.
328
329
@@ -337,8 +338,9 @@ defmodule Access do
337
338
{1, [a: 2]}
338
339
339
340
"""
340
- @ spec get_and_update ( data , key , ( value -> { get_value , value } | :pop ) ) :: { get_value , data }
341
- when get_value: var , data: container
341
+ @ spec get_and_update ( data , key , ( value | nil -> { current_value , new_value :: value } | :pop ) ) ::
342
+ { current_value , new_data :: data }
343
+ when current_value: var , data: container
342
344
def get_and_update ( container , key , fun )
343
345
344
346
def get_and_update ( % module { } = container , key , fun ) do
@@ -451,7 +453,7 @@ defmodule Access do
451
453
** (BadMapError) expected a map, got: []
452
454
453
455
"""
454
- @ spec key ( key , term ) :: access_fun ( data :: struct | map , get_value :: term )
456
+ @ spec key ( key , term ) :: access_fun ( data :: struct | map , current_value :: term )
455
457
def key ( key , default \\ nil ) do
456
458
fn
457
459
:get , data , next ->
@@ -495,7 +497,7 @@ defmodule Access do
495
497
** (RuntimeError) Access.key!/1 expected a map/struct, got: []
496
498
497
499
"""
498
- @ spec key! ( key ) :: access_fun ( data :: struct | map , get_value :: term )
500
+ @ spec key! ( key ) :: access_fun ( data :: struct | map , current_value :: term )
499
501
def key! ( key ) do
500
502
fn
501
503
:get , % { } = data , next ->
@@ -543,7 +545,7 @@ defmodule Access do
543
545
** (RuntimeError) Access.elem/1 expected a tuple, got: %{}
544
546
545
547
"""
546
- @ spec elem ( non_neg_integer ) :: access_fun ( data :: tuple , get_value :: term )
548
+ @ spec elem ( non_neg_integer ) :: access_fun ( data :: tuple , current_value :: term )
547
549
def elem ( index ) when is_integer ( index ) and index >= 0 do
548
550
pos = index + 1
549
551
@@ -597,7 +599,7 @@ defmodule Access do
597
599
** (RuntimeError) Access.all/0 expected a list, got: %{}
598
600
599
601
"""
600
- @ spec all ( ) :: access_fun ( data :: list , get_value :: list )
602
+ @ spec all ( ) :: access_fun ( data :: list , current_value :: list )
601
603
def all ( ) do
602
604
& all / 3
603
605
end
@@ -672,7 +674,7 @@ defmodule Access do
672
674
** (RuntimeError) Access.at/1 expected a list, got: %{}
673
675
674
676
"""
675
- @ spec at ( integer ) :: access_fun ( data :: list , get_value :: term )
677
+ @ spec at ( integer ) :: access_fun ( data :: list , current_value :: term )
676
678
def at ( index ) when is_integer ( index ) do
677
679
fn op , data , next -> at ( op , data , index , next ) end
678
680
end
@@ -727,7 +729,7 @@ defmodule Access do
727
729
728
730
"""
729
731
@ doc since: "1.11.0"
730
- @ spec at! ( integer ) :: access_fun ( data :: list , get_value :: term )
732
+ @ spec at! ( integer ) :: access_fun ( data :: list , current_value :: term )
731
733
def at! ( index ) when is_integer ( index ) do
732
734
fn op , data , next -> at! ( op , data , index , next ) end
733
735
end
@@ -794,7 +796,7 @@ defmodule Access do
794
796
795
797
"""
796
798
@ doc since: "1.6.0"
797
- @ spec filter ( ( term -> boolean ) ) :: access_fun ( data :: list , get_value :: list )
799
+ @ spec filter ( ( term -> boolean ) ) :: access_fun ( data :: list , current_value :: list )
798
800
def filter ( func ) when is_function ( func ) do
799
801
fn op , data , next -> filter ( op , data , func , next ) end
800
802
end
0 commit comments