@@ -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,11 @@ 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 [FuncType] objects from [FuncExprArg]
110+ // ResultType() and [JSONPathValue] FuncType() that return true from
111+ // [FuncType.ConvertsToNodes]. Use in [github.com/theory/jsonpath/registry.NewFunction]
112+ // evaluator functions to convert types, which should have already been
113+ // validated by the validator function.
109114func NodesFrom (value JSONPathValue ) NodesType {
110115 switch v := value .(type ) {
111116 case NodesType :
@@ -163,9 +168,11 @@ func (lt LogicalType) Bool() bool { return lt == LogicalTrue }
163168func (LogicalType ) FuncType () FuncType { return FuncLogical }
164169
165170// 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.
171+ // cannot. Should only be used for [FuncType] objects from [FuncExprArg]
172+ // ResultType() and [JSONPathValue] FuncType() that return true from
173+ // [FuncType.ConvertsToLogical]. Use in [github.com/theory/jsonpath/registry.NewFunction]
174+ // evaluator functions to convert types, which should have already been
175+ // validated by the validator function.
169176func LogicalFrom (value any ) LogicalType {
170177 switch v := value .(type ) {
171178 case LogicalType :
@@ -222,9 +229,11 @@ func (vt *ValueType) String() string { return fmt.Sprintf("%v", vt.any) }
222229func (* ValueType ) FuncType () FuncType { return FuncValue }
223230
224231// 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.
232+ // Should only be used for [FuncType] objects from [FuncExprArg] ResultType()
233+ // and [JSONPathValue] FuncType() that return true from
234+ // [FuncType.ConvertsToValue]. Use in [github.com/theory/jsonpath/registry.NewFunction]
235+ // evaluator functions to convert types, which should have already been
236+ // validated by the validator function.
228237func ValueFrom (value JSONPathValue ) * ValueType {
229238 switch v := value .(type ) {
230239 case * ValueType :
0 commit comments