Debian Codegraph @

gopls/internal/analysis/recursiveiter/testdata/src/a/a.go

raw symbols SCIP
1 // Copyright 2025 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package recursiveiter
6
7 import "iter"
8
9 type cons struct {
10 car int
11 cdr *cons
12 }
13
14 func (cons *cons) All() iter.Seq[int] {
15 return func(yield func(int) bool) {
16 // The correct recursion is:
17 // func (cons *cons) all(f func(int) bool) {
18 // return cons == nil || yield(cons.car) && cons.cdr.all()
19 // }
20 // then:
21 // _ = cons.all(yield)
22 if cons != nil && yield(cons.car) {
23 for elem := range cons.All() { // want "inefficient recursion in iterator All"
24 if !yield(elem) {
25 break
26 }
27 }
28 }
29 }
30 }