@@ -119,14 +119,14 @@ <h2 id="arrayExists">Array Exists</h2>
119
119
< pre class ="prettyprint java language-java "> < code > import fj.data.Array;
120
120
import static fj.data.Array.array;
121
121
import static fj.data.List.fromString;
122
- import static java.lang.Character .isLowerCase;
122
+ import static fj.function.Characters .isLowerCase;
123
123
124
124
public final class Array_exists {
125
- public static void main(final String[] args) {
126
- final Array<String> a = array("Hello", "There", "what", "DAY", "iS", "iT");
127
- final boolean b = a.exists(s -> fromString(s).forall(isLowerCase));
128
- System.out.println(b); // true ("what" provides the only example ; try removing it)
129
- }
125
+ public static void main(final String[] args) {
126
+ final Array<String> a = array("Hello", "There", "what", "DAY", "iS", "iT");
127
+ final boolean b = a.exists(s -> fromString(s).forall(isLowerCase));
128
+ System.out.println(b); // true ("what" is the only value that qualifies ; try removing it)
129
+ }
130
130
}</ code > </ pre >
131
131
</ div >
132
132
</ div >
@@ -147,13 +147,15 @@ <h2 id="arrayFilter">Array Filter</h2>
147
147
import static fj.data.Array.array;
148
148
import static fj.Show.arrayShow;
149
149
import static fj.Show.intShow;
150
+ import static fj.function.Integers.even;
150
151
151
152
public final class Array_filter {
152
- public static void main(final String[] args) {
153
- final Array<Integer> a = array(97, 44, 67, 3, 22, 90, 1, 77, 98, 1078, 6, 64, 6, 79, 42);
154
- final Array<Integer> b = a.filter(i -> i % 2 == 0);
155
- arrayShow(intShow).println(b); // {44,22,90,98,1078,6,64,6,42}
156
- }
153
+ public static void main(final String[] args) {
154
+ final Array<Integer> a = array(97, 44, 67, 3, 22, 90, 1, 77, 98, 1078, 6, 64, 6, 79, 42);
155
+ final Array<Integer> b = a.filter(even);
156
+ final Array<Integer> c = a.filter(i -> i % 2 == 0);
157
+ arrayShow(intShow).println(b); // {44,22,90,98,1078,6,64,6,42}
158
+ }
157
159
}</ code > </ pre >
158
160
</ div >
159
161
</ div >
@@ -170,15 +172,20 @@ <h2 id="arrayFoldLeft">Array Fold Left</h2>
170
172
</ div >
171
173
< div class ="listingblock ">
172
174
< div class ="content ">
173
- < pre class ="prettyprint java language-java "> < code > import fj.data.Array;
175
+ < pre class ="prettyprint java language-java "> < code > import fj.F;
176
+ import fj.data.Array;
174
177
import static fj.data.Array.array;
178
+ import static fj.function.Integers.add;
175
179
176
180
public final class Array_foldLeft {
177
- public static void main(final String[] args) {
178
- final Array<Integer> a = array(97, 44, 67, 3, 22, 90, 1, 77, 98, 1078, 6, 64, 6, 79, 42);
179
- final int b = a.<Integer>foldLeft(i -> (j -> i + j), 0);
180
- System.out.println(b); // 1774
181
- }
181
+ public static void main(final String[] args) {
182
+ final Array<Integer> a = array(97, 44, 67, 3, 22, 90, 1, 77, 98, 1078, 6, 64, 6, 79, 42);
183
+ final int b = a.foldLeft(add, 0);
184
+
185
+ F<Integer, F<Integer, Integer>> add2 = i -> (j -> i + j);
186
+ final int c = a.foldLeft(add2, 0);
187
+ System.out.println(b); // 1774
188
+ }
182
189
}</ code > </ pre >
183
190
</ div >
184
191
</ div >
@@ -198,14 +205,14 @@ <h2 id="arrayForall">Array For All</h2>
198
205
< pre class ="prettyprint java language-java "> < code > import fj.data.Array;
199
206
import static fj.data.Array.array;
200
207
import static fj.data.List.fromString;
201
- import static java.lang.Character .isLowerCase;
208
+ import static fj.function.Characters .isLowerCase;
202
209
203
210
public final class Array_forall {
204
- public static void main(final String[] args) {
205
- final Array<String> a = array("hello", "There", "what", "day", "is", "it");
206
- final boolean b = a.forall(s -> fromString(s).forall(isLowerCase));
207
- System.out.println(b); // false ("There" is a counter-example; try removing it)
208
- }
211
+ public static void main(final String[] args) {
212
+ final Array<String> a = array("hello", "There", "what", "day", "is", "it");
213
+ final boolean b = a.forall(s -> fromString(s).forall(isLowerCase));
214
+ System.out.println(b); // false ("There" is a counter-example; try removing it)
215
+ }
209
216
}</ code > </ pre >
210
217
</ div >
211
218
</ div >
@@ -218,21 +225,24 @@ <h2 id="arrayMap">Array Map</h2>
218
225
< p > < a href ="https://github.com/functionaljava/functionaljava/blob/master/demo/src/main/java/fj/demo/Array_map.java "> Github Source</ a > </ p >
219
226
</ div >
220
227
< div class ="paragraph ">
221
- < p > Maps a function across the array of integers. In this case, the function adds 42 to each element of the array to produce a new array.</p> </ p >
228
+ < p > Maps a function across the array of integers. In this case, the function adds 42 to each element of the array to produce a new array.</ p >
222
229
</ div >
223
230
< div class ="listingblock ">
224
231
< div class ="content ">
225
232
< pre class ="prettyprint java language-java "> < code > import fj.data.Array;
226
233
import static fj.data.Array.array;
234
+ import static fj.function.Integers.add;
227
235
import static fj.Show.arrayShow;
228
236
import static fj.Show.intShow;
229
237
230
238
public final class Array_map {
231
- public static void main(final String[] args) {
232
- final Array<Integer> a = array(1, 2, 3);
233
- final Array<Integer> b = a.map(i -> i + 42);
234
- arrayShow(intShow).println(b); // {43,44,45}
235
- }
239
+ public static void main(final String[] args) {
240
+ final Array<Integer> a = array(1, 2, 3);
241
+ final Array<Integer> b = a.map(add.f(42));
242
+ final Array<Integer> c = a.map(i -> i + 42);
243
+ arrayShow(intShow).println(b); // {43,44,45}
244
+ arrayShow(intShow).println(c); // {43,44,45}
245
+ }
236
246
}</ code > </ pre >
237
247
</ div >
238
248
</ div >
@@ -249,17 +259,19 @@ <h2 id="listMap">List Map</h2>
249
259
</ div >
250
260
< div class ="listingblock ">
251
261
< div class ="content ">
252
- < pre class ="prettyprint java language-java "> < code > import static fj.data.List.list;
253
- import fj.data.List;
262
+ < pre class ="prettyprint java language-java "> < code > import fj.data.List;
263
+ import static fj.data.List.list;
264
+ import static fj.function.Integers.add;
254
265
import static fj.Show.intShow;
255
266
import static fj.Show.listShow;
256
267
257
268
public final class List_map {
258
- public static void main(final String[] args) {
259
- final List<Integer> a = list(1, 2, 3);
260
- final List<Integer> b = a.map(i -> i + 42);
261
- listShow(intShow).println(b); // [43,44,45]
262
- }
269
+ public static void main(final String[] args) {
270
+ final List<Integer> a = list(1, 2, 3);
271
+ final List<Integer> b = a.map(add.f(42));
272
+ final List<Integer> c = a.map(i -> i = 42);
273
+ listShow(intShow).println(b); // [43,44,45]
274
+ }
263
275
}</ code > </ pre >
264
276
</ div >
265
277
</ div >
@@ -276,24 +288,28 @@ <h2 id="optionBind">Option Bind</h2>
276
288
</ div >
277
289
< div class ="listingblock ">
278
290
< div class ="content ">
279
- < pre class ="prettyprint java language-java "> < code > import fj.data.Option;
280
- import static fj.data.Option.none;
281
- import static fj.data.Option.some;
291
+ < pre class ="prettyprint java language-java "> < code > import fj.F;
292
+ import fj.data.Option;
282
293
import static fj.Show.intShow;
283
294
import static fj.Show.optionShow;
295
+ import static fj.data.Option.none;
296
+ import static fj.data.Option.some;
284
297
285
298
public final class Option_bind {
286
- public static void main(final String[] args) {
287
- final Option<Integer> o1 = some(7);
288
- final Option<Integer> o2 = some(8);
289
- final Option<Integer> o3 = none();
290
- final Option<Integer> p1 = o1.bind(i -> i % 2 == 0 ? some(i * 3) : Option.<Integer>none());
291
- final Option<Integer> p2 = o2.bind(i -> i % 2 == 0 ? some(i * 3) : Option.<Integer>none());
292
- final Option<Integer> p3 = o3.bind(i -> i % 2 == 0 ? some(i * 3) : Option.<Integer>none());
293
- optionShow(intShow).println(p1); // None
294
- optionShow(intShow).println(p2); // Some(24)
295
- optionShow(intShow).println(p3); // None
296
- }
299
+ public static void main(final String[] args) {
300
+ final Option<Integer> o1 = some(7);
301
+ final Option<Integer> o2 = some(8);
302
+ final Option<Integer> o3 = none();
303
+
304
+ F<Integer, Option<Integer>> f = i -> i % 2 == 0 ? some(i * 3) : none();
305
+ final Option<Integer> o4 = o1.bind(f);
306
+ final Option<Integer> o5 = o2.bind(f);
307
+ final Option<Integer> o6 = o3.bind(f);
308
+
309
+ optionShow(intShow).println(o4); // None
310
+ optionShow(intShow).println(o5); // Some(24)
311
+ optionShow(intShow).println(o6); // None
312
+ }
297
313
}</ code > </ pre >
298
314
</ div >
299
315
</ div >
@@ -310,24 +326,33 @@ <h2 id="optionFilter">Option filter</h2>
310
326
</ div >
311
327
< div class ="listingblock ">
312
328
< div class ="content ">
313
- < pre class ="prettyprint java language-java "> < code > import fj.data.Option;
314
- import static fj.data.Option.none;
315
- import static fj.data.Option.some;
329
+ < pre class ="prettyprint java language-java "> < code > import fj.F;
330
+ import fj.data.Option;
316
331
import static fj.Show.intShow;
317
332
import static fj.Show.optionShow;
333
+ import static fj.data.Option.none;
334
+ import static fj.data.Option.some;
335
+ import static fj.function.Integers.even;
318
336
319
337
public final class Option_filter {
320
- public static void main(final String[] args) {
321
- final Option<Integer> o1 = some(7);
322
- final Option<Integer> o2 = none();
323
- final Option<Integer> o3 = some(8);
324
- final Option<Integer> p1 = o1.filter(i -> i % 2 == 0);
325
- final Option<Integer> p2 = o2.filter(i -> i % 2 == 0);
326
- final Option<Integer> p3 = o3.filter(i -> i % 2 == 0);
327
- optionShow(intShow).println(p1); // None
328
- optionShow(intShow).println(p2); // None
329
- optionShow(intShow).println(p3); // Some(8)
330
- }
338
+ public static void main(final String[] args) {
339
+ final Option<Integer> o1 = some(7);
340
+ final Option<Integer> o2 = none();
341
+ final Option<Integer> o3 = some(8);
342
+
343
+ final Option<Integer> o4 = o1.filter(even);
344
+ final Option<Integer> o5 = o2.filter(even);
345
+ final Option<Integer> o6 = o3.filter(even);
346
+
347
+ F<Integer, Boolean> f = i -> i % 2 == 0;
348
+ final Option<Integer> o7 = o1.filter(f);
349
+ final Option<Integer> o8 = o1.filter(f);
350
+ final Option<Integer> o9 = o1.filter(i -> i % 2 == 0);
351
+
352
+ optionShow(intShow).println(o4); // None
353
+ optionShow(intShow).println(o5); // None
354
+ optionShow(intShow).println(o6); // Some(8)
355
+ }
331
356
}</ code > </ pre >
332
357
</ div >
333
358
</ div >
@@ -345,20 +370,25 @@ <h2 id="optionMap">Option Map</h2>
345
370
< div class ="listingblock ">
346
371
< div class ="content ">
347
372
< pre class ="prettyprint java language-java "> < code > import fj.data.Option;
348
- import static fj.data.Option.none;
349
- import static fj.data.Option.some;
350
373
import static fj.Show.intShow;
351
374
import static fj.Show.optionShow;
375
+ import static fj.data.Option.none;
376
+ import static fj.data.Option.some;
377
+ import static fj.function.Integers.add;
352
378
353
379
public final class Option_map {
354
- public static void main(final String[] args) {
355
- final Option<Integer> o1 = some(7);
356
- final Option<Integer> o2 = none();
357
- final Option<Integer> p1 = o1.map(i -> i + 42);
358
- final Option<Integer> p2 = o2.map(i -> i + 42);
359
- optionShow(intShow).println(p1); // Some(49)
360
- optionShow(intShow).println(p2); // None
361
- }
380
+ public static void main(final String[] args) {
381
+ final Option<Integer> o1 = some(7);
382
+ final Option<Integer> o2 = none();
383
+ final Option<Integer> p1 = o1.map(add.f(42));
384
+ final Option<Integer> p2 = o2.map(add.f(42));
385
+
386
+ final Option<Integer> p3 = o1.map(i -> i + 42);
387
+ final Option<Integer> p4 = o2.map(i -> i + 42);
388
+
389
+ optionShow(intShow).println(p1); // Some(49)
390
+ optionShow(intShow).println(p2); // None
391
+ }
362
392
}</ code > </ pre >
363
393
</ div >
364
394
</ div >
0 commit comments