mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-04 22:48:38 +00:00
make two-argument withValues untyped (#26052)
The twp-argument form of `withValue` are expression when the branches themselves are expressions.
This commit is contained in:
@@ -33,6 +33,22 @@ s2[p2] = 45_000
|
||||
s3[p1] = 30_000
|
||||
s3[p2] = 45_000
|
||||
|
||||
block: # two-argument form of withValue forms expression
|
||||
block: # Present
|
||||
let sal = salaries.withValue(p1, sal):
|
||||
sal[]
|
||||
do:
|
||||
0
|
||||
doAssert sal == 30_000
|
||||
block: # Missing
|
||||
let sal = salaries.withValue(Person(), sal):
|
||||
sal[]
|
||||
do:
|
||||
0
|
||||
doAssert sal == 0
|
||||
block: # Short form
|
||||
doAssert salaries.withValue(p1, sal, sal[], 0) == 30_000
|
||||
|
||||
block: # Ordered table should preserve order after deletion
|
||||
var
|
||||
s4 = initOrderedTable[int, int]()
|
||||
|
||||
Reference in New Issue
Block a user