Forgive me if this is trivial, I’m just starting out.
I’m looking at the .sliding()
method that appears to be implemented for Iterators.
The comments describe the functionality of this method as follows:
Returns an iterator which presents a “sliding window” view of
this iterator. The first argument is the window size, and
the second argumentstep
is how far to advance the window
on each iteration. Thestep
defaults to1
.
The returned
GroupedIterator
can be configured to either
pad a partial result to sizesize
or suppress the partial
result entirely.
And gives an example:
Returns List(ArraySeq(1, 2, 3), ArraySeq(2, 3, 4), ArraySeq(3, 4, 5))
(1 to 5).iterator.sliding(3).toList
The method is pretty straight forward. But I’d like to understand where the functionality is actually implemented. Where is the code that is actually going over the elements in the iterator and coming up with a List[ArraySeq[Int]]
?
Within the definition of this class GroupedIterator
I could not find code that achieves the result in the example. I thought it must be overriding the toList
method somehow but I don’t know if that makes much sense. I’d appreciate some help. I’ve looked all around the GitHub repo and I think I just don’t know what I’m looking for and where to find it.
Also, I’m using Scala 2.12.
Link to Iterator.scala