Skip to content

Commit

Permalink
Merge pull request #3980 from aledbf/refactor-isiterable
Browse files Browse the repository at this point in the history
Refactor isIterable
  • Loading branch information
k8s-ci-robot authored Apr 9, 2019
2 parents 4cc086a + 6d02a9e commit 10c0df5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/sets/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ type equalFunction func(e1, e2 interface{}) bool

// Compare checks if the parameters are iterable and contains the same elements
func Compare(listA, listB interface{}, eq equalFunction) bool {
a := reflect.ValueOf(listA)
ok := isIterable(a)
ok := isIterable(listA)
if !ok {
return false
}

b := reflect.ValueOf(listB)
ok = isIterable(b)
ok = isIterable(listB)
if !ok {
return false
}

a := reflect.ValueOf(listA)
b := reflect.ValueOf(listB)

if a.IsNil() && b.IsNil() {
return true
}
Expand Down Expand Up @@ -91,9 +92,9 @@ func StringElementsMatch(a, b []string) bool {
return Compare(a, b, compareStrings)
}

func isIterable(obj reflect.Value) bool {
func isIterable(obj interface{}) bool {
switch reflect.TypeOf(obj).Kind() {
case reflect.Struct, reflect.Slice, reflect.Array:
case reflect.Slice, reflect.Array:
return true
default:
return false
Expand Down

0 comments on commit 10c0df5

Please sign in to comment.