@@ -52,10 +52,12 @@ private Functions() {
5252 * @param clazz The class of which the input has to be an instance of.
5353 *
5454 * @return The predicate.
55+ *
56+ * @deprecated use {@link Predicates#instanceOf(java.lang.Class)}
5557 */
58+ @ Deprecated
5659 public static <T , U extends T > Predicate <T > instanceOf (@ Nonnull Class <? extends U > clazz ) {
57- Objects .requireNonNull (clazz );
58- return x -> clazz .isAssignableFrom (x .getClass ());
60+ return Predicates .instanceOf (clazz );
5961 }
6062
6163 /**
@@ -102,7 +104,7 @@ public static <T, U extends T> Function<T, U> cast(@Nonnull Class<? extends U> c
102104 * @return An {@link Optional} containing the input
103105 */
104106 public static <T , U extends T > Function <T , Optional <U >> castIfInstanceOf (@ Nonnull Class <? extends U > clazz ) {
105- Predicate <Object > filter = instanceOf (clazz );
107+ Predicate <Object > filter = Predicates . instanceOf (clazz );
106108 Function <Object , U > mapper = cast (clazz );
107109 return t -> Optional .ofNullable (t ).filter (filter ).map (mapper );
108110 }
@@ -134,24 +136,67 @@ public static <T, U> Function<T, U> constant(@Nullable U u) {
134136 return t -> u ;
135137 }
136138
139+ /**
140+ * Curries the parameter of the {@code Function} and creates a {@code Consumer}.
141+ *
142+ * @param <T> the parameter type
143+ * @param <R> the return type
144+ * @param function the function
145+ * @param t the curried parameter
146+ *
147+ * @return the curried function
148+ */
137149 public static <T , R > Supplier <R > curry (@ Nonnull Function <? super T , ? extends R > function , T t ) {
138150 Objects .requireNonNull (function );
139151 return () -> function .apply (t );
140152 }
141153
154+ /**
155+ * Curries the first parameter of the {@code BiFunction} and creates a {@code Function}.
156+ *
157+ * @param <T1> the first parameter type
158+ * @param <T2> the second parameter type
159+ * @param <R> the return type
160+ * @param bifunction the function
161+ * @param t1 the curried parameter
162+ *
163+ * @return the curried function
164+ */
142165 public static <T1 , T2 , R > Function <T2 , R > curryFirst (@ Nonnull BiFunction <T1 , T2 , R > bifunction , T1 t1 ) {
143166 Objects .requireNonNull (bifunction );
144167 return t2 -> bifunction .apply (t1 , t2 );
145168 }
146169
170+ /**
171+ * Curries the second parameter of the {@code BiFunction} and creates a {@code Function}.
172+ *
173+ * @param <T1> the first parameter type
174+ * @param <T2> the second parameter type
175+ * @param <R> the return type
176+ * @param bifunction the function
177+ * @param t2 the curried parameter
178+ *
179+ * @return the curried function
180+ */
147181 public static <T1 , T2 , R > Function <T1 , R > currySecond (@ Nonnull BiFunction <T1 , T2 , R > bifunction , T2 t2 ) {
148182 Objects .requireNonNull (bifunction );
149183 return t1 -> bifunction .apply (t1 , t2 );
150184 }
151185
186+ /**
187+ * Reverses the parameter order of the BiConsumer
188+ *
189+ * @param <A> the first parameter type
190+ * @param <B> the second parameter type
191+ * @param consumer the consumer
192+ *
193+ * @return the consumer with switched parameters
194+ *
195+ * @deprecated use {@link Consumers#reverse(java.util.function.BiConsumer)}
196+ */
197+ @ Deprecated
152198 public static <A , B > BiConsumer <B , A > reverse (@ Nonnull BiConsumer <A , B > consumer ) {
153- Objects .requireNonNull (consumer );
154- return (a , b ) -> consumer .accept (b , a );
199+ return Consumers .reverse (consumer );
155200 }
156201
157202 public static <T > BinaryOperator <T > mergeLeft (@ Nonnull BiConsumer <T , T > merger ) {
@@ -203,7 +248,7 @@ public static <K, V> Function<Map<K, V>, Stream<K>> keyStreamWhereValues(Predica
203248 *
204249 * @return A function that applies the consumer and returns it's input.
205250 */
206- public static <T > Function <T , T > mutate (Consumer <? super T > action ) {
251+ public static <T > Function <T , T > mutate (@ Nonnull Consumer <? super T > action ) {
207252 Objects .requireNonNull (action );
208253 return (T t ) -> {
209254 action .accept (t );
@@ -222,7 +267,8 @@ public static <T> Function<T, T> mutate(Consumer<? super T> action) {
222267 *
223268 * @return the wrapped function.
224269 */
225- public static <S , T , X extends Exception > Function <S , T > errorWrapper (ThrowingFunction <S , T , X > fun ) {
270+ public static <S , T , X extends Exception > Function <S , T > errorWrapper (@ Nonnull ThrowingFunction <S , T , X > fun ) {
271+ Objects .requireNonNull (fun );
226272 return s -> {
227273 try {
228274 return fun .apply (s );
0 commit comments