Debian Codegraph @

iter.go

raw symbols SCIP
1 // Copyright 2014 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 iter provides a syntactically different way to iterate over
6 // integers. That's it.
7 //
8 // This package was intended to be an educational joke when it was
9 // released in 2014. People didn't get the joke part and started
10 // depending on it. That's fine, I guess. (This is the Internet.) But
11 // it's kinda weird. It's one line, and not even idiomatic Go style. I
12 // encourage you not to depend on this or write code like this, but I
13 // do encourage you to read the code and think about the
14 // representation of Go slices and why it doesn't allocate.
15 package iter
16
17 // N returns a slice of n 0-sized elements, suitable for ranging over.
18 //
19 // For example:
20 //
21 // for i := range iter.N(10) {
22 // fmt.Println(i)
23 // }
24 //
25 // ... will print 0 to 9, inclusive.
26 //
27 // It does not cause any allocations.
28 func N(n int) []struct{} {
29 return make([]struct{}, n)
30 }