ik

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

README

ik

Go Reference

Iter Kit for Go

What's Inside?

Within this package you'll find some useful functions which make using iter.Seq in Go much easier. Check out the documentation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append[T any](t T, s iter.Seq[T]) iter.Seq[T]

Append t to s.

func Chan

func Chan[T any](ch <-chan T) iter.Seq[T]

Chan creats an iter.Seq from a channel.

func Chunk

func Chunk[T any](s iter.Seq[T], chunkSize int) iter.Seq[[]T]

Chunk processes s in chunks of size chunkSize.

func Collect

func Collect[T any](s iter.Seq[T]) []T

Collect s into a slice.

func CollectInto

func CollectInto[T, C any](s iter.Seq[T], collection C, addElement func(element T, collection C) C) C

CollectInto collects s into collection useing collectInto

func Csv

func Csv(r io.ReadCloser) iter.Seq2[[]string, error]

Csv reads the rows of a csv file. Takes ownership of r.

func Elide

func Elide[T any](s iter.Seq2[T, error]) iter.Seq[T]

Elide attempts to ignore errors in s and panics if they occur.

func Enumerate

func Enumerate[T any](s iter.Seq[T]) iter.Seq2[int, T]

Enumerate s.

func Filter

func Filter[T any](s iter.Seq[T], filter func(T) bool) iter.Seq[T]

Filter out unwanted values from s using filter.

func First

func First[T any](s iter.Seq[T], predicate func(T) bool) (t T, ok bool)

First returns the first value in s which matches the given predicate.

func IsSorted

func IsSorted[T cmp.Ordered](s iter.Seq[T]) int

IsSorted returns: 1: array is sorted in ascending order 0: array is unsorted -1: array is sorted in descending order

func IsSortedBy

func IsSortedBy[T any](s iter.Seq[T], order func(a, b T) int) int

IsSortedBy returns: 1: array is sorted in ascending order 0: array is unsorted -1: array is sorted in descending order

func Json

func Json(r io.ReadCloser) iter.Seq2[json.Token, error]

Json creates an iter.Seq2 of json.Tokens and errors.

func Map

func Map[T, U any](s iter.Seq[T], mapper func(T) U) iter.Seq[U]

Map s to another type using a mapper func.

func Max

func Max[T cmp.Ordered](s iter.Seq[T]) (t T, ok bool)

Max returns the maximum element in s

func Min

func Min[T cmp.Ordered](s iter.Seq[T]) (t T, ok bool)

Max returns the maximum element in s

func Prepend

func Prepend[T any](t T, s iter.Seq[T]) iter.Seq[T]

Prepend t to s. This helps solve one of my least favorite features of ticker:

for now := range Prepend(time.Now(), Chan(time.Tick(duration))) {
  // do ticker-y logic
}

func Reduce

func Reduce[T, U any](s iter.Seq[T], reduce func(t T, u U) U, init U) U

Reduce the values found in s using reduce and init.

func Seq2Seq

func Seq2Seq[K, V any](s iter.Seq2[K, V]) iter.Seq[Pair[K, V]]

Seq2Seq makes a Seq out of a Seq2

func Skip

func Skip[T any](s iter.Seq[T], n int) iter.Seq[T]

Skip the first n values.

func SliceRef

func SliceRef[T any](s []T) iter.Seq[*T]

SliceRef returns an iter.Seq which yields references to values in the slice. This is useful when the slice contains large values which shouldn't be copied.

func Sorted

func Sorted[T cmp.Ordered](s iter.Seq[T]) iter.Seq[T]

Sorted sorts the values in T using their default order.

func SortedBy

func SortedBy[T any](s iter.Seq[T], order func(a, b T) int) iter.Seq[T]

SortedBy sorts the values in s using order.

func Sql

func Sql(rows *sql.Rows) iter.Seq[func(...any) error]

Sql creates an iter.Seq from sql.Rows. Each row gives the opportunity to scan the row into a struct. Takes ownership of the rows.

func Take

func Take[T any](s iter.Seq[T], n int) iter.Seq[T]

Take the first n values from s.

func Tee

func Tee[T any](s iter.Seq[T], yield1 func(t T) bool) iter.Seq[T]

Tee the values in s to yield1, returning a new Seq which can be consumed elsewhere.

func Unique

func Unique[T comparable](s iter.Seq[T]) iter.Seq[T]

Unique yields unique values.

func Until

func Until[T any](s iter.Seq[T], until func(T) bool) iter.Seq[T]

Until yields values until until returns false.

Types

type Pair

type Pair[K, V any] struct {
	K K
	V V
}

Pair of values.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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