[java-support] branch main updated: Add Function to BiFunction adapters.

Scott Cantor cantor.2 at osu.edu
Mon Jan 24 16:00:41 UTC 2022


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-support.

View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=4f3db6f0357ef7d9bc7c9d3a911933879ad73534

The following commit(s) were added to refs/heads/main by this push:
     new 4f3db6f  Add Function to BiFunction adapters.
4f3db6f is described below

commit 4f3db6f0357ef7d9bc7c9d3a911933879ad73534
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Jan 24 10:59:45 2022 -0500

    Add Function to BiFunction adapters.
---
 .../java/support/logic/BiFunctionSupport.java      | 30 ++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/main/java/net/shibboleth/utilities/java/support/logic/BiFunctionSupport.java b/src/main/java/net/shibboleth/utilities/java/support/logic/BiFunctionSupport.java
index 33b7fa1..a5aecae 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/logic/BiFunctionSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/logic/BiFunctionSupport.java
@@ -88,4 +88,34 @@ public final class BiFunctionSupport {
         return predicate::test;
     }
     
+    /**
+     * Adapts a {@link Function} into a {BiFunction} that ignores the second argument.
+     * 
+     * @param <A> input type of function
+     * @param <B> ignored argument type
+     * @param <C> return type
+     * @param function the function to apply
+     * 
+     * @return the adapted object
+     */
+    @Nonnull public static <A,B,C> BiFunction<A,B,C> forFunctionOfFirstArg(
+            @Nonnull @ParameterName(name="function") final Function<? super A,? extends C> function) {
+        return (a,b) -> function.apply(a);
+    }
+
+    /**
+     * Adapts a {@link Function} into a {BiFunction} that ignores the first argument.
+     * 
+     * @param <A> ignored argument type
+     * @param <B> input type of function
+     * @param <C> return type
+     * @param function the function to apply
+     * 
+     * @return the adapted object
+     */
+    @Nonnull public static <A,B,C> BiFunction<A,B,C> forFunctionOfSecondArg(
+            @Nonnull @ParameterName(name="function") final Function<? super B,? extends C> function) {
+        return (a,b) -> function.apply(b);
+    }
+
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list