Skip to content

Instantly share code, notes, and snippets.

@ppmathis
Created April 21, 2019 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppmathis/0368c309a0092a553d2e61a8fceba88d to your computer and use it in GitHub Desktop.
Save ppmathis/0368c309a0092a553d2e61a8fceba88d to your computer and use it in GitHub Desktop.
package nagopher
import "github.com/markphelps/optional"
type thresholdModule struct{}
type thresholdOpt func(*threshold)
type threshold struct {
inverted bool
lowerBound optional.Float64
upperBound optional.Float64
}
var Threshold thresholdModule
func (thresholdModule) New(options ...thresholdOpt) *threshold {
threshold := &threshold{
inverted: false,
}
for _, option := range options {
option(threshold)
}
return threshold
}
func (thresholdModule) Inverted(state bool) thresholdOpt {
return func(t *threshold) {
t.inverted = state
}
}
func (thresholdModule) LowerBound(value float64) thresholdOpt {
return func(t *threshold) {
t.lowerBound = optional.NewFloat64(value)
}
}
func (thresholdModule) UpperBound(value float64) thresholdOpt {
return func(t *threshold) {
t.upperBound = optional.NewFloat64(value)
}
}
func (t *threshold) LowerBound() optional.Float64 {
return t.lowerBound
}
func (t *threshold) UpperBound() optional.Float64 {
return t.upperBound
}
func (t *threshold) Inverted() bool {
return t.inverted
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment