garydgregory commented on code in PR #1215: URL: https://github.com/apache/commons-lang/pull/1215#discussion_r1611600584
########## src/main/java/org/apache/commons/lang3/function/Consumers.java: ########## @@ -46,4 +46,17 @@ private Consumers() { // No instances. } + /** + * Applies the given {@link Consumer} action to the object if the object is not null. If the object is null, it does + * nothing. + * + * @param object the object to be consumed. + * @param consumer the consumer to consume. + * @param <T> the type of the argument the consumer accepts. + */ + public static <T> void acceptIfNotNull(final T object, final Consumer<T> consumer) { Review Comment: I disagree that the API is noop if the input to the functional object is null. A lot of APIs accept null as valid input, for example to reset a value to its default. ########## 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: I disagree that the API is noop if the input to the functional object is null. A lot of APIs accept null as valid input, for example to reset a value to its default. -- 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: issues-unsubscr...@commons.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org