introductionToProgramming/week12/Pair.java
Daniel Bulant 125e24b3b8 week12
2025-11-16 13:56:58 +01:00

32 lines
No EOL
717 B
Java

package week12;
class Pair<A, B> {
final A first;
final B second;
Pair(A first, B second) {
this.first = first;
this.second = second;
}
// these getters doesn't seem to be needed, stdlib doesn't usually use getters for final values and instead just makes them public to be used directly
public A getFirst() {
return first;
}
public B getSecond() {
return second;
}
public Pair<B, A> swap() {
return new Pair<B, A>(second, first);
}
public<C> Pair<C, B> withFst(C first) {
return new Pair<C, B>(first, second);
}
public<C> Pair<A, C> withSnd(C second) {
return new Pair<A, C>(first, second);
}
}