@@ -58,6 +58,42 @@ public static DefaultFunctionResolver define(FunctionName functionName, List<
5858 return builder .build ();
5959 }
6060
61+
62+ /**
63+ * Implementation of no args function that uses FunctionProperties.
64+ *
65+ * @param function {@link ExprValue} based no args function.
66+ * @param returnType function return type.
67+ * @return no args function implementation.
68+ */
69+ public static SerializableFunction <FunctionName , Pair <FunctionSignature , FunctionBuilder >>
70+ implWithProperties (SerializableFunction <FunctionProperties , ExprValue > function ,
71+ ExprType returnType ) {
72+ return functionName -> {
73+ FunctionSignature functionSignature =
74+ new FunctionSignature (functionName , Collections .emptyList ());
75+ FunctionBuilder functionBuilder =
76+ (functionProperties , arguments ) ->
77+ new FunctionExpression (functionName , Collections .emptyList ()) {
78+ @ Override
79+ public ExprValue valueOf (Environment <Expression , ExprValue > valueEnv ) {
80+ return function .apply (functionProperties );
81+ }
82+
83+ @ Override
84+ public ExprType type () {
85+ return returnType ;
86+ }
87+
88+ @ Override
89+ public String toString () {
90+ return String .format ("%s()" , functionName );
91+ }
92+ };
93+ return Pair .of (functionSignature , functionBuilder );
94+ };
95+ }
96+
6197 /**
6298 * Implementation of a function that takes one argument, returns a value, and
6399 * requires FunctionProperties to complete.
@@ -101,41 +137,6 @@ public String toString() {
101137 };
102138 }
103139
104- /**
105- * Implementation of no args function that uses FunctionProperties.
106- *
107- * @param function {@link ExprValue} based no args function.
108- * @param returnType function return type.
109- * @return no args function implementation.
110- */
111- public static SerializableFunction <FunctionName , Pair <FunctionSignature , FunctionBuilder >>
112- implWithProperties (SerializableFunction <FunctionProperties , ExprValue > function ,
113- ExprType returnType ) {
114- return functionName -> {
115- FunctionSignature functionSignature =
116- new FunctionSignature (functionName , Collections .emptyList ());
117- FunctionBuilder functionBuilder =
118- (functionProperties , arguments ) ->
119- new FunctionExpression (functionName , Collections .emptyList ()) {
120- @ Override
121- public ExprValue valueOf (Environment <Expression , ExprValue > valueEnv ) {
122- return function .apply (functionProperties );
123- }
124-
125- @ Override
126- public ExprType type () {
127- return returnType ;
128- }
129-
130- @ Override
131- public String toString () {
132- return String .format ("%s()" , functionName );
133- }
134- };
135- return Pair .of (functionSignature , functionBuilder );
136- };
137- }
138-
139140 /**
140141 * No Arg Function Implementation.
141142 *
@@ -298,4 +299,22 @@ public SerializableTriFunction<ExprValue, ExprValue, ExprValue, ExprValue> nullM
298299 }
299300 };
300301 }
302+
303+ /**
304+ * Wrapper the unary ExprValue function that is aware of FunctionProperties,
305+ * with default NULL and MISSING handling.
306+ */
307+ public static SerializableBiFunction <FunctionProperties , ExprValue , ExprValue >
308+ nullMissingHandlingWithProperties (
309+ SerializableBiFunction <FunctionProperties , ExprValue , ExprValue > implementation ) {
310+ return (functionProperties , v1 ) -> {
311+ if (v1 .isMissing ()) {
312+ return ExprValueUtils .missingValue ();
313+ } else if (v1 .isNull ()) {
314+ return ExprValueUtils .nullValue ();
315+ } else {
316+ return implementation .apply (functionProperties , v1 );
317+ }
318+ };
319+ }
301320}
0 commit comments