https://github.com/metagn/spread
macro for spreading blocks into call parameters/collections
https://github.com/metagn/spread
block macro nim sugar syntax
Last synced: 7 months ago
JSON representation
macro for spreading blocks into call parameters/collections
- Host: GitHub
- URL: https://github.com/metagn/spread
- Owner: metagn
- Created: 2022-02-04T14:03:15.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-14T10:06:32.000Z (about 2 years ago)
- Last Synced: 2024-10-14T15:03:10.903Z (12 months ago)
- Topics: block, macro, nim, sugar, syntax
- Language: Nim
- Homepage: https://metagn.github.io/spread/docs/spread.html
- Size: 27.3 KB
- Stars: 13
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# spread
`spread` macro for spreading blocks into call parameters/collections
```nim
import spreadproc foo(a, b, c: int) =
echo "a: ", a
echo "b: ", b
echo "c: ", c# regular call:
foo.spread:
1
c = 3
b = 2# operator version:
...foo:
1
c = 3
b = 2# operator allows inline version with `do`:
let a = 1 + (...min do:
2
3)assert a == 3
# method call syntax:
spread 1.foo:
c = 3
b = 2spread 1.foo(2):
c = 3# arrays:
const arr = [].spread:
1
2
3assert arr == [1, 2, 3]
# table constructors:
let tab = {:}.spread:
"a" = 1 # constructors convert = in a statement to :
_("b": 2, "c": 3) # all arguments of _ are spread directlyassert tab == {"a": 1, "b": 2, "c": 3}
# object or tuple constructors need a single `_: _``:
type Foo = object
a, b, c: intlet obj = spread Foo(_: _):
a = 1
c = 3
b = 2assert obj == Foo(a: 1, b: 2, c: 3)
```