Pair implements Serializable { public static <A, B, C> Function<Pair<A, B>, Pair<A, C>> mapB(Function<B, C> f) { return p -> Pair.of(p.a, f.apply(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 mapB() { Pair<Integer, Character> expectedResult = Pair.of(1, 'a'); Optional<Pair<Integer, String>> boxedPair = Optional.of(Pair.of(1, "a")); Pair<Integer, Character> result = boxedPair.map(Pair.mapB(b -> b.charAt(0))).get(); assertEquals(expectedResult, result); }