An small variation for the chaining pattern, that uses functions, but ignores its result (if any):
value val1 = method1(initialValue);
method2(val1);
value val3 = method3(val1);
Using the tee
method will allow to insert the method into the chain:
chain(initialValue).tee(method2).to(method3);
This is pretty useful for side-effects only functions, like logging or void
operations:
chain(...).to(generateData).tee(logData).to(methodOnData)...
Like for chaining, teeing offer two top-level methods for starting a chain: tee
and tees
value ch = tee(initialValue, logMethod).to(method1);
Note there is no tee
variant accepting only the initial value.
If you understood chaining, teeing is just a piece of cake. Next chapter will introduce advanced spreading concepts.