spread

macro for spreading blocks into call parameters/collections

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.2.1
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:26

Authors

  • metagn

Installation

nimble install spread
choosenim install spread
git clone https://github.com/metagn/spread

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
spread - - - - - - -

Dependencies

Package Version Optional
nim >= 1.0.0 No

Source

Repository https://github.com/metagn/spread
Homepage https://github.com/metagn/spread
Registry Source nimble_official

README

spread

spread macro for spreading blocks into call parameters/collections

import spread

proc 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 = 2

spread 1.foo(2):
  c = 3

# arrays:
const arr = [].spread:
  1
  2
  3

assert 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 directly

assert tab == {"a": 1, "b": 2, "c": 3}

# object or tuple constructors need a single `_: _``:
type Foo = object
  a, b, c: int

let obj = spread Foo(_: _):
  a = 1
  c = 3
  b = 2

assert obj == Foo(a: 1, b: 2, c: 3)