Created
April 21, 2019 20:14
-
-
Save ppmathis/0368c309a0092a553d2e61a8fceba88d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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