Skip to content

Commit 22c87b6

Browse files
committed
Converted fj.data.vector to use lambdas
1 parent 902825b commit 22c87b6

7 files changed

Lines changed: 45 additions & 225 deletions

File tree

core/src/main/java/fj/data/vector/V2.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ public A _2() {
5858
* @return a function that gets the first element of a given vector.
5959
*/
6060
public static <A> F<V2<A>, A> __1() {
61-
return new F<V2<A>, A>() {
62-
public A f(final V2<A> v) {
63-
return v._1();
64-
}
65-
};
61+
return v -> v._1();
6662
}
6763

6864
/**
@@ -71,11 +67,7 @@ public A f(final V2<A> v) {
7167
* @return a function that gets the second element of a given vector.
7268
*/
7369
public static <A> F<V2<A>, A> __2() {
74-
return new F<V2<A>, A>() {
75-
public A f(final V2<A> v) {
76-
return v._2();
77-
}
78-
};
70+
return v -> v._2();
7971
}
8072

8173
/**
@@ -124,11 +116,7 @@ public Stream<A> _1() {
124116
* @return a function that transforms a vector-2 to a stream of its elements.
125117
*/
126118
public static <A> F<V2<A>, Stream<A>> toStream_() {
127-
return new F<V2<A>, Stream<A>>() {
128-
public Stream<A> f(final V2<A> v) {
129-
return v.toStream();
130-
}
131-
};
119+
return v -> v.toStream();
132120
}
133121

134122
/**
@@ -137,11 +125,7 @@ public Stream<A> f(final V2<A> v) {
137125
* @return a function that transforms a vector-2 to the equivalent product-2.
138126
*/
139127
public static <A> F<V2<A>, P2<A, A>> p_() {
140-
return new F<V2<A>, P2<A, A>>() {
141-
public P2<A, A> f(final V2<A> v) {
142-
return v.p();
143-
}
144-
};
128+
return v -> v.p();
145129
}
146130

147131
/**

core/src/main/java/fj/data/vector/V3.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ public <B> V3<B> map(final F<A, B> f) {
227227
* @return a function that transforms a vector-3 to a stream of its elements.
228228
*/
229229
public static <A> F<V3<A>, Stream<A>> toStream_() {
230-
return new F<V3<A>, Stream<A>>() {
231-
public Stream<A> f(final V3<A> v) {
232-
return v.toStream();
233-
}
234-
};
230+
return v -> v.toStream();
235231
}
236232

237233
/**
@@ -240,11 +236,7 @@ public Stream<A> f(final V3<A> v) {
240236
* @return a function that transforms a vector-3 to the equivalent product-3.
241237
*/
242238
public static <A> F<V3<A>, P3<A, A, A>> p_() {
243-
return new F<V3<A>, P3<A, A, A>>() {
244-
public P3<A, A, A> f(final V3<A> v) {
245-
return v.p();
246-
}
247-
};
239+
return v -> v.p();
248240
}
249241

250242
/**
@@ -253,11 +245,7 @@ public P3<A, A, A> f(final V3<A> v) {
253245
* @return a function that gets the first element of a given vector.
254246
*/
255247
public static <A> F<V3<A>, A> __1() {
256-
return new F<V3<A>, A>() {
257-
public A f(final V3<A> v) {
258-
return v._1();
259-
}
260-
};
248+
return v -> v._1();
261249
}
262250

263251
/**
@@ -266,11 +254,7 @@ public A f(final V3<A> v) {
266254
* @return a function that gets the second element of a given vector.
267255
*/
268256
public static <A> F<V3<A>, A> __2() {
269-
return new F<V3<A>, A>() {
270-
public A f(final V3<A> v) {
271-
return v._2();
272-
}
273-
};
257+
return v -> v._2();
274258
}
275259

276260
/**
@@ -279,11 +263,7 @@ public A f(final V3<A> v) {
279263
* @return a function that gets the third element of a given vector.
280264
*/
281265
public static <A> F<V3<A>, A> __3() {
282-
return new F<V3<A>, A>() {
283-
public A f(final V3<A> v) {
284-
return v._3();
285-
}
286-
};
266+
return v -> v._3();
287267
}
288268

289269
}

core/src/main/java/fj/data/vector/V4.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,7 @@ public V4<V2<A>> vzip(final V4<A> bs) {
244244
* @return a function that transforms a vector-4 to a stream of its elements.
245245
*/
246246
public static <A> F<V4<A>, Stream<A>> toStream_() {
247-
return new F<V4<A>, Stream<A>>() {
248-
public Stream<A> f(final V4<A> v) {
249-
return v.toStream();
250-
}
251-
};
247+
return v -> v.toStream();
252248
}
253249

254250
/**
@@ -257,11 +253,7 @@ public Stream<A> f(final V4<A> v) {
257253
* @return a function that transforms a vector-4 to the equivalent product-4.
258254
*/
259255
public static <A> F<V4<A>, P4<A, A, A, A>> p_() {
260-
return new F<V4<A>, P4<A, A, A, A>>() {
261-
public P4<A, A, A, A> f(final V4<A> v) {
262-
return v.p();
263-
}
264-
};
256+
return v -> v.p();
265257
}
266258

267259
/**
@@ -270,11 +262,7 @@ public P4<A, A, A, A> f(final V4<A> v) {
270262
* @return a function that gets the first element of a given vector.
271263
*/
272264
public static <A> F<V4<A>, A> __1() {
273-
return new F<V4<A>, A>() {
274-
public A f(final V4<A> v) {
275-
return v._1();
276-
}
277-
};
265+
return v -> v._1();
278266
}
279267

280268
/**
@@ -283,11 +271,7 @@ public A f(final V4<A> v) {
283271
* @return a function that gets the second element of a given vector.
284272
*/
285273
public static <A> F<V4<A>, A> __2() {
286-
return new F<V4<A>, A>() {
287-
public A f(final V4<A> v) {
288-
return v._2();
289-
}
290-
};
274+
return v -> v._2();
291275
}
292276

293277
/**
@@ -296,11 +280,7 @@ public A f(final V4<A> v) {
296280
* @return a function that gets the third element of a given vector.
297281
*/
298282
public static <A> F<V4<A>, A> __3() {
299-
return new F<V4<A>, A>() {
300-
public A f(final V4<A> v) {
301-
return v._3();
302-
}
303-
};
283+
return v -> v._3();
304284
}
305285

306286
/**

core/src/main/java/fj/data/vector/V5.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,7 @@ public P5<A, A, A, A, A> f(final V5<A> v) {
287287
* @return a function that gets the first element of a given vector.
288288
*/
289289
public static <A> F<V5<A>, A> __1() {
290-
return new F<V5<A>, A>() {
291-
public A f(final V5<A> v) {
292-
return v._1();
293-
}
294-
};
290+
return v -> v._1();
295291
}
296292

297293
/**
@@ -300,11 +296,7 @@ public A f(final V5<A> v) {
300296
* @return a function that gets the second element of a given vector.
301297
*/
302298
public static <A> F<V5<A>, A> __2() {
303-
return new F<V5<A>, A>() {
304-
public A f(final V5<A> v) {
305-
return v._2();
306-
}
307-
};
299+
return v -> v._2();
308300
}
309301

310302
/**
@@ -326,11 +318,7 @@ public A f(final V5<A> v) {
326318
* @return a function that gets the fourth element of a given vector.
327319
*/
328320
public static <A> F<V5<A>, A> __4() {
329-
return new F<V5<A>, A>() {
330-
public A f(final V5<A> v) {
331-
return v._4();
332-
}
333-
};
321+
return v -> v._4();
334322
}
335323

336324
/**
@@ -339,10 +327,6 @@ public A f(final V5<A> v) {
339327
* @return a function that gets the fifth element of a given vector.
340328
*/
341329
public static <A> F<V5<A>, A> __5() {
342-
return new F<V5<A>, A>() {
343-
public A f(final V5<A> v) {
344-
return v._5();
345-
}
346-
};
330+
return v -> v._5();
347331
}
348332
}

core/src/main/java/fj/data/vector/V6.java

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,7 @@ public V6<V2<A>> vzip(final V6<A> bs) {
278278
* @return a function that transforms a vector-6 to a stream of its elements.
279279
*/
280280
public static <A> F<V6<A>, Stream<A>> toStream_() {
281-
return new F<V6<A>, Stream<A>>() {
282-
public Stream<A> f(final V6<A> v) {
283-
return v.toStream();
284-
}
285-
};
281+
return v -> v.toStream();
286282
}
287283

288284
/**
@@ -291,11 +287,7 @@ public Stream<A> f(final V6<A> v) {
291287
* @return a function that transforms a vector-6 to the equivalent product-6.
292288
*/
293289
public static <A> F<V6<A>, P6<A, A, A, A, A, A>> p_() {
294-
return new F<V6<A>, P6<A, A, A, A, A, A>>() {
295-
public P6<A, A, A, A, A, A> f(final V6<A> v) {
296-
return v.p();
297-
}
298-
};
290+
return v -> v.p();
299291
}
300292

301293
/**
@@ -304,11 +296,7 @@ public P6<A, A, A, A, A, A> f(final V6<A> v) {
304296
* @return a function that gets the first element of a given vector.
305297
*/
306298
public static <A> F<V6<A>, A> __1() {
307-
return new F<V6<A>, A>() {
308-
public A f(final V6<A> v) {
309-
return v._1();
310-
}
311-
};
299+
return v -> v._1();
312300
}
313301

314302
/**
@@ -317,11 +305,7 @@ public A f(final V6<A> v) {
317305
* @return a function that gets the second element of a given vector.
318306
*/
319307
public static <A> F<V6<A>, A> __2() {
320-
return new F<V6<A>, A>() {
321-
public A f(final V6<A> v) {
322-
return v._2();
323-
}
324-
};
308+
return v -> v._2();
325309
}
326310

327311
/**
@@ -330,11 +314,7 @@ public A f(final V6<A> v) {
330314
* @return a function that gets the third element of a given vector.
331315
*/
332316
public static <A> F<V6<A>, A> __3() {
333-
return new F<V6<A>, A>() {
334-
public A f(final V6<A> v) {
335-
return v._3();
336-
}
337-
};
317+
return v -> v._3();
338318
}
339319

340320
/**
@@ -343,11 +323,7 @@ public A f(final V6<A> v) {
343323
* @return a function that gets the fourth element of a given vector.
344324
*/
345325
public static <A> F<V6<A>, A> __4() {
346-
return new F<V6<A>, A>() {
347-
public A f(final V6<A> v) {
348-
return v._4();
349-
}
350-
};
326+
return v -> v._4();
351327
}
352328

353329
/**
@@ -356,11 +332,7 @@ public A f(final V6<A> v) {
356332
* @return a function that gets the fifth element of a given vector.
357333
*/
358334
public static <A> F<V6<A>, A> __5() {
359-
return new F<V6<A>, A>() {
360-
public A f(final V6<A> v) {
361-
return v._5();
362-
}
363-
};
335+
return v -> v._5();
364336
}
365337

366338
/**
@@ -369,11 +341,7 @@ public A f(final V6<A> v) {
369341
* @return a function that gets the sixth element of a given vector.
370342
*/
371343
public static <A> F<V6<A>, A> __6() {
372-
return new F<V6<A>, A>() {
373-
public A f(final V6<A> v) {
374-
return v._6();
375-
}
376-
};
344+
return v -> v._6();
377345
}
378346

379347
}

0 commit comments

Comments
 (0)