remove typecheck

This commit is contained in:
Adrien Marquès 2020-03-16 12:53:37 +01:00
parent b38a9a8111
commit acd0e73438
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
2 changed files with 0 additions and 61 deletions

View File

@ -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
}

View File

@ -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
}