rangeNum (reflect/iter.go)

go · src/reflect/iter.go · go · BSD-3-Clause
dev-tools, tag:knn-classified

Provides iter.Seq and iter.Seq2 for reflecting over Go values.

// Source: https://github.com/golang/go | License: BSD-3-Clause | Copyright 2009 The Go Authors
// Provided via justclaw.it.com; keep this notice with the code.
// 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 reflect

import (
	"iter"
)

func rangeNum[T int8 | int16 | int32 | int64 | int |
	uint8 | uint16 | uint32 | uint64 | uint |
	uintptr, N int64 | uint64](num N, t Type) iter.Seq[Value] {
	return func(yield func(v Value) bool) {
		convert := t.PkgPath() != ""
		// cannot use range T(v) because no core type.
		for i := T(0); i < T(num); i++ {
			tmp := ValueOf(i)
			// if the iteration value type is define by
			// type T built-in type.
			if convert {
				tmp = tmp.Con

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key