Skip to content

Commit 23191c2

Browse files
Switch object rename around to be more intuitive.
1 parent 9babd49 commit 23191c2

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let tim = Person(name: "Tim", job: "Fluffer")
2828
2929
tim.lunpack(name, job) # creates name, job with let and assign respective member values to them
3030
31-
tim.lunpack(job, name = otherName) # you can also unpack into custom names using '='
31+
tim.lunpack(job, otherName = name) # you can also unpack into custom names using '='
3232
3333
# will not invoke proc chain multiple times
3434
tim.someProcWithSideEffects(arg).lunpack(name, job)
@@ -40,6 +40,8 @@ tim.someProcWithSideEffects(arg).lunpack(name, job)
4040
# job = someUniqueSym1212498.job
4141
```
4242

43+
See `tests/test1.nim` for more usages.
44+
4345
## TODO
4446

4547
- Docs

src/unpack.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ proc unpackInternal(srcNode, dests: NimNode; sec,
2727
case dest.kind:
2828
of nnkExprEqExpr:
2929
var newNode = stNode.copyNimTree
30-
newNode[0] = dest[1]
31-
newNode[^1] = nnkDotExpr.newTree(src, dest[0])
30+
newNode[0] = dest[0]
31+
newNode[^1] = nnkDotExpr.newTree(src, dest[1])
3232
section.add(newNode)
3333
else:
3434
var newNode = stNode.copyNimTree

tests/test1.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ suite "Object meber unpacking":
8888
check secreteCounter == 1
8989

9090
test "should be able to rename object member with '=' sign":
91-
tim.lunpack(name = otherName)
91+
tim.lunpack(otherName = name)
9292

9393
check otherName == timName
9494

95-
tim.lunpack(job, name = yetAnotherName) # and is order-agnostic.
95+
tim.lunpack(job, yetAnotherName = name) # and is order-agnostic.
9696

9797
check yetAnotherName == timName
9898
check job == fluffer

0 commit comments

Comments
 (0)