// Iterate is a set of helpers for iteration. Context may be used to cancel execution.
// Iterator will be optimized and closed after execution.
//
// By default, iteration has no limit and includes sub-paths.
1376
func Iterate(ctx context.Context, it Iterator) *IterateChain {
	if ctx == nil {
		ctx = context.Background()
	}
	return &IterateChain{
		ctx: ctx, it: it,
		limit: -1, paths: true,
		optimize: true,
	}
}
729833
func (s *set) Iter(f func(*Term) error) error {
	for i := range s.keys {
		if err := f(s.keys[i]); err != nil {
			return err
		}
	}
	return nil
}
1228354
func (db *CLevelDB) Iterator(start, end []byte) Iterator {
	itr := db.db.NewIterator(db.ro)
	return newCLevelDBIterator(itr, start, end, false)
}
42004
func (c *IterateChain) Each(fnc func(Value)) error {
	c.start()
	defer c.end()
	done := c.ctx.Done()

	for c.next() {
		select {
		case <-done:
			return c.ctx.Err()
		default:
		}
		fnc(c.it.Result())
		for c.nextPath() {
			select {
			case <-done:
				return c.ctx.Err()
			default:
			}
			fnc(c.it.Result())
		}
	}
	return c.it.Err()
}
1313792
func (f *FST) Iterator(startKeyInclusive, endKeyExclusive []byte) (*FSTIterator, error) {
	return newIterator(f, startKeyInclusive, endKeyExclusive, nil)
}
808087
func (r *ResourceDefinition) IterateActions(it ActionIterator) error {
	names := make([]string, len(r.Actions))
	i := 0
	for n := range r.Actions {
		names[i] = n
		i++
	}
	sort.Strings(names)
	for _, n := range names {
		if err := it(r.Actions[n]); err != nil {
			return err
		}
	}
	return nil
}
548551
func (o Object) IterateAttributes(it AttributeIterator) error {
	names := make([]string, len(o))
	i := 0
	for n := range o {
		names[i] = n
		i++
	}
	sort.Strings(names)
	for _, n := range names {
		if err := it(n, o[n]); err != nil {
			return err
		}
	}
	return nil
}
616660
func (d *Dictionary) Iterator() segment.DictionaryIterator {
	rv := &DictionaryIterator{
		d: d,
	}

	if d.fst != nil {
		itr, err := d.fst.Iterator(nil, nil)
		if err == nil {
			rv.itr = itr
		} else if err != vellum.ErrIteratorDone {
			rv.err = err
		}
	}

	return rv
}
836444
func Iterator(f func([]byte, []byte) bool) error {
	if db == nil {
		return nil
	}
	return db.Iterator(f)
}
680690
func IteratePrefix(db DB, prefix []byte) Iterator {
	var start, end []byte
	if len(prefix) == 0 {
		start = nil
		end = nil
	} else {
		start = cp(prefix)
		end = cpIncr(prefix)
	}
	return db.Iterator(start, end)
}
587552
func (t *PairTree) Iter() <-chan Pair {
	c := make(chan Pair)
	go t.chanIterate(c)
	return c
}
1122017
func (is *InputStruct) Iterator(index int) (sophie.IterateCloser, error) {
	if is.IteratorF != nil {
		return is.IteratorF(index)
	}
	return &sophie.IterateCloserStruct{}, nil
}
1286110
func (t *ImmutableTree) IterateRange(start, end []byte, ascending bool, fn func(key []byte, value []byte) bool) (stopped bool) {
	if t.root == nil {
		return false
	}
	return t.root.traverseInRange(t, start, end, ascending, false, 0, func(node *Node, _ uint8) bool {
		if node.height == 0 {
			return fn(node.key, node.value)
		}
		return false
	})
}
444676
func (kv *KV) Iterator(f func([]byte, []byte) bool) error {
	return kv.db.View(func(tx *bolt.Tx) error {
		tx.Bucket(kv.table).ForEach(func(k, v []byte) error {
			if k == nil || f(k, v) {
				return nil
			}
			return errors.New("stop")
		})
		return nil
	})
}
130355
func (u *User) Iterator() <-chan Tuple {
	ch := make(chan Tuple)
	go func() {
		u.RLock()
		for key, val := range u.data {
			ch <- Tuple{key, val}
		}
		u.RUnlock()
		close(ch)
	}()
	return ch
}
1235028
func (a *APIDefinition) IterateResources(it ResourceIterator) error {
	res := make([]*ResourceDefinition, len(a.Resources))
	i := 0
	for _, r := range a.Resources {
		res[i] = r
		i++
	}
	// Iterate parent resources first so that action parameters are
	// finalized prior to child actions needing them.
	isParent := func(p, c *ResourceDefinition) bool {
		par := c.Parent()
		for par != nil {
			if par == p {
				return true
			}
			par = par.Parent()
		}
		return false
	}
	sort.Slice(res, func(i, j int) bool {
		if isParent(res[i], res[j]) {
			return true
		}
		if isParent(res[j], res[i]) {
			return false
		}
		return res[i].Name < res[j].Name
	})
	for _, r := range res {
		if err := it(r); err != nil {
			return err
		}
	}
	return nil
}
176142
func (c *IterateChain) All() ([]Value, error) {
	c.start()
	defer c.end()
	done := c.ctx.Done()
	var out []Value
iteration:
	for c.next() {
		select {
		case <-done:
			break iteration
		default:
		}
		out = append(out, c.it.Result())
		for c.nextPath() {
			select {
			case <-done:
				break iteration
			default:
			}
			out = append(out, c.it.Result())
		}
	}
	return out, c.it.Err()
}