diff --git a/typecheck/set.go b/typecheck/set.go deleted file mode 100644 index b3a4a6f..0000000 --- a/typecheck/set.go +++ /dev/null @@ -1,43 +0,0 @@ -package typecheck - -// Set of type checkers -type Set struct { - types []Type -} - -// New returns a new set of type checkers -func New() *Set { - return &Set{types: make([]Type, 0)} -} - -// Add adds a new type checker -func (s *Set) Add(typeChecker Type) { - s.types = append(s.types, typeChecker) -} - -// Run finds a type checker from the registry matching the type `typeName` -// and uses this checker to check the `value`. If no type checker matches -// the `type`, error is returned by default. -func (s *Set) Run(typeName string, value interface{}) error { - - // find matching type (take first) - for _, typeChecker := range s.types { - if typeChecker == nil { - continue - } - - // found - checkerFunc := typeChecker.Checker(typeName) - if checkerFunc == nil { - continue - } - - // check value - if checkerFunc(value) { - return nil - } - return ErrDoesNotMatch - } - - return ErrNoMatchingType -} diff --git a/typecheck/type.go b/typecheck/type.go deleted file mode 100644 index 0a34e49..0000000 --- a/typecheck/type.go +++ /dev/null @@ -1,18 +0,0 @@ -package typecheck - -import "errors" - -// ErrNoMatchingType when no available type checker matches the type -var ErrNoMatchingType = errors.New("no matching type") - -// ErrDoesNotMatch when the value is invalid -var ErrDoesNotMatch = errors.New("does not match") - -// CheckerFunc returns whether a given value fulfills a type -type CheckerFunc func(interface{}) bool - -// Type represents a type checker -type Type interface { - // given a type name, returns the checker function or NIL if the type is not handled here - Checker(string) CheckerFunc -}