Method-cascading and pipe-forward operators proposal

A possible alternative sigil could be:

let hmap = HashMap::new()
    .< insert("key1", val1)
    .< insert("key2", val2);

This design is proposed because it has a visual directionality pointing to the left with <. The added spacing is intentional to make it more scrutable.


Meanwhile foo.(bar) as syntax for bar(foo) can simply be solved with foo.bar(). A new rule can be added to the dot syntax that if all other resolution mechanisms of x.f(y, ..) fails, then f(x, y, ..) will be tried. The new mechanism also extends to unary functions as x.f(). If f is not immediately in scope, then you can also write x.foo::bar::f(y)

This way, every free function can magically start using dot syntax. Of course, this will require some mental retraining to reconsider what a method is.

1 Like