-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters_r.go
40 lines (36 loc) · 1.28 KB
/
filters_r.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
package arrayr
import "github.com/eenti-utils/typr"
// ⚠ uses reflection
//
// returns an array comprised of any elements that appeared more than once in the original specification
// - if no elements appeared more than once, then the resulting array has a length of zero
// - the resulting array, if not empty, will have unique elements
func RepeatedR[V any](a ...V) (r []V) {
if len(a) > 0 {
qualify := func(p typr.Pair[V, int]) (r bool) { return p.Y > 1 }
r = convert(pairX[V], doFilter(qualify, doFrequencyR(a...)...)...)
}
return
}
// ⚠ uses reflection
//
// returns an array comprised of the elements specified, where each element appears exactly once,
// in the resulting array
func UniqueR[V any](a ...V) (r []V) {
if len(a) > 0 {
r = convert(pairX[V], doFrequencyR(a...)...)
}
return
}
// ⚠ uses reflection
//
// returns an array comprised of any elements that only appeared once in the original specification
// - if no elements appeared only once, then the resulting array has a length of zero
// - the resulting array, if not empty, will have unique elements
func UnrepeatedR[V any](a ...V) (r []V) {
if len(a) > 0 {
qualify := func(p typr.Pair[V, int]) (r bool) { return p.Y == 1 }
r = convert(pairX[V], doFilter(qualify, doFrequencyR(a...)...)...)
}
return
}