This module implements the with macro for easy function chaining. See https://github.com/nim-lang/RFCs/issues/193 and https://github.com/nim-lang/RFCs/issues/192 for details leading to this particular design.
Since: version 1.2.
macro with(arg: typed; calls: varargs[untyped]): untyped
calls to use arg as the first argument.arg multiple times!Example:
var x = "yay"
with x:
add "abc"
add "efg"
doAssert x == "yayabcefg"
var a = 44
with a:
+= 4
-= 5
doAssert a == 43
# Nesting works for object types too!
var foo = (bar: 1, qux: (baz: 2))
with foo:
bar = 2
with qux:
baz = 3
doAssert foo.bar == 2
doAssert foo.qux.baz == 3 Source Edit
© 2006–2024 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/with.html