On Fri, 4 Apr 2025 08:55:19 GMT, Per Minborg <pminb...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/StableValue.java line 211: >> >>> 209: * StableValue.function(CACHED_KEYS, LOG2_ORIGINAL); >>> 210: * >>> 211: * public static double log2(int a) { >> >> IMHO this example reveals a lack of compositionality of the partial >> functions we have. If the functions returned optional (to indicate "not >> defined"), then code like this would become much simpler to express: >> >> >> return LOG2_CACHED.apply(a) >> .orElse(LOG2_ORIGINAL.apply(a)); >> >> >> It's not just that this is more fluent -- this is also using the caching >> function to check whether the input is cached or not -- instead of having a >> separate check (potentially duplicating the costs). > > I agree with this observation. We should look at providing true partial > functions using for example `Optional`. Btw, I believe for now we should just "note" the issue, and move one. Let's have the javadoc reflect what the impl really does. We have good ideas on how to address this, so we can either follow up with a CSR post-integration, or we can address this in the next round of preview ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r2028541047