-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPair.java
More file actions
36 lines (27 loc) · 790 Bytes
/
Pair.java
File metadata and controls
36 lines (27 loc) · 790 Bytes
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
package org.lambdaql;
import org.lambdaql.utils.Consumer2;
import org.lambdaql.utils.Function2;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
public record Pair<T1, T2>(T1 t1, T2 t2) implements Tuple {
public static <T1, T2> Pair<T1, T2> of(T1 t1, T2 t2) {
return new Pair<>(t1, t2);
}
public T1 component1() { return t1; }
public T2 component2() { return t2; }
@Override
public List<Object> toList() {
return List.of(t1, t2);
}
@Override
public int arity() {
return 2;
}
public <R> R map(BiFunction<T1, T2, R> mapper) {
return mapper.apply(t1, t2);
}
public void forEach(BiConsumer<T1, T2> action) {
action.accept(t1, t2);
}
}