Content deleted Content added
Deltaspace42 (talk | contribs) m Reverted 1 edit by DogTraining01 (talk) to last revision by 2605:A601:A916:C500:A11E:457A:E651:30B1 |
|||
(3 intermediate revisions by 3 users not shown) | |||
Line 26:
| publisher = [[Prentice Hall]]
| year = 2008
| isbn = 978-0-13-235088-
}}</ref>
Line 37:
Compare:
<syntaxhighlight lang="cpp">
a << b << c;
</syntaxhighlight>
equivalent to:
<syntaxhighlight lang="cpp">
a << b;
a << c;
Line 47:
Another example in [[JavaScript]] uses the built-in methods of Array:
<syntaxhighlight lang="javascript">
const interesting_products = products
.filter(x => x.count > 10)
.sort((a, b) => a.count - b.count)
.map(x => x.name)
</syntaxhighlight>
Note that in JavaScript <code>filter</code> and <code>map</code> return a new shallow copy of the preceding array but <code>sort</code> operates in place. To get a similar behavior, <code>toSorted</code> may be used. But in this particular case, <code>sort</code> operates on the new array returned from <code>filter</code> and therefore does not change the original array.
==See also==
Line 67 ⟶ 69:
* [http://www.infoq.com/articles/internal-dsls-java Creating DSLs in Java using method chaining concept]
* [https://programmingdive.com/method-chaining-in-php/ Method Chaining in PHP]
{{Design patterns}}
{{DEFAULTSORT:Method Chaining}}
|