Pair implements Serializable { public static <A, B, C> Function<Pair<A, B>, Pair<C, B>> mapA(Function<A, C> f) { return p -> Pair.of(f.apply(p.a), p.b); } private  Pair(A a, B b); static Pair<A, B> of(A a, B b); static Pair<A, B> fromEntry(Map.Entry<A, B> entry); static Function<Pair<A, B>, C> map(BiFunction<A, B, C> f); static Function<Pair<A, B>, Pair<C, B>> mapA(Function<A, C> f); static Function<Pair<A, B>, Pair<A, C>> mapB(Function<B, C> f); A a(); B b(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); final A a; final B b; }
@Test public void mapA() { Pair<Double, String> expectedResult = Pair.of(2.5, "a"); Optional<Pair<Integer, String>> boxedPair = Optional.of(Pair.of(1, "a")); Pair<Double, String> result = boxedPair.map(Pair.mapA(a -> a + 1.5)).get(); assertEquals(expectedResult, result); }