stream

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package stream provides a stream implementation and helper functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iter

type Iter[K comparable, V any, M map[K]V | map[K][]V] struct {
	// contains filtered or unexported fields
}

Iter is the key/value Iterator based stream implementation.

func New

func New[K comparable, V any, M map[K]V | map[K][]V](next func() (K, V, bool), collector MapCollector[K, V, M]) Iter[K, V, M]

New instantiates StreamIter

func (Iter[K, V, M]) Conv

func (k Iter[K, V, M]) Conv(converter func(K, V) (K, V, error)) stream.Iter[K, V, M]

Conv returns a breakable stream that applies the 'converter' function to the collection elements

func (Iter[K, V, M]) ConvKey

func (k Iter[K, V, M]) ConvKey(by func(K) (K, error)) stream.Iter[K, V, M]

ConvKey returns a stream that applies the 'converter' function to keys of the map

func (Iter[K, V, M]) ConvValue

func (k Iter[K, V, M]) ConvValue(converter func(V) (V, error)) stream.Iter[K, V, M]

ConvValue returns a stream that applies the 'converter' function to values of the map

func (Iter[K, V, M]) Convert

func (k Iter[K, V, M]) Convert(converter func(K, V) (K, V)) Iter[K, V, M]

Convert returns a stream that applies the 'converter' function to the collection elements

func (Iter[K, V, M]) ConvertKey

func (k Iter[K, V, M]) ConvertKey(by func(K) K) Iter[K, V, M]

ConvertKey returns a stream that applies the 'converter' function to keys of the map

func (Iter[K, V, M]) ConvertValue

func (k Iter[K, V, M]) ConvertValue(converter func(V) V) Iter[K, V, M]

ConvertValue returns a stream that applies the 'converter' function to values of the map

func (Iter[K, V, M]) Filt

func (k Iter[K, V, M]) Filt(predicate func(K, V) (bool, error)) stream.Iter[K, V, M]

Filt returns a breakable stream consisting of elements that satisfy the condition of the 'predicate' function

func (Iter[K, V, M]) FiltKey

func (k Iter[K, V, M]) FiltKey(predicate func(K) (bool, error)) stream.Iter[K, V, M]

FiltKey returns a stream consisting of key/value pairs where the key satisfies the condition of the 'predicate' function

func (Iter[K, V, M]) FiltValue

func (k Iter[K, V, M]) FiltValue(predicate func(V) (bool, error)) stream.Iter[K, V, M]

FiltValue returns a stream consisting of key/value pairs where the value satisfies the condition of the 'predicate' function

func (Iter[K, V, M]) Filter

func (k Iter[K, V, M]) Filter(predicate func(K, V) bool) Iter[K, V, M]

Filter returns a stream consisting of elements that satisfy the condition of the 'predicate' function

func (Iter[K, V, M]) FilterKey

func (k Iter[K, V, M]) FilterKey(predicate func(K) bool) Iter[K, V, M]

FilterKey returns a stream consisting of key/value pairs where the key satisfies the condition of the 'predicate' function

func (Iter[K, V, M]) FilterValue

func (k Iter[K, V, M]) FilterValue(predicate func(V) bool) Iter[K, V, M]

FilterValue returns a stream consisting of key/value pairs where the value satisfies the condition of the 'predicate' function

func (Iter[K, V, M]) HasAny

func (k Iter[K, V, M]) HasAny(predicate func(K, V) bool) bool

HasAny finds the first key/value pari that satisfies the 'predicate' function condition and returns true if successful

func (Iter[K, V, M]) Iter

func (k Iter[K, V, M]) Iter() kv.Iterator[K, V]

Iter creates an iterator and returns as interface

func (Iter[K, V, M]) Loop

func (k Iter[K, V, M]) Loop() Iter[K, V, M]

Loop creates an iterator and returns as implementation type reference

func (Iter[K, V, M]) Map

func (k Iter[K, V, M]) Map() M

Map collects the key/value pairs to a map

func (Iter[K, V, M]) Next

func (k Iter[K, V, M]) Next() (K, V, bool)

Next implements kv.KVIterator

func (Iter[K, V, M]) Reduce

func (k Iter[K, V, M]) Reduce(by func(K, K, V, V) (K, V)) (K, V)

Reduce reduces the key/value pairs into an one pair using the 'merge' function

func (Iter[K, V, M]) Track

func (k Iter[K, V, M]) Track(tracker func(K, V) error) error

Track applies the 'tracker' function for key/value pairs. Return the c.ErrBreak to stop.

func (Iter[K, V, M]) TrackEach

func (k Iter[K, V, M]) TrackEach(tracker func(K, V))

TrackEach applies the 'tracker' function for every key/value pairs

type MapCollector

type MapCollector[K comparable, V any, M map[K]V | map[K][]V] func(next func() (K, V, bool)) M

MapCollector is Converter of key/value Iterator that collects all values to any slice or map, mostly used to extract slice fields to flatting a result

type Stream

type Stream[K comparable, V any, M map[K]V | map[K][]V] interface {
	kv.Iterator[K, V]
	kv.Collection[K, V, M]

	HasAny(func(K, V) bool) bool
}

Stream is map or key/value stream of elements in transformation state.

Jump to

Keyboard shortcuts

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