Documentation
ΒΆ
Overview ΒΆ
Package seq defines various functions useful for sequences and iteration over slices.
Index ΒΆ
Examples ΒΆ
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func Window ΒΆ
Window returns a iterator over consecutive sliding window sub-slices of size n over slice s. All sub-slices will have length n. All sub-slices are clipped to have no capacity beyond the length. If s is empty, the sequence is empty: there is no empty slice in the sequence. If len(s) < n, the sequence is empty: there is no slice of length n in the sequence. Window panics if n is less than 1.
Example ΒΆ
package main
import (
"fmt"
"github.com/mroth/seq"
)
func main() {
type Person struct {
Name string
Age int
}
type People []Person
people := People{
{"Gopher", 13},
{"Alice", 20},
{"Bob", 5},
{"Vera", 24},
{"Zac", 15},
}
// Sliding window over people in []Person 2 elements at a time.
for c := range seq.Window(people, 2) {
fmt.Println(c)
}
}
Output: [{Gopher 13} {Alice 20}] [{Alice 20} {Bob 5}] [{Bob 5} {Vera 24}] [{Vera 24} {Zac 15}]
Types ΒΆ
This section is empty.
Click to show internal directories.
Click to hide internal directories.