thedevsaddam / gojsonq

A simple Go package to Query over JSON/YAML/XML/CSV Data
https://github.com/thedevsaddam/gojsonq/wiki
MIT License
2.18k stars 140 forks source link

No need to convert y in neq function #15

Closed killernova closed 6 years ago

killernova commented 6 years ago
// eq checks whether x, y are deeply eq
func eq(x, y interface{}) (bool, error) {
    // if the y value is numeric (int/int8-int64/float32/float64) then convert to float64
    if fv, ok := toFloat64(y); ok {
        y = fv
    }
    return reflect.DeepEqual(x, y), nil
}

// neq checks whether x, y are deeply not equal
func neq(x, y interface{}) (bool, error) {
    // if the y value is numeric (int/int8-int64/float32/float64) then convert to float64
    if fv, ok := toFloat64(y); ok {
        y = fv
    }
    b, err := eq(x, y)
    return !b, err
}

Since y is converted in eq function, there's no need to be converted in neq function, right?


another question: why not let notIn function reuse in function?

thedevsaddam commented 6 years ago

@killernova Good catch, It was a mistake to convert the y in neq function.

And for notIn probably we can flip the in function.