stream

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 5 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, error), collector MapCollector[K, V, M]) Iter[K, V, M]

New is the main stream constructor

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

func (k Iter[K, V, M]) Filt(predicate func(K, V) (bool, error)) 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)) 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)) 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, error)) (bool, error)

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]) Map

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

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, error)

Next implements kv.KVIterator

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

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

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.

type MapCollector

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

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, Map map[K]V | map[K][]V] interface {
	kv.Iterator[K, V]
	Iter() kv.Iterator[K, V]

	Map() (Map, error)

	Reduce(merger func(K, V, K, V) (K, V, error)) (K, V, error)
	HasAny(predicate func(K, V) (bool, error)) (bool, error)
}

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