stream

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 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)) Iter[T]

New instantiates a stream instance

func (Iter[T]) Append

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

Append collects the elements retrieved by the 'next' function into the specified 'out' slice

func (Iter[T]) Conv

func (t Iter[T]) Conv(converter func(T) (T, error)) breakStream.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)) breakStream.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) (T, bool)

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

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

ForEach applies the 'walker' function for every element

func (Iter[T]) HasAny

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

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() c.Iterator[T]

Iter creates an iterator and returns as interface

func (Iter[T]) Loop

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

Loop creates an iterator and returns as implementation type reference

func (Iter[T]) Next

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

Next implements c.Iterator

func (Iter[T]) Reduce

func (t Iter[T]) Reduce(by func(T, T) T) T

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

func (Iter[T]) Slice

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

Slice collects the elements to a slice

func (Iter[T]) Start added in v0.0.10

func (t Iter[T]) Start() (Iter[T], T, bool)

Start is used with for loop construct like 'for i, val, ok := i.Start(); ok; val, ok = i.Next() { }'

type Stream

type Stream[T any] interface {
	c.Iterator[T]
	c.Collection[T]

	HasAny(func(T) bool) bool
}

Stream is collection or stream of elements in transformation state

Jump to

Keyboard shortcuts

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