Home

Awesome

cascade · nimble license

Method & assignment cascades for Nim, inspired by Smalltalk & Dart.

cascade is a macro for Nim that implements method cascades, a feature originally from Smalltalk that's made its way into modern languages like Dart and Kotlin.

It allows you to avoid repeating an object's name for each method call or assignment. A common case is something like a button:

# before
var res = Button()
res.text = "ok"
res.width = 30
res.color = "#13a89e"
res.enable()

With cascade, you don't need to repeat yourself:

# after
let btn = cascade Button():
  text = "ok"
  width = 30
  color = "#13a89e"
  enable()

Also notice you can avoid declaring a var if you don't need to modify the target object after the fact — the object is mutable within the cascade block but becomes a let binding outside of that block.

installation & usage

Install using Nimble:

nimble install cascade

Then import and use:

import cascade

let x = cascade y:
  z = 10
  f()

supported constructs

Is something missing? Check the open issues first or open a new one. Pull requests are appreciated!

building

To build cascade from source you'll need to have Nim installed, and should also have Nimble, Nim's package manager.

  1. Clone the repo: git clone https://github.com/haltcase/cascade.git
  2. Move into the newly cloned directory: cd cascade
  3. Make your changes: cascade.nim, tests/tests.nim
  4. Run tests: nimble test

contributing

You can check the issues for anything unresolved, search for a problem you're encountering, or open a new one. Pull requests for improvements are also welcome.

license

MIT © Bo Lingen / haltcase