@@ -119,14 +119,14 @@ <h2 id="arrayExists">Array Exists</h2>
119119< pre class ="prettyprint java language-java "> < code > import fj.data.Array;
120120import static fj.data.Array.array;
121121import static fj.data.List.fromString;
122- import static java.lang.Character .isLowerCase;
122+ import static fj.function.Characters .isLowerCase;
123123
124124public 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+ }
130130}</ code > </ pre >
131131</ div >
132132</ div >
@@ -147,13 +147,15 @@ <h2 id="arrayFilter">Array Filter</h2>
147147import static fj.data.Array.array;
148148import static fj.Show.arrayShow;
149149import static fj.Show.intShow;
150+ import static fj.function.Integers.even;
150151
151152public 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+ }
157159}</ code > </ pre >
158160</ div >
159161</ div >
@@ -170,15 +172,20 @@ <h2 id="arrayFoldLeft">Array Fold Left</h2>
170172</ div >
171173< div class ="listingblock ">
172174< 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;
174177import static fj.data.Array.array;
178+ import static fj.function.Integers.add;
175179
176180public 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+ }
182189}</ code > </ pre >
183190</ div >
184191</ div >
@@ -198,14 +205,14 @@ <h2 id="arrayForall">Array For All</h2>
198205< pre class ="prettyprint java language-java "> < code > import fj.data.Array;
199206import static fj.data.Array.array;
200207import static fj.data.List.fromString;
201- import static java.lang.Character .isLowerCase;
208+ import static fj.function.Characters .isLowerCase;
202209
203210public 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+ }
209216}</ code > </ pre >
210217</ div >
211218</ div >
@@ -218,21 +225,24 @@ <h2 id="arrayMap">Array Map</h2>
218225< p > < a href ="https://github.com/functionaljava/functionaljava/blob/master/demo/src/main/java/fj/demo/Array_map.java "> Github Source</ a > </ p >
219226</ div >
220227< 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 >
222229</ div >
223230< div class ="listingblock ">
224231< div class ="content ">
225232< pre class ="prettyprint java language-java "> < code > import fj.data.Array;
226233import static fj.data.Array.array;
234+ import static fj.function.Integers.add;
227235import static fj.Show.arrayShow;
228236import static fj.Show.intShow;
229237
230238public 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+ }
236246}</ code > </ pre >
237247</ div >
238248</ div >
@@ -249,17 +259,19 @@ <h2 id="listMap">List Map</h2>
249259</ div >
250260< div class ="listingblock ">
251261< 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;
254265import static fj.Show.intShow;
255266import static fj.Show.listShow;
256267
257268public 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+ }
263275}</ code > </ pre >
264276</ div >
265277</ div >
@@ -276,24 +288,28 @@ <h2 id="optionBind">Option Bind</h2>
276288</ div >
277289< div class ="listingblock ">
278290< 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;
282293import static fj.Show.intShow;
283294import static fj.Show.optionShow;
295+ import static fj.data.Option.none;
296+ import static fj.data.Option.some;
284297
285298public 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+ }
297313}</ code > </ pre >
298314</ div >
299315</ div >
@@ -310,24 +326,33 @@ <h2 id="optionFilter">Option filter</h2>
310326</ div >
311327< div class ="listingblock ">
312328< 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;
316331import static fj.Show.intShow;
317332import 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;
318336
319337public 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+ }
331356}</ code > </ pre >
332357</ div >
333358</ div >
@@ -345,20 +370,25 @@ <h2 id="optionMap">Option Map</h2>
345370< div class ="listingblock ">
346371< div class ="content ">
347372< 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;
350373import static fj.Show.intShow;
351374import 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;
352378
353379public 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+ }
362392}</ code > </ pre >
363393</ div >
364394</ div >
0 commit comments