Missing python-like chaining in D
Bastiaan Veelo
Bastiaan at Veelo.net
Mon Feb 21 10:57:19 UTC 2022
On Monday, 21 February 2022 at 10:27:08 UTC, forkit wrote:
> cat.meow().eat().sleep().play();
>
> which, the more verbose way, is:
>
> cat.meow();
> cat.eat();
> cat.sleep();
> cat.play();
Not at all, not in the general case!
```d
cat.meow().eat().sleep().play();
```
is equivalent to
```d
play(sleep(eat(meow(cat))));
```
In other words, the result of `eat` is fed into `sleep`, the
result of `sleep` is fed into `play`, etc. Your statement is only
true if all those functions return a reference to `cat`.
-- Bastiaan.
More information about the Digitalmars-d
mailing list