window

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2025 License: MIT Imports: 0 Imported by: 0

README

go-window

A tiny and generic Go package for producing sliding windows over slices, inspired by Rust’s .windows() method.

✨ Features

  • Minimal API: just one function — Slide
  • Generic: works with any slice type ([]int, []string, etc.)
  • Lazy and efficient: uses a goroutine and channel to stream windows

📦 Installation

go get github.com/johan-scriptdrift/go-window

🚀 Usage

package main

import (
	"fmt"
	"github.com/johan-scriptdrift/go-window"
)

func main() {
	nums := []int{1, 2, 3, 4, 5}

	for win := range window.Slide(nums, 3) {
		fmt.Println(win)
	}
}
Output
[1 2 3]
[2 3 4]
[3 4 5]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Slide

func Slide[T any](data []T, size int) <-chan []T

Types

This section is empty.

Jump to

Keyboard shortcuts

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