Skip to content

Commit

Permalink
refactor(logic): use TermString instead of generic any type
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Jan 17, 2023
1 parent 6235cdd commit 130bea3
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions x/logic/types/logic.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
package types

import (
"bytes"
"fmt"
"reflect"
"sort"

"github.com/ichiban/prolog"
)

// TermResults is a map from variable strings to prolog term values.
type TermResults map[string]interface{}
type TermResults map[string]prolog.TermString

// ToSubstitutions converts a TermResults value to a slice of Substitution values.
func (t TermResults) ToSubstitutions() []Substitution {
substitutions := make([]Substitution, 0, len(t))
for v, ts := range t {
var term string
if reflect.TypeOf(ts).Kind() == reflect.Slice {
var buf bytes.Buffer
for _, t := range ts.([]interface{}) {
buf.WriteString(fmt.Sprintf("%v", t))
}
term = buf.String()
} else {
term = fmt.Sprintf("%v", ts)
}

substitution := Substitution{
Variable: v,
Term: Term{
Name: term,
Name: string(ts),
},
}
substitutions = append(substitutions, substitution)
Expand Down

0 comments on commit 130bea3

Please sign in to comment.