itkit

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: Apache-2.0 Imports: 0 Imported by: 6

README

itkit

Go Reference Go Report Card codecov

Short, dead simple and concise generic iterator interface. With a few extras similar to what python has to offer.

📦 Installation

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

🤔 Usage

package main

import (
	"fmt"

	"github.com/0x5a17ed/itkit/iters/sliceit"
	"github.com/0x5a17ed/itkit/itlib"
)

func main() {
	s := []int{1, 2, 3}

	// iterating using the for keyword.
	for it := sliceit.In(s); it.Next(); {
		fmt.Println(it.Value())
	}

	// iterating using a slightly more functional approach.
	itlib.Apply(sliceit.In(s), func(v int) {
		fmt.Println(v)
	})
}

🥇 Acknowledgments

The iterator interface is desgined after the stateful iterators pattern explained in the brilliant blog post from https://ewencp.org/blog/golang-iterators/index.html. Most functions to manipulate iterators draw inspiration from different sources such as Python and github.com/samber/lo.

⚖️ License

itkit is licensed under the Apache License, Version 2.0.

FOSSA Status

☝️ Is it any good?

yes.

Documentation

Overview

Package itkit provides short, dead simple and concise type-safe generic iterator interfaces for Go. With a few extras similar to what Python has to offer.

Piece of advice

Abandon Hope All Ye Who Enter Here.

This Go Module is probably a collection of anti-patterns. It started as an experiment about what can be done with the new Go generics functionality that was introduced into go in the 1.18 version, although I personally like how this module turned out to be.

My recommendation for now would be to use it sparingly and use normal Go iteration with the for keyword where possible and only use itkit iterators where it makes sense to reduce code and complexity without sacrificing readability.

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 may
	// panic otherwise.
	//
	// Note: Use Next to ensure there is an item.
	Value() T
}

An Iterator allows consuming individual items in a stream of items.

Directories

Path Synopsis
_example
internal
iters
chanit
Package chanit allows for native Go channels to be used with iterators.
Package chanit allows for native Go channels to be used with iterators.
funcit
Package funcit allows for functional sources of items to be used with iterators.
Package funcit allows for functional sources of items to be used with iterators.
genit
Package genit allows for stateful running goroutines to be used with iterators.
Package genit allows for stateful running goroutines to be used with iterators.
mapit
Package mapit allows for native Go maps to be used with iterators.
Package mapit allows for native Go maps to be used with iterators.
rangeit
Package rangeit allows to iterate over a range of numbers.
Package rangeit allows to iterate over a range of numbers.
runeit
Package runeit allows for native Go runes to be used with iterators.
Package runeit allows for native Go runes to be used with iterators.
sliceit
Package sliceit allows for native Go slices to be used with iterators.
Package sliceit allows for native Go slices to be used with iterators.
valit
Package valit allows for native Go values to be used with iterators.
Package valit allows for native Go values to be used with iterators.
Package itlib provides generic function for operating on iterators.
Package itlib provides generic function for operating on iterators.

Jump to

Keyboard shortcuts

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