transformers

package
v0.0.0-...-e0320dd Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

transformers provide utilities to modify iterators

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[K any, V any](iterator iter.Seq2[K, V], predicate func(K, V) bool) iter.Seq2[K, V]

Filter allows to filter values of an interator specifying a predicate that gets

Example
package main

import (
	"fmt"
	"slices"

	"github.com/4strodev/iterago/builders"
	"github.com/4strodev/iterago/transformers"
)

func main() {
	iterator := transformers.Filter(builders.Range(0, 10, 1), func(k int, v int) bool {
		return v%2 == 0
	})

	items := slices.Collect(transformers.Values(iterator))
	fmt.Println(items)
}
Output:

[0 2 4 6 8]

func Keys

func Keys[K any, V any](iterator iter.Seq2[K, V]) iter.Seq[K]

Keys returns the keys of a iterator iter.Seq2

func Map

func Map[IK any, IV any, OK any, OV any](iterator iter.Seq2[IK, IV], mapper func(k IK, v IV) (OK, OV)) iter.Seq2[OK, OV]

Map allows you to convert an iterator iter.Seq2 into another iterator with mapped keys and values

Example
package main

import (
	"fmt"
	"slices"

	"github.com/4strodev/iterago/builders"
	"github.com/4strodev/iterago/transformers"
)

func main() {
	iterator := transformers.Map(builders.Range(0, 10, 1), func(index int, value int) (string, int) {
		return fmt.Sprintf("\"%d\"", index), value * 2
	})

	values := transformers.Values(iterator)
	valueItems := slices.Collect(values)

	keys := transformers.Keys(iterator)
	keyItems := slices.Collect(keys)

	fmt.Println(valueItems)
	fmt.Println(keyItems)
}
Output:

[0 2 4 6 8 10 12 14 16 18]
["0" "1" "2" "3" "4" "5" "6" "7" "8" "9"]

func Merge

func Merge[K any, V any](iterators ...iter.Seq2[K, V]) iter.Seq2[K, V]

Merge allows you to merge multiple iterators into one.

func Values

func Values[K any, V any](iterator iter.Seq2[K, V]) iter.Seq[V]

Values returns the values of a iterator iter.Seq2

Types

This section is empty.

Jump to

Keyboard shortcuts

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