"Please note that no intermediate collections are produced."
This is an improvement because, for example, there is less pressure on the garbage collector.
When combining operations such as map
, filter
, these functions iterate over the collection and return a new collection, which is then passed to the next function. This does not apply to gearboxes.
Thus, they can be used because these functions (that is, they are composed the same way) and can be applied to the same collections. But with added performance.
Below is a rough and completely unscientific sketch of the display / display / filter operation with and without gears:
Without gears
Initial collection => map => intermediate collection => map => intermediate collection => filter => final collection
Without reducers (i.e. clojure.core map / filter functions) intermediate collections are produced lazily. That is, new elements are created only when it is required at the next stage of processing, either one element or one fragment at a time.
Note. A block is a block of 32 elements (although this should be considered as an implementation detail). This is for efficiency reasons, to avoid "jumping" from one calculation to another.
See the map
function for a return value , for example: it returns lazy-seq
(except for the case of converters ).
With gearboxes
Initial Collection => Card / Card / Filter Reducer => Final Collection
If you need to quickly process the entire collection, then laziness interferes with performance. Removing the intermediate layers of the lazy sections provides a performance boost. Gearboxes do this and process the collection with impatience, hence faster. You can also use the same functions to facilitate switching.
Please also read the comments below, especially from @ MichaΕ Marczyk