File: collections.go

package info (click to toggle)
golang-github-badgerodon-collections 0.0~git20130729.604e922-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 172 kB
  • sloc: makefile: 5
file content (27 lines) | stat: -rw-r--r-- 431 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package collections

type (
	Collection interface {
		Do(func(interface{})bool)
	}
)

func GetRange(c Collection, start, length int) []interface{} {
	end := start + length
	items := make([]interface{}, length)
	i := 0
	j := 0
	c.Do(func(item interface{})bool{
		if i >= start {
			if i < end {
				items[j] = item
				j++
			} else {
				return false
			}
		}
		i++
		return true
	})
	return items[:j]
}