iterkit

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2022 License: Apache-2.0 Imports: 0 Imported by: 1

README ¶

iterkit

Dead simple generic iterator interface.

The package itertools is meant to implement iterator functions similar to what python has to offer.

📦 Installation

$ go get -u github.com/0x5a17ed/iterkit@latest

🤔 Usage

package main

import (
	"github.com/0x5a17ed/iterkit"
)

func main() {
	it := &iterkit.SliceIterator[int]{Data: []int{1, 2, 3}}
	for it.Next() {
		fmt.Println(it.Value)()
	}
}

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Iterator ¶

type Iterator[T any] interface {
	// Next advances the iterator to the first/next item,
	// returning true if successful meaning there is an item
	// available to be fetched with Value and false otherwise.
	Next() bool

	// Value returns the current item if there is any and panics
	// otherwise.
	//
	// Note: Use Next to ensure there is an item.
	Value() T
}

func From ¶ added in v0.2.1

func From[T any](s []T) Iterator[T]

From returns an iterator yielding items from the given slice.

type SliceIterator ¶

type SliceIterator[T any] struct {
	Data []T
	// contains filtered or unexported fields
}

SliceIterator provides an iterator for slices that conforms to the Iterator protocol.

func (*SliceIterator[T]) Next ¶

func (it *SliceIterator[T]) Next() bool

func (*SliceIterator[T]) Value ¶

func (it *SliceIterator[T]) Value() T

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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