comparison src/main/java/fj/data/Conversions.java @ 0:fe80c1edf1be

add getLoop
author tatsuki
date Fri, 20 Mar 2015 21:04:03 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:fe80c1edf1be
1 package fj.data;
2
3 import fj.F;
4 import fj.P1;
5 import fj.Unit;
6 import fj.function.TryEffect0;
7 import fj.function.Effect0;
8 import fj.function.Effect1;
9
10 import fj.Try;
11 import fj.TryEffect;
12 import fj.Effect;
13 import fj.function.Try0;
14 import fj.function.Try1;
15
16 import java.io.IOException;
17 import static fj.Unit.unit;
18 import static fj.data.List.asString;
19 import static fj.data.List.fromString;
20
21 /**
22 * Functions that convert between data structure types.
23 *
24 * @version %build.number%
25 */
26 public final class Conversions {
27 private Conversions() {
28 throw new UnsupportedOperationException();
29 }
30
31 // BEGIN List ->
32
33 /**
34 * A function that converts lists to arrays.
35 *
36 * @return A function that converts lists to arrays.
37 */
38 public static <A> F<List<A>, Array<A>> List_Array() {
39 return new F<List<A>, Array<A>>() {
40 public Array<A> f(final List<A> as) {
41 return as.toArray();
42 }
43 };
44 }
45
46 /**
47 * A function that converts lists to streams.
48 *
49 * @return A function that converts lists to streams.
50 */
51 public static <A> F<List<A>, Stream<A>> List_Stream() {
52 return new F<List<A>, Stream<A>>() {
53 public Stream<A> f(final List<A> as) {
54 return as.toStream();
55 }
56 };
57 }
58
59 /**
60 * A function that converts lists to options.
61 *
62 * @return A function that converts lists to options.
63 */
64 public static <A> F<List<A>, Option<A>> List_Option() {
65 return new F<List<A>, Option<A>>() {
66 public Option<A> f(final List<A> as) {
67 return as.toOption();
68 }
69 };
70 }
71
72 /**
73 * A function that converts lists to eithers.
74 *
75 * @return A function that converts lists to eithers.
76 */
77 public static <A, B> F<P1<A>, F<List<B>, Either<A, B>>> List_Either() {
78 return new F<P1<A>, F<List<B>, Either<A, B>>>() {
79 public F<List<B>, Either<A, B>> f(final P1<A> a) {
80 return new F<List<B>, Either<A, B>>() {
81 public Either<A, B> f(final List<B> bs) {
82 return bs.toEither(a);
83 }
84 };
85 }
86 };
87 }
88
89 /**
90 * A function that converts lists to strings.
91 */
92 public static final F<List<Character>, String> List_String = new F<List<Character>, String>() {
93 public String f(final List<Character> cs) {
94 return asString(cs);
95 }
96 };
97
98 /**
99 * A function that converts lists to string buffers.
100 */
101 public static final F<List<Character>, StringBuffer> List_StringBuffer = new F<List<Character>, StringBuffer>() {
102 public StringBuffer f(final List<Character> cs) {
103 return new StringBuffer(asString(cs));
104 }
105 };
106
107 /**
108 * A function that converts lists to string builders.
109 */
110 public static final F<List<Character>, StringBuilder> List_StringBuilder = new F<List<Character>, StringBuilder>() {
111 public StringBuilder f(final List<Character> cs) {
112 return new StringBuilder(asString(cs));
113 }
114 };
115
116 // END List ->
117
118 // BEGIN Array ->
119
120 /**
121 * A function that converts arrays to lists.
122 *
123 * @return A function that converts arrays to lists.
124 */
125 public static <A> F<Array<A>, List<A>> Array_List() {
126 return new F<Array<A>, List<A>>() {
127 public List<A> f(final Array<A> as) {
128 return as.toList();
129 }
130 };
131 }
132
133 /**
134 * A function that converts arrays to streams.
135 *
136 * @return A function that converts arrays to streams.
137 */
138 public static <A> F<Array<A>, Stream<A>> Array_Stream() {
139 return new F<Array<A>, Stream<A>>() {
140 public Stream<A> f(final Array<A> as) {
141 return as.toStream();
142 }
143 };
144 }
145
146 /**
147 * A function that converts arrays to options.
148 *
149 * @return A function that converts arrays to options.
150 */
151 public static <A> F<Array<A>, Option<A>> Array_Option() {
152 return new F<Array<A>, Option<A>>() {
153 public Option<A> f(final Array<A> as) {
154 return as.toOption();
155 }
156 };
157 }
158
159 /**
160 * A function that converts arrays to eithers.
161 *
162 * @return A function that converts arrays to eithers.
163 */
164 public static <A, B> F<P1<A>, F<Array<B>, Either<A, B>>> Array_Either() {
165 return new F<P1<A>, F<Array<B>, Either<A, B>>>() {
166 public F<Array<B>, Either<A, B>> f(final P1<A> a) {
167 return new F<Array<B>, Either<A, B>>() {
168 public Either<A, B> f(final Array<B> bs) {
169 return bs.toEither(a);
170 }
171 };
172 }
173 };
174 }
175
176 /**
177 * A function that converts arrays to strings.
178 */
179 public static final F<Array<Character>, String> Array_String = new F<Array<Character>, String>() {
180 public String f(final Array<Character> cs) {
181 final StringBuilder sb = new StringBuilder();
182 cs.foreachDoEffect(new Effect1<Character>() {
183 public void f(final Character c) {
184 sb.append(c);
185 }
186 });
187 return sb.toString();
188 }
189 };
190
191 /**
192 * A function that converts arrays to string buffers.
193 */
194 public static final F<Array<Character>, StringBuffer> Array_StringBuffer = new F<Array<Character>, StringBuffer>() {
195 public StringBuffer f(final Array<Character> cs) {
196 final StringBuffer sb = new StringBuffer();
197 cs.foreachDoEffect(new Effect1<Character>() {
198 public void f(final Character c) {
199 sb.append(c);
200 }
201 });
202 return sb;
203 }
204 };
205
206 /**
207 * A function that converts arrays to string builders.
208 */
209 public static final F<Array<Character>, StringBuilder> Array_StringBuilder =
210 new F<Array<Character>, StringBuilder>() {
211 public StringBuilder f(final Array<Character> cs) {
212 final StringBuilder sb = new StringBuilder();
213 cs.foreachDoEffect((Character c) -> sb.append(c));
214 return sb;
215 }
216 };
217
218 // END Array ->
219
220 // BEGIN Stream ->
221
222 /**
223 * A function that converts streams to lists.
224 *
225 * @return A function that converts streams to lists.
226 */
227 public static <A> F<Stream<A>, List<A>> Stream_List() {
228 return new F<Stream<A>, List<A>>() {
229 public List<A> f(final Stream<A> as) {
230 return as.toList();
231 }
232 };
233 }
234
235 /**
236 * A function that converts streams to arrays.
237 *
238 * @return A function that converts streams to arrays.
239 */
240 public static <A> F<Stream<A>, Array<A>> Stream_Array() {
241 return new F<Stream<A>, Array<A>>() {
242 public Array<A> f(final Stream<A> as) {
243 return as.toArray();
244 }
245 };
246 }
247
248 /**
249 * A function that converts streams to options.
250 *
251 * @return A function that converts streams to options.
252 */
253 public static <A> F<Stream<A>, Option<A>> Stream_Option() {
254 return new F<Stream<A>, Option<A>>() {
255 public Option<A> f(final Stream<A> as) {
256 return as.toOption();
257 }
258 };
259 }
260
261 /**
262 * A function that converts streams to eithers.
263 *
264 * @return A function that converts streams to eithers.
265 */
266 public static <A, B> F<P1<A>, F<Stream<B>, Either<A, B>>> Stream_Either() {
267 return new F<P1<A>, F<Stream<B>, Either<A, B>>>() {
268 public F<Stream<B>, Either<A, B>> f(final P1<A> a) {
269 return new F<Stream<B>, Either<A, B>>() {
270 public Either<A, B> f(final Stream<B> bs) {
271 return bs.toEither(a);
272 }
273 };
274 }
275 };
276 }
277
278 /**
279 * A function that converts streams to strings.
280 */
281 public static final F<Stream<Character>, String> Stream_String = new F<Stream<Character>, String>() {
282 public String f(final Stream<Character> cs) {
283 final StringBuilder sb = new StringBuilder();
284 cs.foreachDoEffect((Character c) -> sb.append(c));
285 return sb.toString();
286 }
287 };
288
289 /**
290 * A function that converts streams to string buffers.
291 */
292 public static final F<Stream<Character>, StringBuffer> Stream_StringBuffer =
293 new F<Stream<Character>, StringBuffer>() {
294 public StringBuffer f(final Stream<Character> cs) {
295 final StringBuffer sb = new StringBuffer();
296 cs.foreachDoEffect((Character c) -> sb.append(c));
297 return sb;
298 }
299 };
300
301 /**
302 * A function that converts streams to string builders.
303 */
304 public static final F<Stream<Character>, StringBuilder> Stream_StringBuilder =
305 new F<Stream<Character>, StringBuilder>() {
306 public StringBuilder f(final Stream<Character> cs) {
307 final StringBuilder sb = new StringBuilder();
308 cs.foreachDoEffect((Character c) -> sb.append(c));
309 return sb;
310 }
311 };
312
313 // END Stream ->
314
315 // BEGIN Option ->
316
317 /**
318 * A function that converts options to lists.
319 *
320 * @return A function that converts options to lists.
321 */
322 public static <A> F<Option<A>, List<A>> Option_List() {
323 return new F<Option<A>, List<A>>() {
324 public List<A> f(final Option<A> o) {
325 return o.toList();
326 }
327 };
328 }
329
330 /**
331 * A function that converts options to arrays.
332 *
333 * @return A function that converts options to arrays.
334 */
335 public static <A> F<Option<A>, Array<A>> Option_Array() {
336 return new F<Option<A>, Array<A>>() {
337 public Array<A> f(final Option<A> o) {
338 return o.toArray();
339 }
340 };
341 }
342
343 /**
344 * A function that converts options to streams.
345 *
346 * @return A function that converts options to streams.
347 */
348 public static <A> F<Option<A>, Stream<A>> Option_Stream() {
349 return new F<Option<A>, Stream<A>>() {
350 public Stream<A> f(final Option<A> o) {
351 return o.toStream();
352 }
353 };
354 }
355
356 /**
357 * A function that converts options to eithers.
358 *
359 * @return A function that converts options to eithers.
360 */
361 public static <A, B> F<P1<A>, F<Option<B>, Either<A, B>>> Option_Either() {
362 return new F<P1<A>, F<Option<B>, Either<A, B>>>() {
363 public F<Option<B>, Either<A, B>> f(final P1<A> a) {
364 return new F<Option<B>, Either<A, B>>() {
365 public Either<A, B> f(final Option<B> o) {
366 return o.toEither(a);
367 }
368 };
369 }
370 };
371 }
372
373 /**
374 * A function that converts options to strings.
375 */
376 public static final F<Option<Character>, String> Option_String = new F<Option<Character>, String>() {
377 public String f(final Option<Character> o) {
378 return asString(o.toList());
379 }
380 };
381
382 /**
383 * A function that converts options to string buffers.
384 */
385 public static final F<Option<Character>, StringBuffer> Option_StringBuffer =
386 new F<Option<Character>, StringBuffer>() {
387 public StringBuffer f(final Option<Character> o) {
388 return new StringBuffer(asString(o.toList()));
389 }
390 };
391
392 /**
393 * A function that converts options to string builders.
394 */
395 public static final F<Option<Character>, StringBuilder> Option_StringBuilder =
396 new F<Option<Character>, StringBuilder>() {
397 public StringBuilder f(final Option<Character> o) {
398 return new StringBuilder(asString(o.toList()));
399 }
400 };
401
402 // END Option ->
403
404 // BEGIN Effect
405
406 public static F<Effect0, P1<Unit>> Effect0_P1() {
407 return e -> Effect0_P1(e);
408 }
409
410 public static P1<Unit> Effect0_P1(Effect0 e) {
411 return Effect.f(e);
412 }
413
414 public static <A> F<A, Unit> Effect1_F(Effect1<A> e) {
415 return Effect.f(e);
416 }
417
418 public static <A> F<Effect1<A>, F<A, Unit>> Effect1_F() {
419 return e -> Effect1_F(e);
420 }
421
422 public static IO<Unit> Effect_IO(Effect0 e) {
423 return () ->{
424 e.f();
425 return Unit.unit();
426 };
427 }
428
429 public static F<Effect0, IO<Unit>> Effect_IO() {
430 return e -> Effect_IO(e);
431 }
432
433 public static SafeIO<Unit> Effect_SafeIO(Effect0 e) {
434 return () -> {
435 e.f();
436 return unit();
437 };
438 }
439
440 public static F<Effect0, SafeIO<Unit>> Effect_SafeIO() {
441 return e -> Effect_SafeIO(e);
442 }
443
444 // END Effect
445
446 // BEGIN Either ->
447
448 /**
449 * A function that converts eithers to lists.
450 *
451 * @return A function that converts eithers to lists.
452 */
453 public static <A, B> F<Either<A, B>, List<A>> Either_ListA() {
454 return new F<Either<A, B>, List<A>>() {
455 public List<A> f(final Either<A, B> e) {
456 return e.left().toList();
457 }
458 };
459 }
460
461 /**
462 * A function that converts eithers to lists.
463 *
464 * @return A function that converts eithers to lists.
465 */
466 public static <A, B> F<Either<A, B>, List<B>> Either_ListB() {
467 return new F<Either<A, B>, List<B>>() {
468 public List<B> f(final Either<A, B> e) {
469 return e.right().toList();
470 }
471 };
472 }
473
474 /**
475 * A function that converts eithers to arrays.
476 *
477 * @return A function that converts eithers to arrays.
478 */
479 public static <A, B> F<Either<A, B>, Array<A>> Either_ArrayA() {
480 return new F<Either<A, B>, Array<A>>() {
481 public Array<A> f(final Either<A, B> e) {
482 return e.left().toArray();
483 }
484 };
485 }
486
487 /**
488 * A function that converts eithers to arrays.
489 *
490 * @return A function that converts eithers to arrays.
491 */
492 public static <A, B> F<Either<A, B>, Array<B>> Either_ArrayB() {
493 return new F<Either<A, B>, Array<B>>() {
494 public Array<B> f(final Either<A, B> e) {
495 return e.right().toArray();
496 }
497 };
498 }
499
500 /**
501 * A function that converts eithers to streams.
502 *
503 * @return A function that converts eithers to streams.
504 */
505 public static <A, B> F<Either<A, B>, Stream<A>> Either_StreamA() {
506 return new F<Either<A, B>, Stream<A>>() {
507 public Stream<A> f(final Either<A, B> e) {
508 return e.left().toStream();
509 }
510 };
511 }
512
513 /**
514 * A function that converts eithers to streams.
515 *
516 * @return A function that converts eithers to streams.
517 */
518 public static <A, B> F<Either<A, B>, Stream<B>> Either_StreamB() {
519 return new F<Either<A, B>, Stream<B>>() {
520 public Stream<B> f(final Either<A, B> e) {
521 return e.right().toStream();
522 }
523 };
524 }
525
526 /**
527 * A function that converts eithers to options.
528 *
529 * @return A function that converts eithers to options.
530 */
531 public static <A, B> F<Either<A, B>, Option<A>> Either_OptionA() {
532 return new F<Either<A, B>, Option<A>>() {
533 public Option<A> f(final Either<A, B> e) {
534 return e.left().toOption();
535 }
536 };
537 }
538
539 /**
540 * A function that converts eithers to options.
541 *
542 * @return A function that converts eithers to options.
543 */
544 public static <A, B> F<Either<A, B>, Option<B>> Either_OptionB() {
545 return new F<Either<A, B>, Option<B>>() {
546 public Option<B> f(final Either<A, B> e) {
547 return e.right().toOption();
548 }
549 };
550 }
551
552 /**
553 * A function that converts eithers to strings.
554 *
555 * @return A function that converts eithers to strings.
556 */
557 public static <B> F<Either<Character, B>, String> Either_StringA() {
558 return new F<Either<Character, B>, String>() {
559 public String f(final Either<Character, B> e) {
560 return asString(e.left().toList());
561 }
562 };
563 }
564
565 /**
566 * A function that converts eithers to strings.
567 *
568 * @return A function that converts eithers to strings.
569 */
570 public static <A> F<Either<A, Character>, String> Either_StringB() {
571 return new F<Either<A, Character>, String>() {
572 public String f(final Either<A, Character> e) {
573 return asString(e.right().toList());
574 }
575 };
576 }
577
578 /**
579 * A function that converts eithers to string buffers.
580 *
581 * @return A function that converts eithers to string buffers.
582 */
583 public static <B> F<Either<Character, B>, StringBuffer> Either_StringBufferA() {
584 return new F<Either<Character, B>, StringBuffer>() {
585 public StringBuffer f(final Either<Character, B> e) {
586 return new StringBuffer(asString(e.left().toList()));
587 }
588 };
589 }
590
591 /**
592 * A function that converts eithers to string buffers.
593 *
594 * @return A function that converts eithers to string buffers.
595 */
596 public static <A> F<Either<A, Character>, StringBuffer> Either_StringBufferB() {
597 return new F<Either<A, Character>, StringBuffer>() {
598 public StringBuffer f(final Either<A, Character> e) {
599 return new StringBuffer(asString(e.right().toList()));
600 }
601 };
602 }
603
604 /**
605 * A function that converts eithers to string builders.
606 *
607 * @return A function that converts eithers to string builders.
608 */
609 public static <B> F<Either<Character, B>, StringBuilder> Either_StringBuilderA() {
610 return new F<Either<Character, B>, StringBuilder>() {
611 public StringBuilder f(final Either<Character, B> e) {
612 return new StringBuilder(asString(e.left().toList()));
613 }
614 };
615 }
616
617 /**
618 * A function that converts eithers to string builders.
619 *
620 * @return A function that converts eithers to string builders.
621 */
622 public static <A> F<Either<A, Character>, StringBuilder> Either_StringBuilderB() {
623 return new F<Either<A, Character>, StringBuilder>() {
624 public StringBuilder f(final Either<A, Character> e) {
625 return new StringBuilder(asString(e.right().toList()));
626 }
627 };
628 }
629
630 // END Either ->
631
632 // BEGIN F
633
634 public static <A> SafeIO<A> F_SafeIO(F<Unit, A> f) {
635 return () -> f.f(unit());
636 }
637
638 public static <A> F<F<Unit, A>, SafeIO<A>> F_SafeIO() {
639 return f -> F_SafeIO(f);
640 }
641
642 // END F
643
644 // BEGIN String ->
645
646 /**
647 * A function that converts strings to lists.
648 */
649 public static final F<String, List<Character>> String_List = new F<String, List<Character>>() {
650 public List<Character> f(final String s) {
651 return fromString(s);
652 }
653 };
654
655 /**
656 * A function that converts strings to arrays.
657 */
658 public static final F<String, Array<Character>> String_Array = new F<String, Array<Character>>() {
659 public Array<Character> f(final String s) {
660 return fromString(s).toArray();
661 }
662 };
663
664 /**
665 * A function that converts strings to options.
666 */
667 public static final F<String, Option<Character>> String_Option = new F<String, Option<Character>>() {
668 public Option<Character> f(final String s) {
669 return fromString(s).toOption();
670 }
671 };
672
673 /**
674 * A function that converts string to eithers.
675 *
676 * @return A function that converts string to eithers.
677 */
678 public static <A> F<P1<A>, F<String, Either<A, Character>>> String_Either() {
679 return new F<P1<A>, F<String, Either<A, Character>>>() {
680 public F<String, Either<A, Character>> f(final P1<A> a) {
681 return new F<String, Either<A, Character>>() {
682 public Either<A, Character> f(final String s) {
683 return fromString(s).toEither(a);
684 }
685 };
686 }
687 };
688 }
689
690 /**
691 * A function that converts strings to streams.
692 */
693 public static final F<String, Stream<Character>> String_Stream = new F<String, Stream<Character>>() {
694 public Stream<Character> f(final String s) {
695 return fromString(s).toStream();
696 }
697 };
698
699 /**
700 * A function that converts strings to string buffers.
701 */
702 public static final F<String, StringBuffer> String_StringBuffer = new F<String, StringBuffer>() {
703 public StringBuffer f(final String s) {
704 return new StringBuffer(s);
705 }
706 };
707
708 /**
709 * A function that converts strings to string builders.
710 */
711 public static final F<String, StringBuilder> String_StringBuilder = new F<String, StringBuilder>() {
712 public StringBuilder f(final String s) {
713 return new StringBuilder(s);
714 }
715 };
716
717 // END String ->
718
719 // BEGIN StringBuffer ->
720
721 /**
722 * A function that converts string buffers to lists.
723 */
724 public static final F<StringBuffer, List<Character>> StringBuffer_List = new F<StringBuffer, List<Character>>() {
725 public List<Character> f(final StringBuffer s) {
726 return fromString(s.toString());
727 }
728 };
729
730 /**
731 * A function that converts string buffers to arrays.
732 */
733 public static final F<StringBuffer, Array<Character>> StringBuffer_Array = new F<StringBuffer, Array<Character>>() {
734 public Array<Character> f(final StringBuffer s) {
735 return fromString(s.toString()).toArray();
736 }
737 };
738
739 /**
740 * A function that converts string buffers to streams.
741 */
742 public static final F<StringBuffer, Stream<Character>> StringBuffer_Stream =
743 new F<StringBuffer, Stream<Character>>() {
744 public Stream<Character> f(final StringBuffer s) {
745 return fromString(s.toString()).toStream();
746 }
747 };
748
749 /**
750 * A function that converts string buffers to options.
751 */
752 public static final F<StringBuffer, Option<Character>> StringBuffer_Option =
753 new F<StringBuffer, Option<Character>>() {
754 public Option<Character> f(final StringBuffer s) {
755 return fromString(s.toString()).toOption();
756 }
757 };
758
759 /**
760 * A function that converts string buffers to eithers.
761 *
762 * @return A function that converts string buffers to eithers.
763 */
764 public static <A> F<P1<A>, F<StringBuffer, Either<A, Character>>> StringBuffer_Either() {
765 return new F<P1<A>, F<StringBuffer, Either<A, Character>>>() {
766 public F<StringBuffer, Either<A, Character>> f(final P1<A> a) {
767 return new F<StringBuffer, Either<A, Character>>() {
768 public Either<A, Character> f(final StringBuffer s) {
769 return fromString(s.toString()).toEither(a);
770 }
771 };
772 }
773 };
774 }
775
776 /**
777 * A function that converts string buffers to strings.
778 */
779 public static final F<StringBuffer, String> StringBuffer_String = new F<StringBuffer, String>() {
780 public String f(final StringBuffer s) {
781 return s.toString();
782 }
783 };
784
785 /**
786 * A function that converts string buffers to string builders.
787 */
788 public static final F<StringBuffer, StringBuilder> StringBuffer_StringBuilder = new F<StringBuffer, StringBuilder>() {
789 public StringBuilder f(final StringBuffer s) {
790 return new StringBuilder(s);
791 }
792 };
793
794 // END StringBuffer ->
795
796 // BEGIN StringBuilder ->
797
798 /**
799 * A function that converts string builders to lists.
800 */
801 public static final F<StringBuilder, List<Character>> StringBuilder_List = new F<StringBuilder, List<Character>>() {
802 public List<Character> f(final StringBuilder s) {
803 return fromString(s.toString());
804 }
805 };
806
807 /**
808 * A function that converts string builders to arrays.
809 */
810 public static final F<StringBuilder, Array<Character>> StringBuilder_Array =
811 new F<StringBuilder, Array<Character>>() {
812 public Array<Character> f(final StringBuilder s) {
813 return fromString(s.toString()).toArray();
814 }
815 };
816
817 /**
818 * A function that converts string builders to streams.
819 */
820 public static final F<StringBuilder, Stream<Character>> StringBuilder_Stream =
821 new F<StringBuilder, Stream<Character>>() {
822 public Stream<Character> f(final StringBuilder s) {
823 return fromString(s.toString()).toStream();
824 }
825 };
826
827 /**
828 * A function that converts string builders to options.
829 */
830 public static final F<StringBuilder, Option<Character>> StringBuilder_Option =
831 new F<StringBuilder, Option<Character>>() {
832 public Option<Character> f(final StringBuilder s) {
833 return fromString(s.toString()).toOption();
834 }
835 };
836
837 /**
838 * A function that converts string builders to eithers.
839 *
840 * @return A function that converts string builders to eithers.
841 */
842 public static <A> F<P1<A>, F<StringBuilder, Either<A, Character>>> StringBuilder_Either() {
843 return new F<P1<A>, F<StringBuilder, Either<A, Character>>>() {
844 public F<StringBuilder, Either<A, Character>> f(final P1<A> a) {
845 return new F<StringBuilder, Either<A, Character>>() {
846 public Either<A, Character> f(final StringBuilder s) {
847 return fromString(s.toString()).toEither(a);
848 }
849 };
850 }
851 };
852 }
853
854 /**
855 * A function that converts string builders to strings.
856 */
857 public static final F<StringBuilder, String> StringBuilder_String = new F<StringBuilder, String>() {
858 public String f(final StringBuilder s) {
859 return s.toString();
860 }
861 };
862
863 /**
864 * A function that converts string builders to string buffers.
865 */
866 public static final F<StringBuilder, StringBuffer> StringBuilder_StringBuffer = new F<StringBuilder, StringBuffer>() {
867 public StringBuffer f(final StringBuilder s) {
868 return new StringBuffer(s);
869 }
870 };
871
872 // END StringBuilder ->
873
874
875 // BEGIN Try
876
877 public static <A, B, Z extends Exception> SafeIO<Validation<Z, A>> Try_SafeIO(Try0<A, Z> t) {
878 return F_SafeIO(u -> Try.f(t)._1());
879 }
880
881 public static <A, B, Z extends Exception> F<Try0<A, Z>, SafeIO<Validation<Z, A>>> Try_SafeIO() {
882 return t -> Try_SafeIO(t);
883 }
884
885 public static <A, B, Z extends IOException> IO<A> Try_IO(Try0<A, Z> t) {
886 return () -> t.f();
887 }
888
889 public static <A, B, Z extends IOException> F<Try0<A, Z>, IO<A>> Try_IO() {
890 return t -> Try_IO(t);
891 }
892
893 public static <A, B, Z extends IOException> F<A, Validation<Z, B>> Try_F(Try1<A, B, Z> t) {
894 return Try.f(t);
895 }
896
897 public static <A, B, Z extends IOException> F<Try1<A, B, Z>, F<A, Validation<Z, B>>> Try_F() {
898 return t -> Try_F(t);
899 }
900
901 // END Try
902
903 // BEGIN TryEffect
904
905 static public <E extends Exception> P1<Validation<E, Unit>> TryEffect_P(final TryEffect0<E> t) {
906 return TryEffect.f(t);
907 }
908
909
910 // END TryEffect
911
912 }