@@ -42,15 +42,7 @@ public int hashCode() {
4242 * @return A new product-2 with the elements swapped.
4343 */
4444 public final P2 <B , A > swap () {
45- return new P2 <B , A >() {
46- public B _1 () {
47- return P2 .this ._2 ();
48- }
49-
50- public A _2 () {
51- return P2 .this ._1 ();
52- }
53- };
45+ return P .lazy (() -> P2 .this ._2 (), () -> P2 .this ._1 ());
5446 }
5547
5648 /**
@@ -60,15 +52,8 @@ public A _2() {
6052 * @return A product with the given function applied.
6153 */
6254 public final <X > P2 <X , B > map1 (final F <A , X > f ) {
63- return new P2 <X , B >() {
64- public X _1 () {
65- return f .f (P2 .this ._1 ());
66- }
67-
68- public B _2 () {
69- return P2 .this ._2 ();
70- }
71- };
55+ P2 <A , B > self = this ;
56+ return P .lazy (() -> f .f (self ._1 ()), () -> self ._2 ());
7257 }
7358
7459 /**
@@ -78,15 +63,7 @@ public B _2() {
7863 * @return A product with the given function applied.
7964 */
8065 public final <X > P2 <A , X > map2 (final F <B , X > f ) {
81- return new P2 <A , X >() {
82- public A _1 () {
83- return P2 .this ._1 ();
84- }
85-
86- public X _2 () {
87- return f .f (P2 .this ._2 ());
88- }
89- };
66+ return P .lazy (() -> P2 .this ._1 (), () -> f .f (P2 .this ._2 ()));
9067 }
9168
9269
@@ -112,16 +89,8 @@ public final <C, D> P2<C, D> split(final F<A, C> f, final F<B, D> g) {
11289 * and with the second element intact.
11390 */
11491 public final <C > P2 <C , B > cobind (final F <P2 <A , B >, C > k ) {
115- return new P2 <C , B >() {
116-
117- public C _1 () {
118- return k .f (P2 .this );
119- }
120-
121- public B _2 () {
122- return P2 .this ._2 ();
123- }
124- };
92+ P2 <A , B > self = this ;
93+ return P .lazy (() -> k .f (self ), () -> self ._2 ());
12594 }
12695
12796 /**
0 commit comments