@@ -16,51 +16,50 @@ import (
1616//
1717// Validation errors are returned to the caller
1818func All (in , predicateFn interface {}) (bool , error ) {
19- var output bool = true ;
19+
2020 input := reflect .ValueOf (in )
2121 predicate := reflect .ValueOf (predicateFn )
2222
2323 if predicate .Kind () != reflect .Func {
24- return output , fmt .Errorf ("predicateFn has to be a function" )
24+ return false , fmt .Errorf ("predicateFn has to be a function" )
2525 }
2626
2727 predicateFnType := predicate .Type ()
2828 if predicateFnType .NumIn () != 1 {
29- return output , fmt .Errorf ("predicate function has to take only one argument" )
29+ return false , fmt .Errorf ("predicate function has to take only one argument" )
3030 }
3131
3232 if predicateFnType .NumOut () != 1 {
33- return output , fmt .Errorf ("predicate function should return only one return value" )
33+ return false , fmt .Errorf ("predicate function should return only one return value" )
3434 }
3535
3636 if predicateFnType .Out (0 ).Kind () != reflect .Bool {
37- return output , fmt .Errorf ("predicate function should return a boolean value" )
37+ return false , fmt .Errorf ("predicate function should return a boolean value" )
3838 }
3939
4040 inputKind := input .Kind ()
4141 if inputKind == reflect .Slice {
4242 inputSliceElemType := input .Type ().Elem
4343 predicateFnArgType := predicateFnType .In (0 )
4444 if inputSliceElemType () != predicateFnArgType {
45- return output , fmt .Errorf ("predicate function's argument (%s) has to be (%s)" , predicateFnArgType , inputSliceElemType ())
45+ return false , fmt .Errorf ("predicate function's argument (%s) has to be (%s)" , predicateFnArgType , inputSliceElemType ())
4646 }
4747
4848 for i := 0 ; i < input .Len (); i ++ {
4949 arg := input .Index (i )
5050 returnValue := predicate .Call ([]reflect.Value {arg })[0 ]
5151 if ! returnValue .Bool () {
52- output = false
53- break
52+ return false , nil
5453 }
5554 }
5655
57- return output , nil
56+ return true , nil
5857 }
5958
60- return output , fmt .Errorf ("not implemented for (%s)" , inputKind )
59+ return false , fmt .Errorf ("not implemented for (%s)" , inputKind )
6160}
6261
6362// Every is an alias for All function
6463func Every (in , predicateFn interface {}) (bool , error ) {
6564 return All (in , predicateFn )
66- }
65+ }
0 commit comments