Can you copy Clojure (partition) or Scala slide () functions using Guava?

I have a list that I want to split in the same way as the (partition sz step col) Clojure method or IterableLike.sliding(size: Int, step: Int) the Scala function. In particular, given the list, for example:

 (1, 2, 3) 

I want to be able to iterate over lists such as:

 (1, 2), (2, 3) 

In Clojure, this will be done with

 (partition 2 1 (1, 2, 3)) 

and Scala it will be:

 val it = Vector(1, 2, 3).sliding(2) 

However, I do not have such luxury, and I hope that I will not have to give up my own. Guava has a separation method that approaches but does not offer overlap. Googling was also barren. Is there such a method, or will I have to roll on my own?

+7
source share
2 answers

Guava has nothing of the kind right now, but if you write issue , we can discuss adding it.

For myself, I would use ArrayDeque to store the current window, but that would not make sense for the library method.

+1
source

Guava does not have this, but its AbstractIterator will most likely simplify folding.

Perhaps a function request already exists for it; if not, please feel free to.

+2
source

All Articles