// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package types

import 

// This file defines go1.23 iterator methods for a variety of data
// types. They are not mirrored to cmd/compile/internal/types2, as
// there is no point doing so until the bootstrap compiler it at least
// go1.23; therefore go1.23-style range statements should not be used
// in code common to types and types2, though clients of go/types are
// free to use them.

// Methods returns a go1.23 iterator over all the methods of an
// interface, ordered by Id.
//
// Example: for m := range t.Methods() { ... }
func ( *Interface) () iter.Seq[*Func] {
	return func( func( *Func) bool) {
		for  := range .NumMethods() {
			if !(.Method()) {
				break
			}
		}
	}
}

// ExplicitMethods returns a go1.23 iterator over the explicit methods of
// an interface, ordered by Id.
//
// Example: for m := range t.ExplicitMethods() { ... }
func ( *Interface) () iter.Seq[*Func] {
	return func( func( *Func) bool) {
		for  := range .NumExplicitMethods() {
			if !(.ExplicitMethod()) {
				break
			}
		}
	}
}

// EmbeddedTypes returns a go1.23 iterator over the types embedded within an interface.
//
// Example: for e := range t.EmbeddedTypes() { ... }
func ( *Interface) () iter.Seq[Type] {
	return func( func( Type) bool) {
		for  := range .NumEmbeddeds() {
			if !(.EmbeddedType()) {
				break
			}
		}
	}
}

// Methods returns a go1.23 iterator over the declared methods of a named type.
//
// Example: for m := range t.Methods() { ... }
func ( *Named) () iter.Seq[*Func] {
	return func( func( *Func) bool) {
		for  := range .NumMethods() {
			if !(.Method()) {
				break
			}
		}
	}
}

// Children returns a go1.23 iterator over the child scopes nested within scope s.
//
// Example: for child := range scope.Children() { ... }
func ( *Scope) () iter.Seq[*Scope] {
	return func( func( *Scope) bool) {
		for  := range .NumChildren() {
			if !(.Child()) {
				break
			}
		}
	}
}

// Fields returns a go1.23 iterator over the fields of a struct type.
//
// Example: for field := range s.Fields() { ... }
func ( *Struct) () iter.Seq[*Var] {
	return func( func( *Var) bool) {
		for  := range .NumFields() {
			if !(.Field()) {
				break
			}
		}
	}
}

// Variables returns a go1.23 iterator over the variables of a tuple type.
//
// Example: for v := range tuple.Variables() { ... }
func ( *Tuple) () iter.Seq[*Var] {
	return func( func( *Var) bool) {
		for  := range .Len() {
			if !(.At()) {
				break
			}
		}
	}
}

// Methods returns a go1.23 iterator over the methods of a method set.
//
// Example: for method := range s.Methods() { ... }
func ( *MethodSet) () iter.Seq[*Selection] {
	return func( func( *Selection) bool) {
		for  := range .Len() {
			if !(.At()) {
				break
			}
		}
	}
}

// Terms returns a go1.23 iterator over the terms of a union.
//
// Example: for term := range union.Terms() { ... }
func ( *Union) () iter.Seq[*Term] {
	return func( func( *Term) bool) {
		for  := range .Len() {
			if !(.Term()) {
				break
			}
		}
	}
}

// TypeParams returns a go1.23 iterator over a list of type parameters.
//
// Example: for tparam := range l.TypeParams() { ... }
func ( *TypeParamList) () iter.Seq[*TypeParam] {
	return func( func( *TypeParam) bool) {
		for  := range .Len() {
			if !(.At()) {
				break
			}
		}
	}
}

// Types returns a go1.23 iterator over the elements of a list of types.
//
// Example: for t := range l.Types() { ... }
func ( *TypeList) () iter.Seq[Type] {
	return func( func( Type) bool) {
		for  := range .Len() {
			if !(.At()) {
				break
			}
		}
	}
}