<div dir="ltr"><div class="gmail_default" style="font-family:monospace">Hello Magnus,</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Thank you for closing my bug! Terribly sorry to ask another favor, but could you link the following link for traceability in the JBS submission?</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace"><a href="https://mail.openjdk.org/pipermail/amber-dev/2024-January/008488.html">https://mail.openjdk.org/pipermail/amber-dev/2024-January/008488.html</a></div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Thank you again for the time and help!</div><div class="gmail_default" style="font-family:monospace">David Alayachew<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 1, 2024 at 1:26 AM David Alayachew <<a href="mailto:davidalayachew@gmail.com">davidalayachew@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"><div class="gmail_default" style="font-family:monospace">Hello all,</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">After reading through Brian Goetz's "Effect cases on Switch" (specifically, the "Other switch tricks" section), I have decided to not implement this feature after all. The fact is, switch expressions, especially with "when-clauses", does a better job of clarifying intent than this feature does. Sure, there is slightly more verbosity, but the intent of this feature was never to minimize the character count, it was to increase clarity. And as is, switch expressions with when clauses accomplish that better.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Here is a link to the subsection of the abovementioned article -- <a href="https://inside.java/2023/12/15/switch-case-effect/#other-switch-tricks" target="_blank">https://inside.java/2023/12/15/switch-case-effect/#other-switch-tricks</a></div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Could someone help me close this on JBS? Or should it just not be closed at all? </div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Here is a link to the JBS -- <a href="https://bugs.openjdk.org/browse/JDK-8319802" target="_blank">https://bugs.openjdk.org/browse/JDK-8319802</a></div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Thank you for your time and help!</div><div class="gmail_default" style="font-family:monospace">David Alayachew<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 9, 2023 at 1:19 AM David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank">davidalayachew@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"><div class="gmail_default" style="font-family:monospace">Oh, I will also add a specialized version of this method to java.util.function.UnaryOperator. That is because UnaryOperator is a subinterface of Function. Function goes T -> R, but UnaryOperator just goes T -> T. We do not want UnaryOperator to have the T -> R static function included due to inheritance, so it will get its own version that has the same method name and parameters, but the type parameters will be different.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Here is another mockup - this time for UnaryOperator2's version of the same method.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">


interface UnaryOperator2<T> extends Function2<T,T>, UnaryOperator<T><br>
> {<br>


<br>
>     public static <T> UnaryOperator2<T> ternaryApply<br>
>     (<br>
>         Predicate<? super T> test,<br>
>         Function<? super T, ? extends T> trueFunction,<br>
>         Function<? super T, ? extends T> falseFunction<br>
>     )<br>
>     {</div><div class="gmail_default" style="font-family:monospace">> </div><div class="gmail_default" style="font-family:monospace">>         return<br>
>             (T input) -><br>
>                 test.test(input)<br>
>                     ? trueFunction.apply(input)<br>
>                     : falseFunction.apply(input)<br>
>                     ;<br>


<br>
>     }<br>


<br>> }<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 9, 2023 at 12:12 AM David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank">davidalayachew@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"><div class="gmail_default" style="font-family:monospace">It has been a month since I sent this proposal. Since no one has told me that this is a terrible idea, I will submit this as an enhancement to JBS, and once the ticket is made, start work on creating a pull request.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 3, 2023 at 3:13 AM David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank">davidalayachew@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"><div class="gmail_default" style="font-family:monospace">Whoops, bad import.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Please replace the following line with the one after it.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">> import java.util.function.Function;</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">> import java.util.function.*;<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 3, 2023 at 3:09 AM David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank">davidalayachew@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"><div style="font-family:monospace" class="gmail_default">Hello all,<br><br>I have an idea that I want to run by you all -- a new method on java.util.function.Function to capture ternary operations.<br><br>Here is a mockup of what I wanted to do.<br><br>> <br>> import java.util.function.Function;<br>> <br>> @FunctionalInterface<br>> public interface Function2<I, O> extends Function<I, O><br>> {<br>> <br>>    public static <I, O> Function<I, O> ternary<br>>    (<br>>        Predicate<I> test,<br>>        Function<I, O> trueOutput,<br>>        Function<I, O> falseOutput<br>>    )<br>>    {<br>>    <br>>       return<br>>           (I input) -><br>>               test.test(input)<br>>               ? trueOutput.apply(input)<br>>               : falseOutput.apply(input)<br>>               ;<br>>    <br>>    }<br>> <br>> }<br>> <br><br>I think this is useful for a few reasons.<br><br> * This composes, just like the ternary operator itself.<br> <br> * It pairs well with Function.identity() and method references to clearly (but concisely) communicate intent.<br> <br> * Ternary operations are common, so this will find great use by developers of all sorts.<br><br>There is at least one part I don't quite like about this design - what if one (or both!) of your outputs is not a functional transformation of the input?<br><br>For example, String username = id.isBlank() ? "UNKNOWN" : lookup(id);<br><br>Obviously, this is easy to work around - simply ignore the input of the function. But you lose clarity and simplicity that way. I would put a note in the javadoc that says that this method should only be used in instances where both outputs are a functional transformation of the input. That way, intent is clarified. But if we go that route, maybe this function should get a better name to capture that? testThenApply? ternaryTransform? ternaryApply?<br><br>Thank you for your time and help!<br>David Alayachew<br></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>