Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/vendor/github.com/anacrolix/missinggo/iter/iterator.go
akuma06 a41f938cec Add Godep support (#758)
As we have seen, dependencies version can prevent the build. We should
user lock versions on dependencies that we know work:
* Packages are vendored
* Add Godep support
* Added addtional install step in readme
* Fix travis build error
2017-05-26 13:07:22 +02:00

57 lignes
1,1 Kio
Go

package iter
import "github.com/anacrolix/missinggo/slices"
type Iterator interface {
// Advances to the next value. Returns false if there are no more values.
// Must be called before the first value.
Next() bool
// Returns the current value. Should panic when the iterator is in an
// invalid state.
Value() interface{}
// Ceases iteration prematurely. This should occur implicitly if Next
// returns false.
Stop()
}
type sliceIterator struct {
slice []interface{}
value interface{}
ok bool
}
func (me *sliceIterator) Next() bool {
if len(me.slice) == 0 {
return false
}
me.value = me.slice[0]
me.slice = me.slice[1:]
me.ok = true
return true
}
func (me *sliceIterator) Value() interface{} {
if !me.ok {
panic("no value; call Next")
}
return me.value
}
func (me *sliceIterator) Stop() {}
func Slice(a []interface{}) Iterator {
return &sliceIterator{
slice: a,
}
}
func StringIterator(a string) Iterator {
return Slice(slices.ToEmptyInterface(a))
}
func ToSlice(it Iterator) (ret []interface{}) {
for it.Next() {
ret = append(ret, it.Value())
}
return
}