cache
cache eagerly evaluates front of range on each construction or call to popFront, to store the result in a _cache. The result is then directly returned when front is called, rather than re-evaluated.
This can be a useful function to place in a chain, after functions that have expensive evaluation, as a lazy alternative to array. In particular, it can be placed after a call to map, or before a call
filter or tee
cache may provide
iteration if needed, but since this comes at an increased cost, it must be explicitly requested via the call to cacheBidirectional. Furthermore, a bidirectional _cache will evaluate the "center" element twice, when there is only one element left in the range.
cache does not provide random access primitives, as cache would be unable to _cache the random accesses. If Range provides slicing primitives, then cache will provide the same slicing primitives, but hasSlicing!Cache will not yield true (as the hasSlicing trait also checks for random access).
Parameters
range | an input range |