|
1 | 1 | package com.jnape.palatable.lambda.functions.builtin.fn2; |
2 | 2 |
|
3 | | -import com.jnape.palatable.lambda.adt.product.Product2; |
4 | 3 | import com.jnape.palatable.lambda.functions.Fn1; |
5 | 4 | import com.jnape.palatable.lambda.functions.Fn2; |
6 | 5 |
|
| 6 | +import java.util.Map; |
7 | 7 | import java.util.function.BiFunction; |
8 | 8 |
|
9 | 9 | /** |
10 | | - * Given a <code>{@link BiFunction}<A, B, C></code> and a <code>{@link Product2}<A, B></code>, destructure |
11 | | - * the product and apply the slots as arguments to the function, returning the result. |
| 10 | + * Given a <code>{@link BiFunction}<A, B, C></code> and a <code>{@link Map.Entry}<A, B></code>, destructure |
| 11 | + * the entry and apply the key and value as arguments to the function, returning the result. |
12 | 12 | * |
13 | 13 | * @param <A> the first argument type |
14 | 14 | * @param <B> the second argument type |
15 | 15 | * @param <C> the result type |
16 | 16 | */ |
17 | | -public final class Into<A, B, C> implements Fn2<BiFunction<? super A, ? super B, ? extends C>, Product2<A, B>, C> { |
| 17 | +public final class Into<A, B, C> implements Fn2<BiFunction<? super A, ? super B, ? extends C>, Map.Entry<A, B>, C> { |
18 | 18 |
|
19 | 19 | private static final Into INSTANCE = new Into(); |
20 | 20 |
|
21 | 21 | private Into() { |
22 | 22 | } |
23 | 23 |
|
24 | 24 | @Override |
25 | | - public C apply(BiFunction<? super A, ? super B, ? extends C> fn, Product2<A, B> product) { |
26 | | - return product.into(fn); |
| 25 | + public C apply(BiFunction<? super A, ? super B, ? extends C> fn, Map.Entry<A, B> entry) { |
| 26 | + return fn.apply(entry.getKey(), entry.getValue()); |
27 | 27 | } |
28 | 28 |
|
29 | 29 | @SuppressWarnings("unchecked") |
30 | 30 | public static <A, B, C> Into<A, B, C> into() { |
31 | 31 | return INSTANCE; |
32 | 32 | } |
33 | 33 |
|
34 | | - public static <A, B, C> Fn1<Product2<A, B>, C> into( |
| 34 | + public static <A, B, C> Fn1<Map.Entry<A, B>, C> into( |
35 | 35 | BiFunction<? super A, ? super B, ? extends C> fn) { |
36 | 36 | return Into.<A, B, C>into().apply(fn); |
37 | 37 | } |
38 | 38 |
|
39 | 39 | public static <A, B, C> C into(BiFunction<? super A, ? super B, ? extends C> fn, |
40 | | - Product2<A, B> product) { |
41 | | - return Into.<A, B, C>into(fn).apply(product); |
| 40 | + Map.Entry<A, B> entry) { |
| 41 | + return Into.<A, B, C>into(fn).apply(entry); |
42 | 42 | } |
43 | 43 | } |
0 commit comments