iterutil

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package iterutil provides utilities for iterators.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Seq2ToSeq

func Seq2ToSeq[In1, In2, Out any](in iter.Seq2[In1, In2], convert func(In1, In2) Out) iter.Seq[Out]

Seq2ToSeq converts a iter.Seq2 to a iter.Seq.

Example
ss := []string{"zero", "one", "two"}
it := Seq2ToSeq(slices.All(ss), NewKeyVal)
for kv := range it {
	fmt.Println(kv.Key, kv.Val)
}
Output:
0 zero
1 one
2 two

func SeqToSeq2

func SeqToSeq2[In, Out1, Out2 any](in iter.Seq[In], convert func(In) (Out1, Out2)) iter.Seq2[Out1, Out2]

SeqToSeq2 converts a iter.Seq to a iter.Seq2.

Example
kvs := []KeyVal[int, string]{
	NewKeyVal(0, "zero"),
	NewKeyVal(1, "one"),
	NewKeyVal(2, "two"),
}
it := SeqToSeq2(slices.Values(kvs), KeyVal[int, string].Values)
for k, v := range it {
	fmt.Println(k, v)
}
Output:
0 zero
1 one
2 two

Types

type KeyVal

type KeyVal[K, V any] struct {
	Key K
	Val V
}

KeyVal represents a key-value pair.

func NewKeyVal

func NewKeyVal[K, V any](key K, val V) KeyVal[K, V]

NewKeyVal creates a new KeyVal.

func (KeyVal[K, V]) Values

func (kv KeyVal[K, V]) Values() (key K, val V)

Values returns the key and value of the KeyVal.

Jump to

Keyboard shortcuts

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