iterator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package iterator implements the Iterator design pattern. The Jukebox aggregates a collection of vinyl Records. Its Load method returns a RecordsIterator, which can traverse through collection manually using the Next and Prev methods, or sequentially using a goroutine and channel via the Sequentially method.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run()

Types

type Jukebox

type Jukebox struct {
	Records []*Record
}

Jukebox represents the aggregator of vinyl Records, that could Load them in RecordsIterator.

func NewJukebox

func NewJukebox(records []*Record) *Jukebox

NewJukebox constructs the new Jukebox.

func (*Jukebox) Load

func (j *Jukebox) Load() *RecordsIterator

Load returns the RecordIterator for the Jukebox.

type Player

type Player interface {
	Stop()
	Play()
}

Player is a general interface that defines the playing abilities.

type Record

type Record struct {
	Playing bool
	// contains filtered or unexported fields
}

Record represents the vinyl record that could be played separately of within Jukebox.

func NewRecord

func NewRecord(artist, title string, duration int) *Record

NewRecord construct the new Record.

func (*Record) Play

func (r *Record) Play()

Play sets Record's playing state to true.

func (*Record) Stop

func (r *Record) Stop()

Stop sets Record's playing state to false.

func (*Record) String

func (r *Record) String() string

String formats Record information in human readable format.

type RecordsIterator

type RecordsIterator struct {
	// contains filtered or unexported fields
}

RecordsIterator represents the iterator that allows to traverse through jukebox collection manually or sequentially.

func NewRecordsIterator

func NewRecordsIterator(juke *Jukebox) *RecordsIterator

NewRecordsIterator constructs the RecordsIterator.

func (*RecordsIterator) Next

func (ri *RecordsIterator) Next() *Record

Next returns the next Record in jukebox's collection and stops previously played record.

func (*RecordsIterator) Prev

func (ri *RecordsIterator) Prev() *Record

Prev returns the previous Record in jukebox's collection and stops current record.

func (*RecordsIterator) Sequentially

func (ri *RecordsIterator) Sequentially() <-chan *Record

Sequentially returns the channel of Records, that allows to traverse through collection sequentially.

Jump to

Keyboard shortcuts

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