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 ¶
Types ¶
type Jukebox ¶
type Jukebox struct {
Records []*Record
}
Jukebox represents the aggregator of vinyl Records, that could Load them in RecordsIterator.
func NewJukebox ¶
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.
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.