File: cursor.go

package info (click to toggle)
golang-github-cloudflare-circl 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,060 kB
  • sloc: asm: 20,492; ansic: 1,292; makefile: 68
file content (15 lines) | stat: -rw-r--r-- 345 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Package cursor aids with iteration of slices.
package cursor

type Cursor[V ~[]E, E any] []E

func New[V ~[]E, E any](x V) Cursor[V, E] { return Cursor[V, E](x) }

// Next return an slice of size n and advances the pointer.
func (s *Cursor[V, E]) Next(n uint) (out V) {
	if uint(len(*s)) >= n {
		out = V(*s)[:n]
		*s = (*s)[n:]
	}
	return
}