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: 4 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[T any] struct {
	// contains filtered or unexported fields
}

Iter is the Iterator based stream implementation.

func New

func New[T any](next func() (T, bool, error)) Iter[T]

New instantiates a stream instance

func (Iter[T]) Conv

func (t Iter[T]) Conv(converter func(T) (T, error)) Iter[T]

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

func (Iter[T]) Convert

func (t Iter[T]) Convert(converter func(T) T) Iter[T]

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

func (Iter[T]) Filt

func (t Iter[T]) Filt(predicate func(T) (bool, error)) Iter[T]

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

func (Iter[T]) Filter

func (t Iter[T]) Filter(predicate func(T) bool) Iter[T]

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

func (Iter[T]) First

func (t Iter[T]) First(predicate func(T) (bool, error)) (T, bool, error)

First returns the first element that satisfies the condition of the 'predicate' function

func (Iter[T]) For

func (t Iter[T]) For(walker func(T) error) error

For applies the 'walker' function for the elements. Return the c.ErrBreak to stop.

func (Iter[T]) HasAny

func (t Iter[T]) HasAny(predicate func(T) (bool, error)) (bool, error)

HasAny finds the first element that satisfies the 'predicate' function condition and returns true if successful

func (Iter[T]) Iter

func (t Iter[T]) Iter() Iter[T]

Iter creates an iterator and returns as interface

func (Iter[T]) Next

func (t Iter[T]) Next() (element T, ok bool, err error)

Next implements c.Iterator

func (Iter[T]) Reduce

func (t Iter[T]) Reduce(merger func(T, T) (T, error)) (T, error)

Reduce reduces the elements into an one using the 'merge' function

func (Iter[T]) Slice

func (t Iter[T]) Slice() ([]T, error)

Slice collects the elements to a slice

type Stream

type Stream[T, I any] interface {
	c.Iterator[T]
	Iter() I

	Slice() ([]T, error)

	Reduce(merger func(T, T) (T, error)) (T, error)
	HasAny(predicate func(T) (bool, error)) (bool, error)
}

Stream is collection or stream of elements in transformation state. It supports interrupting on an error that may occur in intermediate or final executor functions.

Jump to

Keyboard shortcuts

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