Skip to content

Commit

Permalink
feat(prolog): add default value support to GetOption func
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Oct 27, 2023
1 parent e011a17 commit 9a2dee9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions x/logic/util/prolog.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,14 @@ func GetOption(name engine.Atom, options engine.Term, env *engine.Env) (engine.T
}
return extractOption(resolvedTerm)
}

// GetOptionWithDefault returns the value of the first option with the given name in the given options, or the given
// default value if no option is found.
func GetOptionWithDefault(name engine.Atom, options engine.Term, defaultValue engine.Term, env *engine.Env) (engine.Term, error) {
if term, err := GetOption(name, options, env); err != nil {
return nil, err
} else if term != nil {
return term, nil
}
return defaultValue, nil
}

0 comments on commit 9a2dee9

Please sign in to comment.