seq

package module
v0.0.0-...-4adf8ad Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 1 Imported by: 0

README ΒΆ

seq πŸ”

PkgGoDev CodeFactor Build Status

Handy sequence iterator tools for Go 1.23+

Quick support for some common sequence iteration tools I needed in Go that are not in the standard library slices package as of 1.23.

[!NOTE] It seems almost certain this should already exist in an existing battle-tested module somewhere, but I didn't find one with a Google search, so it was faster to just drop this together myself than keep searching.

Operations supported:

  • Sliding window βœ…

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 ΒΆ

func Window[Slice ~[]E, E any](s Slice, n int) iter.Seq[Slice]

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL