imbf commented on code in PR #1215:
URL: https://github.com/apache/commons-lang/pull/1215#discussion_r1615359136
##########
src/main/java/org/apache/commons/lang3/function/Functions.java:
##########
@@ -41,4 +41,20 @@ public static <T, R> Function<T, R> function(final
Function<T, R> function) {
private Functions() {
// no instances needed.
}
+
+ /**
+ * Applies the {@link Function} on the object if the object and the
function are not {@code null}. Otherwise, do
+ * nothing.
+ *
+ * @param object the object to apply the function.
+ * @param function the function to apply.
+ * @param <T> the type of the argument the function applies.
+ * @param <R> the type of the result the function returns.
+ * @return the value the function returns if the object and the function
are not {@code null}; {@code null}
+ * otherwise.
+ * @since 3.15.0
+ */
+ public static <T, R> R applyIfNotNull(final T object, final Function<T, R>
function) {
+ return object != null && function != null ? function.apply(object) :
null;
Review Comment:
That sounds great. null can also be a valid input.
Thank you.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]