Stream

package
v0.2.33 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 0 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrNoMoreItems

type ErrNoMoreItems struct{}

ErrNoMoreItems is an error that indicates that there are no more items in the stream.

func NewErrNoMoreItems

func NewErrNoMoreItems() *ErrNoMoreItems

NewErrNoMoreItems creates a new ErrNoMoreItems error.

Returns:

  • *ErrNoMoreItems: A pointer to the new error.

func (*ErrNoMoreItems) Error

func (e *ErrNoMoreItems) Error() string

Error is a method of errors that returns the error message.

Returns:

  • string: The error message.

type Stream

type Stream[T any] struct {
	// contains filtered or unexported fields
}

Stream is a stream of items.

Side effects:

  • Modifications to the elements inserted and removed from the stream can affect the stream's values. Especially if the elements are pointers.

func NewStream

func NewStream[T any](items []T) *Stream[T]

NewStream creates a new stream with the given items.

Parameters:

  • items: The items to add to the stream.

Returns:

  • Stream: The new stream.

func (*Stream[T]) Consume

func (s *Stream[T]) Consume() T

Consume consumes the next item in the stream. It panics if there are no more items in the stream.

Returns:

  • T: The consumed item.

func (*Stream[T]) GetItems

func (s *Stream[T]) GetItems() []T

GetItems returns the items in the stream.

Returns:

  • []T: The items in the stream.

func (*Stream[T]) GetLeftoverItems

func (s *Stream[T]) GetLeftoverItems() []T

GetLeftoverItems returns the items that have not been consumed.

Returns:

  • []T: The leftover items in the stream.

func (*Stream[T]) IsDone

func (s *Stream[T]) IsDone() bool

IsDone returns true if the stream has been fully consumed.

Returns:

  • bool: True if the stream has been fully consumed.

func (*Stream[T]) IsEmpty

func (s *Stream[T]) IsEmpty() bool

IsEmpty returns true if the stream is empty.

Returns:

  • bool: True if the stream is empty.

func (*Stream[T]) Peek

func (s *Stream[T]) Peek() T

Peek returns the next item in the stream without consuming it. It panics if there are no more items in the stream.

Returns:

  • T: The next item in the stream.

func (*Stream[T]) Reset

func (s *Stream[T]) Reset()

Reset resets the stream to the beginning.

func (*Stream[T]) Size

func (s *Stream[T]) Size() int

Size returns the number of items in the stream.

Returns:

  • int: The number of items in the stream.

type Streamer

type Streamer[T any] interface {
	// Size returns the number of items in the stream.
	//
	// Returns:
	//   - int: The number of items in the stream.
	Size() int

	// IsEmpty returns true if the stream is empty.
	//
	// Returns:
	//   - bool: True if the stream is empty.
	IsEmpty() bool

	// Peek returns the next item in the stream without consuming it.
	// It panics if there are no more items in the stream.
	//
	// Returns:
	//   - T: The next item in the stream.
	Peek() T

	// Consume consumes the next item in the stream.
	// It panics if there are no more items in the stream.
	//
	// Returns:
	//   - T: The consumed item.
	Consume() T

	// Reset resets the stream to the beginning.
	Reset()

	// IsDone returns true if the stream has been fully consumed.
	//
	// Returns:
	//   - bool: True if the stream has been fully consumed.
	IsDone() bool

	// GetItems returns the items in the stream.
	//
	// Returns:
	//   - []T: The items in the stream.
	GetItems() []T

	// GetLeftoverItems returns the items that have not been consumed.
	//
	// Returns:
	//   - []T: The leftover items in the stream.
	GetLeftoverItems() []T
}

Streamer is an interface for streams of items.

Jump to

Keyboard shortcuts

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