Files
lo/docs/data/core-sliding.md
T
Samuel Berthe fa095e4b4f fix(doc): fix go playground demo URL (#832)
* fix(doc): fix go playground demo URL

* fix(doc): add more go playground demo URL
2026-03-06 00:09:59 +01:00

994 B

name, slug, sourceRef, category, subCategory, variantHelpers, playUrl, similarHelpers, position, signatures
name slug sourceRef category subCategory variantHelpers playUrl similarHelpers position signatures
Sliding sliding slice.go#L313 core slice
core#slice#sliding
https://go.dev/play/p/aIIU6gWxl2T
core#slice#window
core#slice#chunk
core#slice#partitionby
core#slice#flatten
it#sequence#sliding
150
func Sliding[T any, Slice ~[]T](collection Slice, size, step int) []Slice

Creates a slice of sliding windows of a given size with a given step. If step is equal to size, windows don't overlap (similar to Chunk). If step is less than size, windows overlap.

// Overlapping windows (step < size)
lo.Sliding([]int{1, 2, 3, 4, 5, 6}, 3, 1)
// [][]int{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}}

// Non-overlapping windows (step == size, like Chunk)
lo.Sliding([]int{1, 2, 3, 4, 5, 6}, 3, 3)
// [][]int{{1, 2, 3}, {4, 5, 6}}

// Step > size (skipping elements)
lo.Sliding([]int{1, 2, 3, 4, 5, 6, 7, 8}, 2, 3)
// [][]int{{1, 2}, {4, 5}, {7, 8}}