-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecification.go
46 lines (36 loc) · 1.25 KB
/
specification.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
package specp
type Satisfier[T any] interface {
IsSatisfiedBy(value T) bool
}
type Specification[T any] interface {
Satisfier[T]
And(other Specification[T]) Specification[T]
AndNot(other Specification[T]) Specification[T]
Not() Specification[T]
OrNot(other Specification[T]) Specification[T]
Or(other Specification[T]) Specification[T]
}
type CompositeSpecification[T any] struct {
Value Satisfier[T]
}
func NewCompositeSpecification[T any](satisfier Satisfier[T]) CompositeSpecification[T] {
return CompositeSpecification[T]{Value: satisfier}
}
func (c CompositeSpecification[T]) IsSatisfiedBy(value T) bool {
return c.Value.IsSatisfiedBy(value)
}
func (c CompositeSpecification[T]) And(other Specification[T]) Specification[T] {
return NewAndSpecificiation[T](c, other)
}
func (c CompositeSpecification[T]) AndNot(other Specification[T]) Specification[T] {
return NewAndNotSpecificiation[T](c, other)
}
func (c CompositeSpecification[T]) Not() Specification[T] {
return NewNotSpecification[T](c)
}
func (c CompositeSpecification[T]) OrNot(other Specification[T]) Specification[T] {
return NewOrNotSpecification[T](c, other)
}
func (c CompositeSpecification[T]) Or(other Specification[T]) Specification[T] {
return NewOrSpecification[T](c, other)
}