Skip to content

Commit

Permalink
(chore)Export ApplyParams
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjunwen committed Sep 22, 2020
1 parent c3976f9 commit 6759dc9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions array_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func AddOpMerge(jl *JSONLogic) {
}

func opMerge(apply Applier, params []interface{}, data interface{}) (res interface{}, err error) {
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand All @@ -252,7 +252,7 @@ func opIn(apply Applier, params []interface{}, data interface{}) (res interface{
if len(params) < 2 {
return nil, fmt.Errorf("in: expect at least two params")
}
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand Down Expand Up @@ -292,7 +292,7 @@ func AddOpCat(jl *JSONLogic) {
}

func opCat(apply Applier, params []interface{}, data interface{}) (res interface{}, err error) {
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand All @@ -317,7 +317,7 @@ func opSubstr(apply Applier, params []interface{}, data interface{}) (res interf
if len(params) < 2 {
return nil, fmt.Errorf("substr: expect at least two params")
}
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func opVar(apply Applier, params []interface{}, data interface{}) (res interface
if len(params) < 1 {
return nil, fmt.Errorf("var: expect at least one param")
}
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand Down Expand Up @@ -90,7 +90,7 @@ func opMissing(apply Applier, params []interface{}, data interface{}) (res inter
if len(params) == 0 {
return []interface{}{}, nil
}
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func opMissingSome(apply Applier, params []interface{}, data interface{}) (res i
if len(params) != 2 {
return nil, fmt.Errorf("missing_some: expect 2 params")
}
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand Down
3 changes: 2 additions & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ func compareValues(symbol compSymbol, left, right interface{}) (bool, error) {

}

func applyParams(apply Applier, params []interface{}, data interface{}) ([]interface{}, error) {
// ApplyParams apply data to an array of params. Useful in operation implementation.
func ApplyParams(apply Applier, params []interface{}, data interface{}) ([]interface{}, error) {
r, err := apply(params, data)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func opStrictEqual(apply Applier, params []interface{}, data interface{}) (res i
if len(params) < 2 {
return nil, fmt.Errorf("===/!==: expect at least two params")
}
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func opCompare(symbol compSymbol) Operation {
if len(params) < 2 {
return nil, fmt.Errorf("%s: expect at least two params", symbol)
}
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func opMinus(apply Applier, params []interface{}, data interface{}) (res interfa
}
return -n, nil
default:
params, err := applyParams(apply, params, data)
params, err := ApplyParams(apply, params, data)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func opDiv(apply Applier, params []interface{}, data interface{}) (res interface
if len(params) < 2 {
return nil, fmt.Errorf("/: expect at least two params")
}
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func opMod(apply Applier, params []interface{}, data interface{}) (res interface
if len(params) < 2 {
return nil, fmt.Errorf("%%: expect at least two params")
}
params, err = applyParams(apply, params, data)
params, err = ApplyParams(apply, params, data)
if err != nil {
return
}
Expand Down

0 comments on commit 6759dc9

Please sign in to comment.