]> git.lizzy.rs Git - go-anidb.git/blobdiff - misc/episode.go
misc: Make the iterator part of EpisodeContainer interface
[go-anidb.git] / misc / episode.go
index c5d41a88e3e566beaebbd9a8285947f08b64c596..fee19d8ba920647955fb121ca4c5d0da2f22a094 100644 (file)
@@ -10,6 +10,9 @@ import (
 type EpisodeContainer interface {
        // Returns true if this EpisodeContainer is equivalent or a superset of the given EpisodeContainer
        ContainsEpisodes(EpisodeContainer) bool
+       // Returns a channel meant for iterating with for/range.
+       // Sends all contained episodes in order.
+       Episodes() chan Episode
 }
 
 type Formatter interface {
@@ -95,6 +98,15 @@ func (ep *Episode) scale() int {
        return scale(ep.Number)
 }
 
+func (ep *Episode) Episodes() chan Episode {
+       ch := make(chan Episode, 1)
+       if ep != nil {
+               ch <- *ep
+       }
+       close(ch)
+       return ch
+}
+
 // Returns true if ec is an Episode and is identical to this episode,
 // or if ec is a single episode EpisodeRange / EpisodeList that
 // contain only this episode.