Skip to content

Commit f1d0ff3

Browse files
SeanTAllenjemc
authored andcommitted
Clarify lambda interface to map.upsert (ponylang#1363)
The current example is unclear as to which value is the old value and which is the new value when setting up the lambda. By switching from addition to subtraction in the example, this becomes clear. This documentation could be improved further but this is a decent start towards resolving that possible confusion without having to look at the source code.
1 parent e519c41 commit f1d0ff3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/collections/map.pony

+5-5
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ class HashMap[K, V, H: HashFunction[K] val]
8787
using the provided function. If the provided key has not been added to
8888
the map yet, it sets its value to the provided value.
8989
90-
As a simple example, say we had a map with U64 values and we wanted to
90+
As a simple example, say we had a map with I64 values and we wanted to
9191
add 4 to the current value for key "test", which let's say is currently 2.
9292
We call
9393
94-
m.upsert("test", 4, lambda(x: U64, y: U64): U64 => x + y end)
94+
m.upsert("test", 4, lambda(x: I64, y: I64): I64 => x - y end)
9595
96-
This changes the value associated with "test" to 6.
96+
This changes the value associated with "test" to -2.
9797
9898
If we have not yet added the key "new-key" to the map and we call
9999
100-
m.upsert("new-key", 4, lambda(x: U64, y: U64): U64 => x + y end)
100+
m.upsert("new-key", 4, lambda(x: I64, y: I64): I64 => x - y end)
101101
102-
then "new-key" is added to the map with a value of 4.
102+
then "new-key" is added to the map with a value of -4.
103103
104104
Returns the value that we set the key to
105105
"""

0 commit comments

Comments
 (0)