Stream

package
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 2 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 quantity or from is negative.

Behaviors:

  • Use qty -1 to get all items from 'from' to the end of the stream.

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]) GetOne added in v0.3.1

func (s *Stream[T]) GetOne(index int) (T, error)

GetOne returns the item at the given index.

Parameters:

  • index: The index of the item to get.

Returns:

  • T: The item at the given index.
  • error: An error if the index is negative or out of bounds.

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]) Iterator added in v0.3.1

func (s *Stream[T]) Iterator() ll.Iterater[T]

Iterator returns an iterator for the stream.

Returns:

  • ll.Iterater[T]: An iterator for the stream.

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.

Jump to

Keyboard shortcuts

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