forked from kokardy/listing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
75 lines (62 loc) · 1.63 KB
/
types.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package listing
// Replacer is interface for combinations and permutations
type Replacer interface {
Len() int
Replace([]int) Replacer
}
// IntReplacer is Replacer for int
type IntReplacer []int
// Len implements Replacer.Len
func (il IntReplacer) Len() int {
return len(il)
}
// Replace implements Replacer.Replace
func (il IntReplacer) Replace(indices []int) Replacer {
result := make(IntReplacer, len(indices), len(indices))
for i, idx := range indices {
result[i] = il[idx]
}
return result
}
// RuneReplacer is Replacer for rune
type RuneReplacer []rune
// Len implements Replacer.Len
func (rl RuneReplacer) Len() int {
return len(rl)
}
// Replace implements Replacer.Replace
func (rl RuneReplacer) Replace(indices []int) Replacer {
result := make(RuneReplacer, len(indices), len(indices))
for i, idx := range indices {
result[i] = rl[idx]
}
return result
}
// StringReplacer is Replacer for String
type StringReplacer []string
// Len implements Replacer.Len
func (sl StringReplacer) Len() int {
return len(sl)
}
// Replace implements Replacer.Replace
func (sl StringReplacer) Replace(indices []int) Replacer {
result := make(StringReplacer, len(indices), len(indices))
for i, idx := range indices {
result[i] = sl[idx]
}
return result
}
// Float64Replacer is Replacer for Float64
type Float64Replacer []string
// Len implements Replacer.Len
func (fr Float64Replacer) Len() int {
return len(fr)
}
// Replace implements Replacer.Replace
func (fr Float64Replacer) Replace(indices []int) Replacer {
result := make(Float64Replacer, len(indices), len(indices))
for i, idx := range indices {
result[i] = fr[idx]
}
return result
}