-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspecification.go
More file actions
52 lines (41 loc) · 963 Bytes
/
Copy pathspecification.go
File metadata and controls
52 lines (41 loc) · 963 Bytes
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
package ungo
type Specification[T any] interface {
IsSatisfiedBy(T) bool
}
type ListSpec[T any] struct {
specs []Specification[T]
}
func (s ListSpec[T]) IsSatisfiedBy(value T) bool {
for _, spec := range s.specs {
if !spec.IsSatisfiedBy(value) {
return false
}
}
return true
}
type FuncSpec[T any] struct {
fn func(T) bool
}
func (s FuncSpec[T]) IsSatisfiedBy(value T) bool {
return s.fn(value)
}
type AndSpec[T any] struct {
spec1 Specification[T]
spec2 Specification[T]
}
func (s AndSpec[T]) IsSatisfiedBy(value T) bool {
return s.spec1.IsSatisfiedBy(value) && s.spec2.IsSatisfiedBy(value)
}
type OrSpec[T any] struct {
spec1 Specification[T]
spec2 Specification[T]
}
func (s OrSpec[T]) IsSatisfiedBy(value T) bool {
return s.spec1.IsSatisfiedBy(value) || s.spec2.IsSatisfiedBy(value)
}
type NotSpec[T any] struct {
spec Specification[T]
}
func (s NotSpec[T]) IsSatisfiedBy(value T) bool {
return !s.spec.IsSatisfiedBy(value)
}