Stream

package
v0.2.36 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MIT Imports: 1 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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]) Get added in v0.2.36

func (s *Stream[T]) Get(from int, qty int) ([]T, error)

Get returns qty of items from the stream starting from the given index.

Parameters:

  • from: The index of the first item to get.
  • qty: The number of items to get.

Returns:

  • []T: The items from the stream.
  • error: An error if there are no more items in the stream or if the qty is negative.

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

func (s *Stream[T]) IsDone(from int, qty int) bool

IsDone returns true if from + qty is greater than the number of items in the stream.

Returns:

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

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

	// Get returns qty of items from the stream starting from the given index.
	//
	// Parameters:
	//   - from: The index of the first item to get.
	//   - qty: The number of items to get.
	//
	// Returns:
	//   - []T: The items from the stream.
	//   - error: An error of type *ers.ErrInvalidParameter if from or qty is negative.
	//
	// Behaviors:
	//   - If there are not enough items in the stream, no error is returned
	// 	but the number of items returned will be less than qty.
	Get(from int, qty int) ([]T, error)

	// IsDone returns true if from + qty is greater than the number of items in the stream.
	//
	// Parameters:
	//   - from: The index of the first item to check.
	//   - qty: The number of items to check.
	//
	// Returns:
	//   - bool: True if the stream has been fully consumed.
	IsDone(from int, qty int) bool

	// GetItems returns the items in the stream.
	//
	// Returns:
	//   - []T: The items in the stream.
	GetItems() []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