1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package bjc.utils.data;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
/**
* An interface representing a pair of values
*
* @author ben
*
* @param <L>
* The type stored in the left side of the pair
* @param <R>
* The type stored in the right side of the pair
*/
public interface IPair<L, R> {
/**
* Create a new pair by applying the given functions to the left/right.
* Does not change the internal contents of this pair.
*
* @param <L2>
* The new left type of the pair
* @param <R2>
* The new right type of the pair
*
* @param leftTransformer
* The function to apply to the left value.
* @param rightTransformer
* The function to apply to the right value.
* @return A new pair containing the two modified values.
*/
public <L2, R2> IPair<L2, R2> apply(Function<L, L2> leftTransformer,
Function<R, R2> rightTransformer);
/**
* Apply a function to the two internal values that returns a new pair.
*
* Is a monadic bind.
*
* @param <L2>
* The new left pair type
* @param <R2>
* The new right pair type
* @param binder
* The function to use as a bind
* @return The new pair
*/
public <L2, R2> IPair<L2, R2>
bind(BiFunction<L, R, IPair<L2, R2>> binder);
/**
* Execute an action with the values of this pair. Has no effect on the
* internal contents
*
* @param action
* The action to execute on the values
*/
public void doWith(BiConsumer<L, R> action);
/**
* Collapse this pair to a single value. Does not change the internal
* contents of this pair.
*
* @param <E>
* The resulting type after merging
*
* @param merger
* The function to use to collapse the pair.
* @return The collapsed value.
*/
public <E> E merge(BiFunction<L, R, E> merger);
}
|