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 ¶
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 ¶
IsDone returns true if the stream has been fully consumed.
Returns:
- bool: True if the stream has been fully consumed.
func (*Stream[T]) IsEmpty ¶
IsEmpty returns true if the stream is empty.
Returns:
- bool: True if the stream is empty.
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.