This has been available if you use https://typelevel.org/cats/ on Foldable
s for a while, for example:
import cats.syntax.foldable._
val list = List(1, 2, 3, 4, 5)
println(list.sliding2)
// List((1,2), (2,3), (3,4), (4,5))
sliding3
, sliding4
, etc are also defined, see the scaladoc for more information.