3 ms·
> That assumes setupBase(), etc are either void-returning or return the this-instance (newModel). This is Incorrect, it doesn't assume anything. Dart's method
by mythz 11y ago
> That assumes setupBase(), etc are either void-returning or return the this-instance (newModel).
This is Incorrect, it doesn't assume anything. Dart's method cascades just returns the receiver, it doesn't matter what the method returns, it's value is ignored and receiver is returned instead.
http://news.dartlang.org/2012/02/method-cascades-in-dart-posted-by-gilad.html http://news.dartlang.org/2012/02/method-cascades-in-dart-pos...
Since the return value is ignored, it's only useful for methods with side-effects.
- spion 11y agoIt assumes you have a stateful, side-effectful API when you could instead have an API that returns new immutable objects of the same type
- spankalee 11y agoIn that case instead of cascades you just use regular invocation.
- Arnavion 11y ago>This is Incorrect, it doesn't assume anything. Dart's method cascades just returns the receiver, it doesn't matter what the method returns, it's value is ignored and receiver is returned instead. ... which would only be useful if the method was void-returning or returned the this-instance, i.e., it didn't return a new instance and left the LHS unmodified.
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]
- mythz 11y ago> which would only be useful if the method was void-returning or returned the this-instance Simply untrue, there are plenty of times methods have side-effects that return something other than void or itself, e.g: - Incrementing a value and returning the current value - Inserting or Updating rows and returning the number of rows affected - Setting an entry and returning whether there was an existing entry or not
- Arnavion 11y agoThe example I was responding to was about "setupBase" and "setupAdvanced"...