Skip to content

Commit

Permalink
eval func should return ok not err
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Feb 21, 2019
1 parent ded2b11 commit f7f9cc6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
11 changes: 2 additions & 9 deletions cmd/tsl_mem/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
package main

import (
"fmt"

"github.com/yaacov/tsl/pkg/walkers/semantics"

"github.com/yaacov/tsl/cmd/model"
Expand All @@ -33,13 +31,8 @@ type Book map[string]interface{}
var Books = []Book{}

func evalFactory(book Book) semantics.EvalFunc {
return func(k string) (interface{}, error) {
v, ok := book[k]
if !ok {
return nil, fmt.Errorf("no value for key %s", k)
}

return v, nil
return func(k string) (interface{}, bool) {
return book[k], true
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/walkers/semantics/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

// EvalFunc is a key evaluation function type.
type EvalFunc = func(string) (interface{}, error)
type EvalFunc = func(string) (interface{}, bool)

// Walk travel the TSL tree and implements search semantics.
//
Expand All @@ -44,9 +44,9 @@ type EvalFunc = func(string) (interface{}, error)
//
// // evalFactory creates an evaluation function for a data record.
// func evalFactory(r map[string]string) semantics.EvalFunc {
// return func(k string) (interface{}, error) {
// v := r[k]
// return v, nil
// return func(k string) (interface{}, bool) {
// v, ok := r[k]
// return v, ok
// }
// }
//
Expand Down

0 comments on commit f7f9cc6

Please sign in to comment.