<div dir="ltr"><br><div>Found this answer from smarks:</div><div><br></div><div><a href="https://stackoverflow.com/questions/26549659/built-in-java-8-predicate-that-always-returns-true/26553481#26553481">https://stackoverflow.com/questions/26549659/built-in-java-8-predicate-that-always-returns-true/26553481#26553481</a><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Certainly there is some value in something that has a name vs. a written-out lambda, but this value is quite small. We expect that people will learn how to read and write x -> true and () -> { } and that their usage will become idiomatic. Even the value of Function.identity() over x -> x is questionable.</blockquote><div><br></div><div>Makes sense. And where would we stop..?</div><div><br></div><div>EIrik.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 20, 2023 at 7:24 PM Eirik Bjørsnøs <<a href="mailto:eirbjo@gmail.com">eirbjo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<br><div><br></div><div>So I found myself writing some code which sets up a j.u.s.Stream processing pipeline where the stream can optionally be traced/logged via a peeking Consumer.</div><div><br></div><div>The default should be not to trace, in which case I initially set the Consumer to null. But then I need to check that trace != null when setting up the stream. This felt awkward..</div><div><br></div><div>Since related code was using Function.identity() as a "no mapping configured" default, I went looking for Consumer.empty(), only to learn that no such thing exists.</div><div><br></div><div>I can of course just do () -> {}, but I think Consumer.empty() conveys the purpose a bit more clearly..</div><div><br></div><div><div>Is there some thought behind this not existing? Would it be worth adding?</div><div><br></div></div><div><br></div><div>/**<br> * Returns a consumer which performs no operation on its input argument<br> *<br> * @param <T> the type of the input argument<br> * @return a Consumer which performs no operation on its input argument<br> */<br>static <T> Consumer<T> empty() {<br>    return t -> {};<br>}<br></div></div>
</blockquote></div>