@@ -43,23 +43,26 @@ const (
4343 FuncLogical
4444)
4545
46- // ConvertsToValue returns true if ft can be converted to a [ValueType]. Used
47- // by [github.com/theory/jsonpath/registry.NewFunction] validator functions
48- // to ensure the compatibility of parameter expressions.
46+ // ConvertsToValue returns true if ft can be converted to a [ValueType]. In
47+ // other words, ft values can safely be passed to [ValueFrom] without it
48+ // panicking. Used by [github.com/theory/jsonpath/registry.NewFunction]
49+ // validator functions to ensure the compatibility of parameter expressions.
4950func (ft FuncType ) ConvertsToValue () bool {
5051 return ft == FuncValue || ft == FuncLiteral || ft == FuncSingularQuery
5152}
5253
5354// ConvertsToLogical returns true if ft can be converted to a [LogicalType].
54- // Used by [github.com/theory/jsonpath/registry.NewFunction] validator
55- // functions to ensure the compatibility of parameter expressions.
55+ // In other words, ft values can safely be passed to [LogicalFrom] without it
56+ // panicking. Used by [github.com/theory/jsonpath/registry.NewFunction]
57+ // validator functions to ensure the compatibility of parameter expressions.
5658func (ft FuncType ) ConvertsToLogical () bool {
5759 return ft == FuncLogical || ft == FuncNodes || ft == FuncSingularQuery
5860}
5961
60- // ConvertsToNodes returns true if ft can be converted to a [NodesType]. Used
61- // by [github.com/theory/jsonpath/registry.NewFunction] validator functions to
62- // ensure the compatibility of parameter expressions.
62+ // ConvertsToNodes returns true if ft can be converted to a [NodesType]. In
63+ // other words, ft values can safely be passed to [NodesFrom] without it
64+ // panicking. Used by [github.com/theory/jsonpath/registry.NewFunction]
65+ // validator functions to ensure the compatibility of parameter expressions.
6366func (ft FuncType ) ConvertsToNodes () bool {
6467 return ft == FuncNodes || ft == FuncSingularQuery
6568}
@@ -103,9 +106,10 @@ func Nodes(val ...any) NodesType {
103106func (NodesType ) FuncType () FuncType { return FuncNodes }
104107
105108// NodesFrom attempts to convert value to a [NodesType] and panics if it
106- // cannot. Used by [github.com/theory/jsonpath/registry.NewFunction] evaluator
107- // functions to convert types, which should have already been validated by the
108- // validator function.
109+ // cannot. Should only be used for a value whose [FuncType.ConvertsToNodes]
110+ // returns true. Use in [github.com/theory/jsonpath/registry.NewFunction]
111+ // evaluator functions to convert types, which should have already been
112+ // validated by [FuncType.ConvertsToNodes] in the validator function.
109113func NodesFrom (value JSONPathValue ) NodesType {
110114 switch v := value .(type ) {
111115 case NodesType :
@@ -163,9 +167,10 @@ func (lt LogicalType) Bool() bool { return lt == LogicalTrue }
163167func (LogicalType ) FuncType () FuncType { return FuncLogical }
164168
165169// LogicalFrom attempts to convert value to a [LogicalType] and panics if it
166- // cannot. Used by [github.com/theory/jsonpath/registry.NewFunction] evaluator
167- // functions to convert types, which should have already been validated by the
168- // validator function.
170+ // cannot. Should only be used for a value whose [FuncType.ConvertsToLogical]
171+ // returns true. Use in [github.com/theory/jsonpath/registry.NewFunction]
172+ // evaluator functions to convert types, which should have already been
173+ // validated by [FuncType.ConvertsToLogical] in the validator function.
169174func LogicalFrom (value any ) LogicalType {
170175 switch v := value .(type ) {
171176 case LogicalType :
@@ -221,10 +226,11 @@ func (vt *ValueType) String() string { return fmt.Sprintf("%v", vt.any) }
221226// FuncType returns [FuncValue]. Defined by the [JSONPathValue] interface.
222227func (* ValueType ) FuncType () FuncType { return FuncValue }
223228
224- // ValueFrom attempts to convert value to a ValueType and panics if it cannot.
225- // Used by [github.com/theory/jsonpath/registry.NewFunction] evaluator
226- // functions to convert types, which should have already been validated by the
227- // validator function.
229+ // ValueFrom attempts to convert value to a [ValueType] and panics if it
230+ // cannot. Should only be used for a value whose [FuncType.ConvertsToValue]
231+ // returns true. Use in [github.com/theory/jsonpath/registry.NewFunction]
232+ // evaluator functions to convert types, which should have already been
233+ // validated by [FuncType.ConvertsToValue] in the validator function.
228234func ValueFrom (value JSONPathValue ) * ValueType {
229235 switch v := value .(type ) {
230236 case * ValueType :
0 commit comments