001    package fj.data;
002    
003    import fj.Effect;
004    import fj.F;
005    import static fj.P.p;
006    import fj.P1;
007    import fj.P2;
008    import static fj.data.List.list;
009    import static fj.data.Option.some;
010    
011    import java.util.ArrayList;
012    import java.util.BitSet;
013    import java.util.EnumSet;
014    import java.util.HashSet;
015    import java.util.LinkedHashSet;
016    import java.util.LinkedList;
017    import java.util.PriorityQueue;
018    import java.util.Stack;
019    import java.util.TreeSet;
020    import java.util.Vector;
021    import java.util.Iterator;
022    import java.util.NoSuchElementException;
023    import static java.util.EnumSet.copyOf;
024    import java.util.concurrent.ArrayBlockingQueue;
025    import java.util.concurrent.Callable;
026    import java.util.concurrent.ConcurrentLinkedQueue;
027    import java.util.concurrent.CopyOnWriteArrayList;
028    import java.util.concurrent.CopyOnWriteArraySet;
029    import java.util.concurrent.DelayQueue;
030    import java.util.concurrent.Delayed;
031    import java.util.concurrent.Future;
032    import java.util.concurrent.LinkedBlockingQueue;
033    import java.util.concurrent.PriorityBlockingQueue;
034    import java.util.concurrent.SynchronousQueue;
035    
036    /**
037     * Functions that convert between types from the core Java API.
038     *
039     * @version %build.number%<br>
040     *          <ul>
041     *          <li>$LastChangedRevision: 161 $</li>
042     *          <li>$LastChangedDate: 2009-06-01 17:14:38 +1000 (Mon, 01 Jun 2009) $</li>
043     *          </ul>
044     */
045    public final class Java {
046      private Java() {
047        throw new UnsupportedOperationException();
048      }
049    
050      // BEGIN List ->
051    
052      /**
053       * A function that converts lists to array lists.
054       *
055       * @return A function that converts lists to array lists.
056       */
057      public static <A> F<List<A>, ArrayList<A>> List_ArrayList() {
058        return new F<List<A>, ArrayList<A>>() {
059          public ArrayList<A> f(final List<A> as) {
060            return new ArrayList<A>(as.toCollection());
061          }
062        };
063      }
064    
065      /**
066       * A function that converts lists to bit sets.
067       */
068      public static final F<List<Boolean>, BitSet> List_BitSet = new F<List<Boolean>, BitSet>() {
069        public BitSet f(final List<Boolean> bs) {
070          final BitSet s = new BitSet(bs.length());
071          bs.zipIndex().foreach(new Effect<P2<Boolean, Integer>>() {
072            public void e(final P2<Boolean, Integer> bi) {
073              s.set(bi._2(), bi._1());
074            }
075          });
076          return s;
077        }
078      };
079    
080      /**
081       * A function that converts lists to array enum sets.
082       *
083       * @return A function that converts lists to enum sets.
084       */
085      public static <A extends Enum<A>> F<List<A>, EnumSet<A>> List_EnumSet() {
086        return new F<List<A>, EnumSet<A>>() {
087          public EnumSet<A> f(final List<A> as) {
088            return copyOf(as.toCollection());
089          }
090        };
091      }
092    
093      /**
094       * A function that converts lists to hash sets.
095       *
096       * @return A function that converts lists to hash sets.
097       */
098      public static <A> F<List<A>, HashSet<A>> List_HashSet() {
099        return new F<List<A>, HashSet<A>>() {
100          public HashSet<A> f(final List<A> as) {
101            return new HashSet<A>(as.toCollection());
102          }
103        };
104      }
105    
106      /**
107       * A function that converts lists to linked hash sets.
108       *
109       * @return A function that converts lists to linked hash sets.
110       */
111      public static <A> F<List<A>, LinkedHashSet<A>> List_LinkedHashSet() {
112        return new F<List<A>, LinkedHashSet<A>>() {
113          public LinkedHashSet<A> f(final List<A> as) {
114            return new LinkedHashSet<A>(as.toCollection());
115          }
116        };
117      }
118    
119      /**
120       * A function that converts lists to linked lists.
121       *
122       * @return A function that converts lists to linked lists.
123       */
124      public static <A> F<List<A>, LinkedList<A>> List_LinkedList() {
125        return new F<List<A>, LinkedList<A>>() {
126          public LinkedList<A> f(final List<A> as) {
127            return new LinkedList<A>(as.toCollection());
128          }
129        };
130      }
131    
132      /**
133       * A function that converts lists to priority queues.
134       *
135       * @return A function that converts lists to priority queues.
136       */
137      public static <A> F<List<A>, PriorityQueue<A>> List_PriorityQueue() {
138        return new F<List<A>, PriorityQueue<A>>() {
139          public PriorityQueue<A> f(final List<A> as) {
140            return new PriorityQueue<A>(as.toCollection());
141          }
142        };
143      }
144    
145      /**
146       * A function that converts lists to stacks.
147       *
148       * @return A function that converts lists to stacks.
149       */
150      public static <A> F<List<A>, Stack<A>> List_Stack() {
151        return new F<List<A>, Stack<A>>() {
152          public Stack<A> f(final List<A> as) {
153            final Stack<A> s = new Stack<A>();
154            s.addAll(as.toCollection());
155            return s;
156          }
157        };
158      }
159    
160      /**
161       * A function that converts lists to stacks.
162       *
163       * @return A function that converts lists to stacks.
164       */
165      public static <A> F<List<A>, TreeSet<A>> List_TreeSet() {
166        return new F<List<A>, TreeSet<A>>() {
167          public TreeSet<A> f(final List<A> as) {
168            return new TreeSet<A>(as.toCollection());
169          }
170        };
171      }
172    
173      /**
174       * A function that converts lists to vectors.
175       *
176       * @return A function that converts lists to vectors.
177       */
178      public static <A> F<List<A>, Vector<A>> List_Vector() {
179        return new F<List<A>, Vector<A>>() {
180          @SuppressWarnings({"UseOfObsoleteCollectionType"})
181          public Vector<A> f(final List<A> as) {
182            return new Vector<A>(as.toCollection());
183          }
184        };
185      }
186    
187      /**
188       * A function that converts lists to array blocking queue.
189       *
190       * @param fair The argument to pass to the constructor of the array blocking queue.
191       * @return A function that converts lists to array blocking queue.
192       */
193      public static <A> F<List<A>, ArrayBlockingQueue<A>> List_ArrayBlockingQueue(final boolean fair) {
194        return new F<List<A>, ArrayBlockingQueue<A>>() {
195          @SuppressWarnings({"UseOfObsoleteCollectionType"})
196          public ArrayBlockingQueue<A> f(final List<A> as) {
197            return new ArrayBlockingQueue<A>(as.length(), fair, as.toCollection());
198          }
199        };
200      }
201    
202      /**
203       * A function that converts lists to concurrent linked queues.
204       *
205       * @return A function that converts lists to concurrent linked queues.
206       */
207      public static <A> F<List<A>, ConcurrentLinkedQueue<A>> List_ConcurrentLinkedQueue() {
208        return new F<List<A>, ConcurrentLinkedQueue<A>>() {
209          @SuppressWarnings({"UseOfObsoleteCollectionType"})
210          public ConcurrentLinkedQueue<A> f(final List<A> as) {
211            return new ConcurrentLinkedQueue<A>(as.toCollection());
212          }
213        };
214      }
215    
216      /**
217       * A function that converts lists to copy on write array lists.
218       *
219       * @return A function that converts lists to copy on write array lists.
220       */
221      public static <A> F<List<A>, CopyOnWriteArrayList<A>> List_CopyOnWriteArrayList() {
222        return new F<List<A>, CopyOnWriteArrayList<A>>() {
223          @SuppressWarnings({"UseOfObsoleteCollectionType"})
224          public CopyOnWriteArrayList<A> f(final List<A> as) {
225            return new CopyOnWriteArrayList<A>(as.toCollection());
226          }
227        };
228      }
229    
230      /**
231       * A function that converts lists to copy on write array sets.
232       *
233       * @return A function that converts lists to copy on write array sets.
234       */
235      public static <A> F<List<A>, CopyOnWriteArraySet<A>> List_CopyOnWriteArraySet() {
236        return new F<List<A>, CopyOnWriteArraySet<A>>() {
237          @SuppressWarnings({"UseOfObsoleteCollectionType"})
238          public CopyOnWriteArraySet<A> f(final List<A> as) {
239            return new CopyOnWriteArraySet<A>(as.toCollection());
240          }
241        };
242      }
243    
244      /**
245       * A function that converts lists to delay queues.
246       *
247       * @return A function that converts lists to delay queues.
248       */
249      public static <A extends Delayed> F<List<A>, DelayQueue<A>> List_DelayQueue() {
250        return new F<List<A>, DelayQueue<A>>() {
251          @SuppressWarnings({"UseOfObsoleteCollectionType"})
252          public DelayQueue<A> f(final List<A> as) {
253            return new DelayQueue<A>(as.toCollection());
254          }
255        };
256      }
257    
258      /**
259       * A function that converts lists to linked blocking queues.
260       *
261       * @return A function that converts lists to linked blocking queues.
262       */
263      public static <A> F<List<A>, LinkedBlockingQueue<A>> List_LinkedBlockingQueue() {
264        return new F<List<A>, LinkedBlockingQueue<A>>() {
265          @SuppressWarnings({"UseOfObsoleteCollectionType"})
266          public LinkedBlockingQueue<A> f(final List<A> as) {
267            return new LinkedBlockingQueue<A>(as.toCollection());
268          }
269        };
270      }
271    
272      /**
273       * A function that converts lists to priority blocking queues.
274       *
275       * @return A function that converts lists to priority blocking queues.
276       */
277      public static <A> F<List<A>, PriorityBlockingQueue<A>> List_PriorityBlockingQueue() {
278        return new F<List<A>, PriorityBlockingQueue<A>>() {
279          @SuppressWarnings({"UseOfObsoleteCollectionType"})
280          public PriorityBlockingQueue<A> f(final List<A> as) {
281            return new PriorityBlockingQueue<A>(as.toCollection());
282          }
283        };
284      }
285    
286      /**
287       * A function that converts lists to synchronous queues.
288       *
289       * @param fair The argument to pass to the constructor of the synchronous queue.
290       * @return A function that converts lists to synchronous queues.
291       */
292      public static <A> F<List<A>, SynchronousQueue<A>> List_SynchronousQueue(final boolean fair) {
293        return new F<List<A>, SynchronousQueue<A>>() {
294          @SuppressWarnings({"UseOfObsoleteCollectionType"})
295          public SynchronousQueue<A> f(final List<A> as) {
296            final SynchronousQueue<A> q = new SynchronousQueue<A>(fair);
297            q.addAll(as.toCollection());
298            return q;
299          }
300        };
301      }
302    
303      // END List ->
304    
305      // BEGIN Array ->
306    
307      /**
308       * A function that converts arrays to array lists.
309       *
310       * @return A function that converts arrays to array lists.
311       */
312      public static <A> F<Array<A>, ArrayList<A>> Array_ArrayList() {
313        return new F<Array<A>, ArrayList<A>>() {
314          public ArrayList<A> f(final Array<A> as) {
315            return new ArrayList<A>(as.toCollection());
316          }
317        };
318      }
319    
320      /**
321       * A function that converts arrays to bit sets.
322       */
323      public static final F<Array<Boolean>, BitSet> Array_BitSet = new F<Array<Boolean>, BitSet>() {
324        public BitSet f(final Array<Boolean> bs) {
325          final BitSet s = new BitSet(bs.length());
326    
327          bs.zipIndex().foreach(new Effect<P2<Boolean, Integer>>() {
328            public void e(final P2<Boolean, Integer> bi) {
329              s.set(bi._2(), bi._1());
330            }
331          });
332          return s;
333        }
334      };
335    
336      /**
337       * A function that converts arrays to enum sets.
338       *
339       * @return A function that converts arrays to enum sets.
340       */
341      public static <A extends Enum<A>> F<Array<A>, EnumSet<A>> Array_EnumSet() {
342        return new F<Array<A>, EnumSet<A>>() {
343          public EnumSet<A> f(final Array<A> as) {
344            return copyOf(as.toCollection());
345          }
346        };
347      }
348    
349      /**
350       * A function that converts arrays to hash sets.
351       *
352       * @return A function that converts arrays to hash sets.
353       */
354      public static <A> F<Array<A>, HashSet<A>> Array_HashSet() {
355        return new F<Array<A>, HashSet<A>>() {
356          public HashSet<A> f(final Array<A> as) {
357            return new HashSet<A>(as.toCollection());
358          }
359        };
360      }
361    
362      /**
363       * A function that converts arrays to linked hash sets.
364       *
365       * @return A function that converts arrays to linked hash sets.
366       */
367      public static <A> F<Array<A>, LinkedHashSet<A>> Array_LinkedHashSet() {
368        return new F<Array<A>, LinkedHashSet<A>>() {
369          public LinkedHashSet<A> f(final Array<A> as) {
370            return new LinkedHashSet<A>(as.toCollection());
371          }
372        };
373      }
374    
375      /**
376       * A function that converts arrays to linked lists.
377       *
378       * @return A function that converts arrays to linked lists.
379       */
380      public static <A> F<Array<A>, LinkedList<A>> Array_LinkedList() {
381        return new F<Array<A>, LinkedList<A>>() {
382          public LinkedList<A> f(final Array<A> as) {
383            return new LinkedList<A>(as.toCollection());
384          }
385        };
386      }
387    
388      /**
389       * A function that converts arrays to priority queues.
390       *
391       * @return A function that converts arrays to priority queues.
392       */
393      public static <A> F<Array<A>, PriorityQueue<A>> Array_PriorityQueue() {
394        return new F<Array<A>, PriorityQueue<A>>() {
395          public PriorityQueue<A> f(final Array<A> as) {
396            return new PriorityQueue<A>(as.toCollection());
397          }
398        };
399      }
400    
401      /**
402       * A function that converts arrays to stacks.
403       *
404       * @return A function that converts arrays to stacks.
405       */
406      public static <A> F<Array<A>, Stack<A>> Array_Stack() {
407        return new F<Array<A>, Stack<A>>() {
408          public Stack<A> f(final Array<A> as) {
409            final Stack<A> s = new Stack<A>();
410            s.addAll(as.toCollection());
411            return s;
412          }
413        };
414      }
415    
416      /**
417       * A function that converts arrays to tree sets.
418       *
419       * @return A function that converts arrays to tree sets.
420       */
421      public static <A> F<Array<A>, TreeSet<A>> Array_TreeSet() {
422        return new F<Array<A>, TreeSet<A>>() {
423          public TreeSet<A> f(final Array<A> as) {
424            return new TreeSet<A>(as.toCollection());
425          }
426        };
427      }
428    
429      /**
430       * A function that converts arrays to vectors.
431       *
432       * @return A function that converts arrays to vectors.
433       */
434      public static <A> F<Array<A>, Vector<A>> Array_Vector() {
435        return new F<Array<A>, Vector<A>>() {
436          @SuppressWarnings({"UseOfObsoleteCollectionType"})
437          public Vector<A> f(final Array<A> as) {
438            return new Vector<A>(as.toCollection());
439          }
440        };
441      }
442    
443      /**
444       * A function that converts arrays to array blocking queues.
445       *
446       * @param fair The argument to pass to the constructor of the array blocking queue.
447       * @return A function that converts arrays to array blocking queues.
448       */
449      public static <A> F<Array<A>, ArrayBlockingQueue<A>> Array_ArrayBlockingQueue(final boolean fair) {
450        return new F<Array<A>, ArrayBlockingQueue<A>>() {
451          @SuppressWarnings({"UseOfObsoleteCollectionType"})
452          public ArrayBlockingQueue<A> f(final Array<A> as) {
453            return new ArrayBlockingQueue<A>(as.length(), fair, as.toCollection());
454          }
455        };
456      }
457    
458      /**
459       * A function that converts arrays to concurrent linked queues.
460       *
461       * @return A function that converts arrays to concurrent linked queues.
462       */
463      public static <A> F<Array<A>, ConcurrentLinkedQueue<A>> Array_ConcurrentLinkedQueue() {
464        return new F<Array<A>, ConcurrentLinkedQueue<A>>() {
465          @SuppressWarnings({"UseOfObsoleteCollectionType"})
466          public ConcurrentLinkedQueue<A> f(final Array<A> as) {
467            return new ConcurrentLinkedQueue<A>(as.toCollection());
468          }
469        };
470      }
471    
472      /**
473       * A function that converts arrays to copy on write array lists.
474       *
475       * @return A function that converts arrays to copy on write array lists.
476       */
477      public static <A> F<Array<A>, CopyOnWriteArrayList<A>> Array_CopyOnWriteArrayList() {
478        return new F<Array<A>, CopyOnWriteArrayList<A>>() {
479          @SuppressWarnings({"UseOfObsoleteCollectionType"})
480          public CopyOnWriteArrayList<A> f(final Array<A> as) {
481            return new CopyOnWriteArrayList<A>(as.toCollection());
482          }
483        };
484      }
485    
486      /**
487       * A function that converts arrays to copy on write array sets.
488       *
489       * @return A function that converts arrays to copy on write array sets.
490       */
491      public static <A> F<Array<A>, CopyOnWriteArraySet<A>> Array_CopyOnWriteArraySet() {
492        return new F<Array<A>, CopyOnWriteArraySet<A>>() {
493          @SuppressWarnings({"UseOfObsoleteCollectionType"})
494          public CopyOnWriteArraySet<A> f(final Array<A> as) {
495            return new CopyOnWriteArraySet<A>(as.toCollection());
496          }
497        };
498      }
499    
500      /**
501       * A function that converts arrays to delay queues.
502       *
503       * @return A function that converts arrays to delay queues.
504       */
505      public static <A extends Delayed> F<Array<A>, DelayQueue<A>> Array_DelayQueue() {
506        return new F<Array<A>, DelayQueue<A>>() {
507          @SuppressWarnings({"UseOfObsoleteCollectionType"})
508          public DelayQueue<A> f(final Array<A> as) {
509            return new DelayQueue<A>(as.toCollection());
510          }
511        };
512      }
513    
514      /**
515       * A function that converts arrays to linked blocking queues.
516       *
517       * @return A function that converts arrays to linked blocking queues.
518       */
519      public static <A> F<Array<A>, LinkedBlockingQueue<A>> Array_LinkedBlockingQueue() {
520        return new F<Array<A>, LinkedBlockingQueue<A>>() {
521          @SuppressWarnings({"UseOfObsoleteCollectionType"})
522          public LinkedBlockingQueue<A> f(final Array<A> as) {
523            return new LinkedBlockingQueue<A>(as.toCollection());
524          }
525        };
526      }
527    
528      /**
529       * A function that converts arrays to priority blocking queues.
530       *
531       * @return A function that converts arrays to priority blocking queues.
532       */
533      public static <A> F<Array<A>, PriorityBlockingQueue<A>> Array_PriorityBlockingQueue() {
534        return new F<Array<A>, PriorityBlockingQueue<A>>() {
535          @SuppressWarnings({"UseOfObsoleteCollectionType"})
536          public PriorityBlockingQueue<A> f(final Array<A> as) {
537            return new PriorityBlockingQueue<A>(as.toCollection());
538          }
539        };
540      }
541    
542      /**
543       * A function that converts arrays to synchronous queues.
544       *
545       * @param fair The argument to pass to the constructor of the synchronous queue.
546       * @return A function that converts arrays to synchronous queues.
547       */
548      public static <A> F<Array<A>, SynchronousQueue<A>> Array_SynchronousQueue(final boolean fair) {
549        return new F<Array<A>, SynchronousQueue<A>>() {
550          @SuppressWarnings({"UseOfObsoleteCollectionType"})
551          public SynchronousQueue<A> f(final Array<A> as) {
552            final SynchronousQueue<A> q = new SynchronousQueue<A>(fair);
553            q.addAll(as.toCollection());
554            return q;
555          }
556        };
557      }
558    
559      // END Array ->
560    
561      // BEGIN Stream ->
562    
563      /**
564       * A function that converts streams to iterable.
565       *
566       * @return A function that converts streams to iterable.
567       */
568      public static <A> F<Stream<A>, Iterable<A>> Stream_Iterable() {
569        return new F<Stream<A>, Iterable<A>>() {
570          public Iterable<A> f(final Stream<A> as) {
571            return new Iterable<A>() {
572              public Iterator<A> iterator() {
573                return new Iterator<A>() {
574                  private Stream<A> x = as;
575    
576                  public boolean hasNext() {
577                    return x.isNotEmpty();
578                  }
579    
580                  public A next() {
581                    if (x.isEmpty())
582                      throw new NoSuchElementException("Empty iterator");
583                    else {
584                      final A a = x.head();
585                      x = x.tail()._1();
586                      return a;
587                    }
588                  }
589    
590                  public void remove() {
591                    throw new UnsupportedOperationException();
592                  }
593                };
594              }
595            };
596          }
597        };
598      }
599    
600      /**
601       * A function that converts streams to array lists.
602       *
603       * @return A function that converts streams to array lists.
604       */
605      public static <A> F<Stream<A>, ArrayList<A>> Stream_ArrayList() {
606        return new F<Stream<A>, ArrayList<A>>() {
607          public ArrayList<A> f(final Stream<A> as) {
608            return new ArrayList<A>(as.toCollection());
609          }
610        };
611      }
612    
613      /**
614       * A function that converts streams to bit sets.
615       */
616      public static final F<Stream<Boolean>, BitSet> Stream_BitSet = new F<Stream<Boolean>, BitSet>() {
617        public BitSet f(final Stream<Boolean> bs) {
618          final BitSet s = new BitSet(bs.length());
619          bs.zipIndex().foreach(new Effect<P2<Boolean, Integer>>() {
620            public void e(final P2<Boolean, Integer> bi) {
621              s.set(bi._2(), bi._1());
622            }
623          });
624          return s;
625        }
626      };
627    
628      /**
629       * A function that converts streams to enum sets.
630       *
631       * @return A function that converts streams to enum sets.
632       */
633      public static <A extends Enum<A>> F<Stream<A>, EnumSet<A>> Stream_EnumSet() {
634        return new F<Stream<A>, EnumSet<A>>() {
635          public EnumSet<A> f(final Stream<A> as) {
636            return copyOf(as.toCollection());
637          }
638        };
639      }
640    
641      /**
642       * A function that converts streams to hash sets.
643       *
644       * @return A function that converts streams to hash sets.
645       */
646      public static <A> F<Stream<A>, HashSet<A>> Stream_HashSet() {
647        return new F<Stream<A>, HashSet<A>>() {
648          public HashSet<A> f(final Stream<A> as) {
649            return new HashSet<A>(as.toCollection());
650          }
651        };
652      }
653    
654      /**
655       * A function that converts streams to linked hash sets.
656       *
657       * @return A function that converts streams to linked hash sets.
658       */
659      public static <A> F<Stream<A>, LinkedHashSet<A>> Stream_LinkedHashSet() {
660        return new F<Stream<A>, LinkedHashSet<A>>() {
661          public LinkedHashSet<A> f(final Stream<A> as) {
662            return new LinkedHashSet<A>(as.toCollection());
663          }
664        };
665      }
666    
667      /**
668       * A function that converts streams to linked lists.
669       *
670       * @return A function that converts streams to linked lists.
671       */
672      public static <A> F<Stream<A>, LinkedList<A>> Stream_LinkedList() {
673        return new F<Stream<A>, LinkedList<A>>() {
674          public LinkedList<A> f(final Stream<A> as) {
675            return new LinkedList<A>(as.toCollection());
676          }
677        };
678      }
679    
680      /**
681       * A function that converts streams to priority queues.
682       *
683       * @return A function that converts streams to priority queues.
684       */
685      public static <A> F<Stream<A>, PriorityQueue<A>> Stream_PriorityQueue() {
686        return new F<Stream<A>, PriorityQueue<A>>() {
687          public PriorityQueue<A> f(final Stream<A> as) {
688            return new PriorityQueue<A>(as.toCollection());
689          }
690        };
691      }
692    
693      /**
694       * A function that converts streams to stacks.
695       *
696       * @return A function that converts streams to stacks.
697       */
698      public static <A> F<Stream<A>, Stack<A>> Stream_Stack() {
699        return new F<Stream<A>, Stack<A>>() {
700          public Stack<A> f(final Stream<A> as) {
701            final Stack<A> s = new Stack<A>();
702            s.addAll(as.toCollection());
703            return s;
704          }
705        };
706      }
707    
708      /**
709       * A function that converts streams to tree sets.
710       *
711       * @return A function that converts streams to tree sets.
712       */
713      public static <A> F<Stream<A>, TreeSet<A>> Stream_TreeSet() {
714        return new F<Stream<A>, TreeSet<A>>() {
715          public TreeSet<A> f(final Stream<A> as) {
716            return new TreeSet<A>(as.toCollection());
717          }
718        };
719      }
720    
721      /**
722       * A function that converts streams to vectors.
723       *
724       * @return A function that converts streams to vectors.
725       */
726      public static <A> F<Stream<A>, Vector<A>> Stream_Vector() {
727        return new F<Stream<A>, Vector<A>>() {
728          @SuppressWarnings({"UseOfObsoleteCollectionType"})
729          public Vector<A> f(final Stream<A> as) {
730            return new Vector<A>(as.toCollection());
731          }
732        };
733      }
734    
735      /**
736       * A function that converts streams to array blocking queues.
737       *
738       * @param fair The argument to pass to the constructor of the array blocking queue.
739       * @return A function that converts streams to array blocking queues.
740       */
741      public static <A> F<Stream<A>, ArrayBlockingQueue<A>> Stream_ArrayBlockingQueue(final boolean fair) {
742        return new F<Stream<A>, ArrayBlockingQueue<A>>() {
743          @SuppressWarnings({"UseOfObsoleteCollectionType"})
744          public ArrayBlockingQueue<A> f(final Stream<A> as) {
745            return new ArrayBlockingQueue<A>(as.length(), fair, as.toCollection());
746          }
747        };
748      }
749    
750      /**
751       * A function that converts streams to concurrent linked queues.
752       *
753       * @return A function that converts streams to concurrent linked queues.
754       */
755      public static <A> F<Stream<A>, ConcurrentLinkedQueue<A>> Stream_ConcurrentLinkedQueue() {
756        return new F<Stream<A>, ConcurrentLinkedQueue<A>>() {
757          @SuppressWarnings({"UseOfObsoleteCollectionType"})
758          public ConcurrentLinkedQueue<A> f(final Stream<A> as) {
759            return new ConcurrentLinkedQueue<A>(as.toCollection());
760          }
761        };
762      }
763    
764      /**
765       * A function that converts streams to copy on write array lists.
766       *
767       * @return A function that converts streams to copy on write array lists.
768       */
769      public static <A> F<Stream<A>, CopyOnWriteArrayList<A>> Stream_CopyOnWriteArrayList() {
770        return new F<Stream<A>, CopyOnWriteArrayList<A>>() {
771          @SuppressWarnings({"UseOfObsoleteCollectionType"})
772          public CopyOnWriteArrayList<A> f(final Stream<A> as) {
773            return new CopyOnWriteArrayList<A>(as.toCollection());
774          }
775        };
776      }
777    
778      /**
779       * A function that converts streams to copy on write array sets.
780       *
781       * @return A function that converts streams to copy on write array sets.
782       */
783      public static <A> F<Stream<A>, CopyOnWriteArraySet<A>> Stream_CopyOnWriteArraySet() {
784        return new F<Stream<A>, CopyOnWriteArraySet<A>>() {
785          @SuppressWarnings({"UseOfObsoleteCollectionType"})
786          public CopyOnWriteArraySet<A> f(final Stream<A> as) {
787            return new CopyOnWriteArraySet<A>(as.toCollection());
788          }
789        };
790      }
791    
792      /**
793       * A function that converts streams to delay queues.
794       *
795       * @return A function that converts streams to delay queues.
796       */
797      public static <A extends Delayed> F<Stream<A>, DelayQueue<A>> Stream_DelayQueue() {
798        return new F<Stream<A>, DelayQueue<A>>() {
799          @SuppressWarnings({"UseOfObsoleteCollectionType"})
800          public DelayQueue<A> f(final Stream<A> as) {
801            return new DelayQueue<A>(as.toCollection());
802          }
803        };
804      }
805    
806      /**
807       * A function that converts streams to linked blocking queues.
808       *
809       * @return A function that converts streams to linked blocking queues.
810       */
811      public static <A> F<Stream<A>, LinkedBlockingQueue<A>> Stream_LinkedBlockingQueue() {
812        return new F<Stream<A>, LinkedBlockingQueue<A>>() {
813          @SuppressWarnings({"UseOfObsoleteCollectionType"})
814          public LinkedBlockingQueue<A> f(final Stream<A> as) {
815            return new LinkedBlockingQueue<A>(as.toCollection());
816          }
817        };
818      }
819    
820      /**
821       * A function that converts streams to priority blocking queues.
822       *
823       * @return A function that converts streams to priority blocking queues.
824       */
825      public static <A> F<Stream<A>, PriorityBlockingQueue<A>> Stream_PriorityBlockingQueue() {
826        return new F<Stream<A>, PriorityBlockingQueue<A>>() {
827          @SuppressWarnings({"UseOfObsoleteCollectionType"})
828          public PriorityBlockingQueue<A> f(final Stream<A> as) {
829            return new PriorityBlockingQueue<A>(as.toCollection());
830          }
831        };
832      }
833    
834      /**
835       * A function that converts streams to synchronous queues.
836       *
837       * @param fair The argument to pass to the constructor of the synchronous queue.
838       * @return A function that converts streams to synchronous queues.
839       */
840      public static <A> F<Stream<A>, SynchronousQueue<A>> Stream_SynchronousQueue(final boolean fair) {
841        return new F<Stream<A>, SynchronousQueue<A>>() {
842          @SuppressWarnings({"UseOfObsoleteCollectionType"})
843          public SynchronousQueue<A> f(final Stream<A> as) {
844            final SynchronousQueue<A> q = new SynchronousQueue<A>(fair);
845            q.addAll(as.toCollection());
846            return q;
847          }
848        };
849      }
850    
851      // END Stream ->
852    
853      // BEGIN Option ->
854    
855      /**
856       * A function that converts options to array lists.
857       *
858       * @return A function that converts options to array lists.
859       */
860      public static <A> F<Option<A>, ArrayList<A>> Option_ArrayList() {
861        return new F<Option<A>, ArrayList<A>>() {
862          public ArrayList<A> f(final Option<A> as) {
863            return new ArrayList<A>(as.toCollection());
864          }
865        };
866      }
867    
868      /**
869       * A function that converts options to bit sets.
870       */
871      public static final F<Option<Boolean>, BitSet> Option_BitSet = new F<Option<Boolean>, BitSet>() {
872        public BitSet f(final Option<Boolean> bs) {
873          final BitSet s = new BitSet(bs.length());
874    
875          bs.foreach(new Effect<Boolean>() {
876            public void e(final Boolean b) {
877              if (b)
878                s.set(0);
879            }
880          });
881          return s;
882        }
883      };
884    
885      /**
886       * A function that converts options to enum sets.
887       *
888       * @return A function that converts options to enum sets.
889       */
890      public static <A extends Enum<A>> F<Option<A>, EnumSet<A>> Option_EnumSet() {
891        return new F<Option<A>, EnumSet<A>>() {
892          public EnumSet<A> f(final Option<A> as) {
893            return copyOf(as.toCollection());
894          }
895        };
896      }
897    
898      /**
899       * A function that converts options to hash sets.
900       *
901       * @return A function that converts options to hash sets.
902       */
903      public static <A> F<Option<A>, HashSet<A>> Option_HashSet() {
904        return new F<Option<A>, HashSet<A>>() {
905          public HashSet<A> f(final Option<A> as) {
906            return new HashSet<A>(as.toCollection());
907          }
908        };
909      }
910    
911      /**
912       * A function that converts options to linked hash sets.
913       *
914       * @return A function that converts options to linked hash sets.
915       */
916      public static <A> F<Option<A>, LinkedHashSet<A>> Option_LinkedHashSet() {
917        return new F<Option<A>, LinkedHashSet<A>>() {
918          public LinkedHashSet<A> f(final Option<A> as) {
919            return new LinkedHashSet<A>(as.toCollection());
920          }
921        };
922      }
923    
924      /**
925       * A function that converts options to linked lists.
926       *
927       * @return A function that converts options to linked lists.
928       */
929      public static <A> F<Option<A>, LinkedList<A>> Option_LinkedList() {
930        return new F<Option<A>, LinkedList<A>>() {
931          public LinkedList<A> f(final Option<A> as) {
932            return new LinkedList<A>(as.toCollection());
933          }
934        };
935      }
936    
937      /**
938       * A function that converts options to priority queues.
939       *
940       * @return A function that converts options to priority queues.
941       */
942      public static <A> F<Option<A>, PriorityQueue<A>> Option_PriorityQueue() {
943        return new F<Option<A>, PriorityQueue<A>>() {
944          public PriorityQueue<A> f(final Option<A> as) {
945            return new PriorityQueue<A>(as.toCollection());
946          }
947        };
948      }
949    
950      /**
951       * A function that converts options to stacks.
952       *
953       * @return A function that converts options to stacks.
954       */
955      public static <A> F<Option<A>, Stack<A>> Option_Stack() {
956        return new F<Option<A>, Stack<A>>() {
957          public Stack<A> f(final Option<A> as) {
958            final Stack<A> s = new Stack<A>();
959            s.addAll(as.toCollection());
960            return s;
961          }
962        };
963      }
964    
965      /**
966       * A function that converts options to tree sets.
967       *
968       * @return A function that converts options to tree sets.
969       */
970      public static <A> F<Option<A>, TreeSet<A>> Option_TreeSet() {
971        return new F<Option<A>, TreeSet<A>>() {
972          public TreeSet<A> f(final Option<A> as) {
973            return new TreeSet<A>(as.toCollection());
974          }
975        };
976      }
977    
978      /**
979       * A function that converts options to vectors.
980       *
981       * @return A function that converts options to vectors.
982       */
983      public static <A> F<Option<A>, Vector<A>> Option_Vector() {
984        return new F<Option<A>, Vector<A>>() {
985          @SuppressWarnings({"UseOfObsoleteCollectionType"})
986          public Vector<A> f(final Option<A> as) {
987            return new Vector<A>(as.toCollection());
988          }
989        };
990      }
991    
992      /**
993       * A function that converts options to array blocking queues.
994       *
995       * @param fair The argument to pass to the constructor of the array blocking queue.
996       * @return A function that converts options to array blocking queues.
997       */
998      public static <A> F<Option<A>, ArrayBlockingQueue<A>> Option_ArrayBlockingQueue(final boolean fair) {
999        return new F<Option<A>, ArrayBlockingQueue<A>>() {
1000          @SuppressWarnings({"UseOfObsoleteCollectionType"})
1001          public ArrayBlockingQueue<A> f(final Option<A> as) {
1002            return new ArrayBlockingQueue<A>(as.length(), fair, as.toCollection());
1003          }
1004        };
1005      }
1006    
1007      /**
1008       * A function that converts options to concurrent linked queues.
1009       *
1010       * @return A function that converts options to concurrent linked queues.
1011       */
1012      public static <A> F<Option<A>, ConcurrentLinkedQueue<A>> Option_ConcurrentLinkedQueue() {
1013        return new F<Option<A>, ConcurrentLinkedQueue<A>>() {
1014          @SuppressWarnings({"UseOfObsoleteCollectionType"})
1015          public ConcurrentLinkedQueue<A> f(final Option<A> as) {
1016            return new ConcurrentLinkedQueue<A>(as.toCollection());
1017          }
1018        };
1019      }
1020    
1021      /**
1022       * A function that converts options to copy on write array lists.
1023       *
1024       * @return A function that converts options to copy on write array lists.
1025       */
1026      public static <A> F<Option<A>, CopyOnWriteArrayList<A>> Option_CopyOnWriteArrayList() {
1027        return new F<Option<A>, CopyOnWriteArrayList<A>>() {
1028          @SuppressWarnings({"UseOfObsoleteCollectionType"})
1029          public CopyOnWriteArrayList<A> f(final Option<A> as) {
1030            return new CopyOnWriteArrayList<A>(as.toCollection());
1031          }
1032        };
1033      }
1034    
1035      /**
1036       * A function that converts options to copy on write array sets.
1037       *
1038       * @return A function that converts options to copy on write array sets.
1039       */
1040      public static <A> F<Option<A>, CopyOnWriteArraySet<A>> Option_CopyOnWriteArraySet() {
1041        return new F<Option<A>, CopyOnWriteArraySet<A>>() {
1042          @SuppressWarnings({"UseOfObsoleteCollectionType"})
1043          public CopyOnWriteArraySet<A> f(final Option<A> as) {
1044            return new CopyOnWriteArraySet<A>(as.toCollection());
1045          }
1046        };
1047      }
1048    
1049      /**
1050       * A function that converts options to delay queues.
1051       *
1052       * @return A function that converts options to delay queues.
1053       */
1054      public static <A extends Delayed> F<Option<A>, DelayQueue<A>> Option_DelayQueue() {
1055        return new F<Option<A>, DelayQueue<A>>() {
1056          @SuppressWarnings({"UseOfObsoleteCollectionType"})
1057          public DelayQueue<A> f(final Option<A> as) {
1058            return new DelayQueue<A>(as.toCollection());
1059          }
1060        };
1061      }
1062    
1063      /**
1064       * A function that converts options to linked blocking queues.
1065       *
1066       * @return A function that converts options to linked blocking queues.
1067       */
1068      public static <A> F<Option<A>, LinkedBlockingQueue<A>> Option_LinkedBlockingQueue() {
1069        return new F<Option<A>, LinkedBlockingQueue<A>>() {
1070          @SuppressWarnings({"UseOfObsoleteCollectionType"})
1071          public LinkedBlockingQueue<A> f(final Option<A> as) {
1072            return new LinkedBlockingQueue<A>(as.toCollection());
1073          }
1074        };
1075      }
1076    
1077      /**
1078       * A function that converts options to priority blocking queues.
1079       *
1080       * @return A function that converts options to priority blocking queues.
1081       */
1082      public static <A> F<Option<A>, PriorityBlockingQueue<A>> Option_PriorityBlockingQueue() {
1083        return new F<Option<A>, PriorityBlockingQueue<A>>() {
1084          @SuppressWarnings({"UseOfObsoleteCollectionType"})
1085          public PriorityBlockingQueue<A> f(final Option<A> as) {
1086            return new PriorityBlockingQueue<A>(as.toCollection());
1087          }
1088        };
1089      }
1090    
1091      /**
1092       * A function that converts options to synchronous queues.
1093       *
1094       * @param fair The argument to pass to the constructor of the synchronous queue.
1095       * @return A function that converts options to synchronous queues.
1096       */
1097      public static <A> F<Option<A>, SynchronousQueue<A>> Option_SynchronousQueue(final boolean fair) {
1098        return new F<Option<A>, SynchronousQueue<A>>() {
1099          @SuppressWarnings({"UseOfObsoleteCollectionType"})
1100          public SynchronousQueue<A> f(final Option<A> as) {
1101            final SynchronousQueue<A> q = new SynchronousQueue<A>(fair);
1102            q.addAll(as.toCollection());
1103            return q;
1104          }
1105        };
1106      }
1107    
1108      // END Option ->
1109    
1110      // BEGIN Either ->
1111    
1112      /**
1113       * A function that converts eithers to array lists.
1114       *
1115       * @return A function that converts eithers to array lists.
1116       */
1117      public static <A, B> F<Either<A, B>, ArrayList<A>> Either_ArrayListA() {
1118        return fj.Function.compose(Java.<A>Option_ArrayList(), Conversions.<A, B>Either_OptionA());
1119      }
1120    
1121      /**
1122       * A function that converts eithers to array lists.
1123       *
1124       * @return A function that converts eithers to array lists.
1125       */
1126      public static <A, B> F<Either<A, B>, ArrayList<B>> Either_ArrayListB() {
1127        return fj.Function.compose(Java.<B>Option_ArrayList(), Conversions.<A, B>Either_OptionB());
1128      }
1129    
1130      /**
1131       * A function that converts eithers to bit sets.
1132       *
1133       * @return A function that converts eithers to bit sets.
1134       */
1135      public static <B> F<Either<Boolean, B>, BitSet> Either_BitSetA() {
1136        return fj.Function.compose(Java.Option_BitSet, Conversions.<Boolean, B>Either_OptionA());
1137      }
1138    
1139      /**
1140       * A function that converts eithers to bit sets.
1141       *
1142       * @return A function that converts eithers to bit sets.
1143       */
1144      public static <A> F<Either<A, Boolean>, BitSet> Either_BitSetB() {
1145        return fj.Function.compose(Java.Option_BitSet, Conversions.<A, Boolean>Either_OptionB());
1146      }
1147    
1148      /**
1149       * A function that converts eithers to enum sets.
1150       *
1151       * @return A function that converts eithers to enum sets.
1152       */
1153      public static <A extends Enum<A>, B> F<Either<A, B>, EnumSet<A>> Either_EnumSetA() {
1154        return fj.Function.compose(Java.<A>Option_EnumSet(), Conversions.<A, B>Either_OptionA());
1155      }
1156    
1157      /**
1158       * A function that converts eithers to enum sets.
1159       *
1160       * @return A function that converts eithers to enum sets.
1161       */
1162      public static <A, B extends Enum<B>> F<Either<A, B>, EnumSet<B>> Either_EnumSetB() {
1163        return fj.Function.compose(Java.<B>Option_EnumSet(), Conversions.<A, B>Either_OptionB());
1164      }
1165    
1166      /**
1167       * A function that converts eithers to hash sets.
1168       *
1169       * @return A function that converts eithers to hash sets.
1170       */
1171      public static <A, B> F<Either<A, B>, HashSet<A>> Either_HashSetA() {
1172        return fj.Function.compose(Java.<A>Option_HashSet(), Conversions.<A, B>Either_OptionA());
1173      }
1174    
1175      /**
1176       * A function that converts eithers to hash sets.
1177       *
1178       * @return A function that converts eithers to hash sets.
1179       */
1180      public static <A, B> F<Either<A, B>, HashSet<B>> Either_HashSetB() {
1181        return fj.Function.compose(Java.<B>Option_HashSet(), Conversions.<A, B>Either_OptionB());
1182      }
1183    
1184      /**
1185       * A function that converts eithers to linked hash sets.
1186       *
1187       * @return A function that converts eithers to linked hash sets.
1188       */
1189      public static <A, B> F<Either<A, B>, LinkedHashSet<A>> Either_LinkedHashSetA() {
1190        return fj.Function.compose(Java.<A>Option_LinkedHashSet(), Conversions.<A, B>Either_OptionA());
1191      }
1192    
1193      /**
1194       * A function that converts eithers to linked hash sets.
1195       *
1196       * @return A function that converts eithers to linked hash sets.
1197       */
1198      public static <A, B> F<Either<A, B>, LinkedHashSet<B>> Either_LinkedHashSetB() {
1199        return fj.Function.compose(Java.<B>Option_LinkedHashSet(), Conversions.<A, B>Either_OptionB());
1200      }
1201    
1202      /**
1203       * A function that converts eithers to linked lists.
1204       *
1205       * @return A function that converts eithers to linked lists.
1206       */
1207      public static <A, B> F<Either<A, B>, LinkedList<A>> Either_LinkedListA() {
1208        return fj.Function.compose(Java.<A>Option_LinkedList(), Conversions.<A, B>Either_OptionA());
1209      }
1210    
1211      /**
1212       * A function that converts eithers to priority queues.
1213       *
1214       * @return A function that eithers options to priority queues.
1215       */
1216      public static <A, B> F<Either<A, B>, PriorityQueue<A>> Option_PriorityQueueA() {
1217        return fj.Function.compose(Java.<A>Option_PriorityQueue(), Conversions.<A, B>Either_OptionA());
1218      }
1219    
1220      /**
1221       * A function that converts eithers to priority queues.
1222       *
1223       * @return A function that eithers options to priority queues.
1224       */
1225      public static <A, B> F<Either<A, B>, PriorityQueue<B>> Option_PriorityQueueB() {
1226        return fj.Function.compose(Java.<B>Option_PriorityQueue(), Conversions.<A, B>Either_OptionB());
1227      }
1228    
1229      /**
1230       * A function that converts eithers to linked lists.
1231       *
1232       * @return A function that converts eithers to linked lists.
1233       */
1234      public static <A, B> F<Either<A, B>, LinkedList<B>> Either_LinkedListB() {
1235        return fj.Function.compose(Java.<B>Option_LinkedList(), Conversions.<A, B>Either_OptionB());
1236      }
1237    
1238      /**
1239       * A function that converts eithers to stacks.
1240       *
1241       * @return A function that converts eithers to stacks.
1242       */
1243      public static <A, B> F<Either<A, B>, Stack<A>> Either_StackA() {
1244        return fj.Function.compose(Java.<A>Option_Stack(), Conversions.<A, B>Either_OptionA());
1245      }
1246    
1247      /**
1248       * A function that converts eithers to stacks.
1249       *
1250       * @return A function that converts eithers to stacks.
1251       */
1252      public static <A, B> F<Either<A, B>, Stack<B>> Either_StackB() {
1253        return fj.Function.compose(Java.<B>Option_Stack(), Conversions.<A, B>Either_OptionB());
1254      }
1255    
1256      /**
1257       * A function that converts eithers to tree sets.
1258       *
1259       * @return A function that converts eithers to tree sets.
1260       */
1261      public static <A, B> F<Either<A, B>, TreeSet<A>> Either_TreeSetA() {
1262        return fj.Function.compose(Java.<A>Option_TreeSet(), Conversions.<A, B>Either_OptionA());
1263      }
1264    
1265      /**
1266       * A function that converts eithers to tree sets.
1267       *
1268       * @return A function that converts eithers to tree sets.
1269       */
1270      public static <A, B> F<Either<A, B>, TreeSet<B>> Either_TreeSetB() {
1271        return fj.Function.compose(Java.<B>Option_TreeSet(), Conversions.<A, B>Either_OptionB());
1272      }
1273    
1274      /**
1275       * A function that converts eithers to vectors.
1276       *
1277       * @return A function that converts eithers to vectors.
1278       */
1279      public static <A, B> F<Either<A, B>, Vector<A>> Either_VectorA() {
1280        return fj.Function.compose(Java.<A>Option_Vector(), Conversions.<A, B>Either_OptionA());
1281      }
1282    
1283      /**
1284       * A function that converts eithers to vectors.
1285       *
1286       * @return A function that converts eithers to vectors.
1287       */
1288      public static <A, B> F<Either<A, B>, Vector<B>> Either_VectorB() {
1289        return fj.Function.compose(Java.<B>Option_Vector(), Conversions.<A, B>Either_OptionB());
1290      }
1291    
1292      /**
1293       * A function that converts eithers to array blocking queues.
1294       *
1295       * @param fair The argument to pass to the constructor of the array blocking queue.
1296       * @return A function that converts eithers to array blocking queues.
1297       */
1298      public static <A, B> F<Either<A, B>, ArrayBlockingQueue<A>> Either_ArrayBlockingQueueA(final boolean fair) {
1299        return fj.Function.compose(Java.<A>Option_ArrayBlockingQueue(fair), Conversions.<A, B>Either_OptionA());
1300      }
1301    
1302      /**
1303       * A function that converts eithers to array blocking queues.
1304       *
1305       * @param fair The argument to pass to the constructor of the array blocking queue.
1306       * @return A function that converts eithers to array blocking queues.
1307       */
1308      public static <A, B> F<Either<A, B>, ArrayBlockingQueue<B>> Either_ArrayBlockingQueueB(final boolean fair) {
1309        return fj.Function.compose(Java.<B>Option_ArrayBlockingQueue(fair), Conversions.<A, B>Either_OptionB());
1310      }
1311    
1312      /**
1313       * A function that converts eithers to concurrent linked queues.
1314       *
1315       * @return A function that converts eithers to concurrent linked queues.
1316       */
1317      public static <A, B> F<Either<A, B>, ConcurrentLinkedQueue<A>> Either_ConcurrentLinkedQueueA() {
1318        return fj.Function.compose(Java.<A>Option_ConcurrentLinkedQueue(), Conversions.<A, B>Either_OptionA());
1319      }
1320    
1321      /**
1322       * A function that converts eithers to concurrent linked queues.
1323       *
1324       * @return A function that converts eithers to concurrent linked queues.
1325       */
1326      public static <A, B> F<Either<A, B>, ConcurrentLinkedQueue<B>> Either_ConcurrentLinkedQueueB() {
1327        return fj.Function.compose(Java.<B>Option_ConcurrentLinkedQueue(), Conversions.<A, B>Either_OptionB());
1328      }
1329    
1330      /**
1331       * A function that converts eithers to copy on write array lists.
1332       *
1333       * @return A function that converts eithers to copy on write array lists.
1334       */
1335      public static <A, B> F<Either<A, B>, CopyOnWriteArrayList<A>> Either_CopyOnWriteArrayListA() {
1336        return fj.Function.compose(Java.<A>Option_CopyOnWriteArrayList(), Conversions.<A, B>Either_OptionA());
1337      }
1338    
1339      /**
1340       * A function that converts eithers to copy on write array lists.
1341       *
1342       * @return A function that converts eithers to copy on write array lists.
1343       */
1344      public static <A, B> F<Either<A, B>, CopyOnWriteArrayList<B>> Either_CopyOnWriteArrayListB() {
1345        return fj.Function.compose(Java.<B>Option_CopyOnWriteArrayList(), Conversions.<A, B>Either_OptionB());
1346      }
1347    
1348      /**
1349       * A function that converts eithers to copy on write array sets.
1350       *
1351       * @return A function that converts eithers to copy on write array sets.
1352       */
1353      public static <A, B> F<Either<A, B>, CopyOnWriteArraySet<A>> Either_CopyOnWriteArraySetA() {
1354        return fj.Function.compose(Java.<A>Option_CopyOnWriteArraySet(), Conversions.<A, B>Either_OptionA());
1355      }
1356    
1357      /**
1358       * A function that converts eithers to copy on write array sets.
1359       *
1360       * @return A function that converts eithers to copy on write array sets.
1361       */
1362      public static <A, B> F<Either<A, B>, CopyOnWriteArraySet<B>> Either_CopyOnWriteArraySetB() {
1363        return fj.Function.compose(Java.<B>Option_CopyOnWriteArraySet(), Conversions.<A, B>Either_OptionB());
1364      }
1365    
1366      /**
1367       * A function that converts eithers to delay queues.
1368       *
1369       * @return A function that converts eithers to delay queues.
1370       */
1371      public static <A extends Delayed, B> F<Either<A, B>, DelayQueue<A>> Either_DelayQueueA() {
1372        return fj.Function.compose(Java.<A>Option_DelayQueue(), Conversions.<A, B>Either_OptionA());
1373      }
1374    
1375      /**
1376       * A function that converts eithers to delay queues.
1377       *
1378       * @return A function that converts eithers to delay queues.
1379       */
1380      public static <A, B extends Delayed> F<Either<A, B>, DelayQueue<B>> Either_DelayQueueB() {
1381        return fj.Function.compose(Java.<B>Option_DelayQueue(), Conversions.<A, B>Either_OptionB());
1382      }
1383    
1384      /**
1385       * A function that converts eithers to linked blocking queues.
1386       *
1387       * @return A function that converts eithers to linked blocking queues.
1388       */
1389      public static <A, B> F<Either<A, B>, LinkedBlockingQueue<A>> Either_LinkedBlockingQueueA() {
1390        return fj.Function.compose(Java.<A>Option_LinkedBlockingQueue(), Conversions.<A, B>Either_OptionA());
1391      }
1392    
1393      /**
1394       * A function that converts eithers to linked blocking queues.
1395       *
1396       * @return A function that converts eithers to linked blocking queues.
1397       */
1398      public static <A, B> F<Either<A, B>, LinkedBlockingQueue<B>> Either_LinkedBlockingQueueB() {
1399        return fj.Function.compose(Java.<B>Option_LinkedBlockingQueue(), Conversions.<A, B>Either_OptionB());
1400      }
1401    
1402      /**
1403       * A function that converts eithers to priority blocking queues.
1404       *
1405       * @return A function that converts eithers to priority blocking queues.
1406       */
1407      public static <A, B> F<Either<A, B>, PriorityBlockingQueue<A>> Either_PriorityBlockingQueueA() {
1408        return fj.Function.compose(Java.<A>Option_PriorityBlockingQueue(), Conversions.<A, B>Either_OptionA());
1409      }
1410    
1411      /**
1412       * A function that converts eithers to priority blocking queues.
1413       *
1414       * @return A function that converts eithers to priority blocking queues.
1415       */
1416      public static <A, B> F<Either<A, B>, PriorityBlockingQueue<B>> Either_PriorityBlockingQueueB() {
1417        return fj.Function.compose(Java.<B>Option_PriorityBlockingQueue(), Conversions.<A, B>Either_OptionB());
1418      }
1419    
1420      /**
1421       * A function that converts eithers to synchronous queues.
1422       *
1423       * @param fair The argument to pass to the constructor of the synchronous queue.
1424       * @return A function that converts eithers to synchronous queues.
1425       */
1426      public static <A, B> F<Either<A, B>, SynchronousQueue<A>> Either_SynchronousQueueA(final boolean fair) {
1427        return fj.Function.compose(Java.<A>Option_SynchronousQueue(fair), Conversions.<A, B>Either_OptionA());
1428      }
1429    
1430      /**
1431       * A function that converts eithers to synchronous queues.
1432       *
1433       * @param fair The argument to pass to the constructor of the synchronous queue.
1434       * @return A function that converts eithers to synchronous queues.
1435       */
1436      public static <A, B> F<Either<A, B>, SynchronousQueue<B>> Either_SynchronousQueueB(final boolean fair) {
1437        return fj.Function.compose(Java.<B>Option_SynchronousQueue(fair), Conversions.<A, B>Either_OptionB());
1438      }
1439    
1440      // END Either ->
1441    
1442      // BEGIN String ->
1443    
1444      /**
1445       * A function that converts strings to array lists.
1446       */
1447      public static final F<String, ArrayList<Character>> String_ArrayList =
1448          fj.Function.compose(Java.<Character>List_ArrayList(), Conversions.String_List);
1449    
1450      /**
1451       * A function that converts strings to hash sets.
1452       */
1453      public static final F<String, HashSet<Character>> String_HashSet =
1454          fj.Function.compose(Java.<Character>List_HashSet(), Conversions.String_List);
1455    
1456      /**
1457       * A function that converts strings to linked hash sets.
1458       */
1459      public static final F<String, LinkedHashSet<Character>> String_LinkedHashSet =
1460          fj.Function.compose(Java.<Character>List_LinkedHashSet(), Conversions.String_List);
1461    
1462      /**
1463       * A function that converts strings to linked lists.
1464       */
1465      public static final F<String, LinkedList<Character>> String_LinkedList =
1466          fj.Function.compose(Java.<Character>List_LinkedList(), Conversions.String_List);
1467    
1468      /**
1469       * A function that converts strings to priority queues.
1470       */
1471      public static final F<String, PriorityQueue<Character>> String_PriorityQueue =
1472          fj.Function.compose(Java.<Character>List_PriorityQueue(), Conversions.String_List);
1473    
1474      /**
1475       * A function that converts strings to stacks.
1476       */
1477      public static final F<String, Stack<Character>> String_Stack =
1478          fj.Function.compose(Java.<Character>List_Stack(), Conversions.String_List);
1479    
1480      /**
1481       * A function that converts strings to tree sets.
1482       */
1483      public static final F<String, TreeSet<Character>> String_TreeSet =
1484          fj.Function.compose(Java.<Character>List_TreeSet(), Conversions.String_List);
1485    
1486      /**
1487       * A function that converts strings to vectors.
1488       */
1489      public static final F<String, Vector<Character>> String_Vector =
1490          fj.Function.compose(Java.<Character>List_Vector(), Conversions.String_List);
1491    
1492      /**
1493       * A function that converts strings to array blocking queues.
1494       *
1495       * @param fair The argument to pass to the constructor of the array blocking queue.
1496       * @return A function that converts strings to array blocking queues.
1497       */
1498      public static F<String, ArrayBlockingQueue<Character>> String_ArrayBlockingQueue(final boolean fair) {
1499        return fj.Function.compose(Java.<Character>List_ArrayBlockingQueue(fair), Conversions.String_List);
1500      }
1501    
1502      /**
1503       * A function that converts strings to concurrent linked queues.
1504       */
1505      public static final F<String, ConcurrentLinkedQueue<Character>> String_ConcurrentLinkedQueue =
1506          fj.Function.compose(Java.<Character>List_ConcurrentLinkedQueue(), Conversions.String_List);
1507    
1508      /**
1509       * A function that converts strings to copy on write array lists.
1510       */
1511      public static final F<String, CopyOnWriteArrayList<Character>> String_CopyOnWriteArrayList =
1512          fj.Function.compose(Java.<Character>List_CopyOnWriteArrayList(), Conversions.String_List);
1513    
1514      /**
1515       * A function that converts strings to copy on write array sets.
1516       */
1517      public static final F<String, CopyOnWriteArraySet<Character>> String_CopyOnWriteArraySet =
1518          fj.Function.compose(Java.<Character>List_CopyOnWriteArraySet(), Conversions.String_List);
1519    
1520      /**
1521       * A function that converts strings to linked blocking queues.
1522       */
1523      public static final F<String, LinkedBlockingQueue<Character>> String_LinkedBlockingQueue =
1524          fj.Function.compose(Java.<Character>List_LinkedBlockingQueue(), Conversions.String_List);
1525    
1526      /**
1527       * A function that converts strings to priority blocking queues.
1528       */
1529      public static final F<String, PriorityBlockingQueue<Character>> String_PriorityBlockingQueue =
1530          fj.Function.compose(Java.<Character>List_PriorityBlockingQueue(), Conversions.String_List);
1531    
1532      /**
1533       * A function that converts strings to synchronous queues.
1534       *
1535       * @param fair The argument to pass to the constructor of the synchronous queue.
1536       * @return A function that converts strings to synchronous queues.
1537       */
1538      public static F<String, SynchronousQueue<Character>> String_SynchronousQueue(final boolean fair) {
1539        return fj.Function.compose(Java.<Character>List_SynchronousQueue(fair), Conversions.String_List);
1540      }
1541    
1542      // END String ->
1543    
1544      // BEGIN StringBuffer ->
1545    
1546      /**
1547       * A function that converts string buffers to array lists.
1548       */
1549      public static final F<StringBuffer, ArrayList<Character>> StringBuffer_ArrayList =
1550          fj.Function.compose(Java.<Character>List_ArrayList(), Conversions.StringBuffer_List);
1551    
1552      /**
1553       * A function that converts string buffers to hash sets.
1554       */
1555      public static final F<StringBuffer, HashSet<Character>> StringBuffer_HashSet =
1556          fj.Function.compose(Java.<Character>List_HashSet(), Conversions.StringBuffer_List);
1557    
1558      /**
1559       * A function that converts string buffers to linked hash sets.
1560       */
1561      public static final F<StringBuffer, LinkedHashSet<Character>> StringBuffer_LinkedHashSet =
1562          fj.Function.compose(Java.<Character>List_LinkedHashSet(), Conversions.StringBuffer_List);
1563    
1564      /**
1565       * A function that converts string buffers to linked lists.
1566       */
1567      public static final F<StringBuffer, LinkedList<Character>> StringBuffer_LinkedList =
1568          fj.Function.compose(Java.<Character>List_LinkedList(), Conversions.StringBuffer_List);
1569    
1570      /**
1571       * A function that converts string buffers to priority queues.
1572       */
1573      public static final F<StringBuffer, PriorityQueue<Character>> StringBuffer_PriorityQueue =
1574          fj.Function.compose(Java.<Character>List_PriorityQueue(), Conversions.StringBuffer_List);
1575    
1576      /**
1577       * A function that converts string buffers to stacks.
1578       */
1579      public static final F<StringBuffer, Stack<Character>> StringBuffer_Stack =
1580          fj.Function.compose(Java.<Character>List_Stack(), Conversions.StringBuffer_List);
1581    
1582      /**
1583       * A function that converts string buffers to tree sets.
1584       */
1585      public static final F<StringBuffer, TreeSet<Character>> StringBuffer_TreeSet =
1586          fj.Function.compose(Java.<Character>List_TreeSet(), Conversions.StringBuffer_List);
1587    
1588      /**
1589       * A function that converts string buffers to vectors.
1590       */
1591      public static final F<StringBuffer, Vector<Character>> StringBuffer_Vector =
1592          fj.Function.compose(Java.<Character>List_Vector(), Conversions.StringBuffer_List);
1593    
1594      /**
1595       * A function that converts string buffers to array blocking queues.
1596       *
1597       * @param fair The argument to pass to the constructor of the array blocking queue.
1598       * @return A function that converts string buffers to array blocking queues.
1599       */
1600      public static F<StringBuffer, ArrayBlockingQueue<Character>> StringBuffer_ArrayBlockingQueue(final boolean fair) {
1601        return fj.Function.compose(Java.<Character>List_ArrayBlockingQueue(fair), Conversions.StringBuffer_List);
1602      }
1603    
1604      /**
1605       * A function that converts string buffers to concurrent linked queues.
1606       */
1607      public static final F<StringBuffer, ConcurrentLinkedQueue<Character>> StringBuffer_ConcurrentLinkedQueue =
1608          fj.Function.compose(Java.<Character>List_ConcurrentLinkedQueue(), Conversions.StringBuffer_List);
1609    
1610      /**
1611       * A function that converts string buffers to copy on write array lists.
1612       */
1613      public static final F<StringBuffer, CopyOnWriteArrayList<Character>> StringBuffer_CopyOnWriteArrayList =
1614          fj.Function.compose(Java.<Character>List_CopyOnWriteArrayList(), Conversions.StringBuffer_List);
1615    
1616      /**
1617       * A function that converts string buffers to copy on write array sets.
1618       */
1619      public static final F<StringBuffer, CopyOnWriteArraySet<Character>> StringBuffer_CopyOnWriteArraySet =
1620          fj.Function.compose(Java.<Character>List_CopyOnWriteArraySet(), Conversions.StringBuffer_List);
1621    
1622      /**
1623       * A function that converts string buffers to linked blocking queues.
1624       */
1625      public static final F<StringBuffer, LinkedBlockingQueue<Character>> StringBuffer_LinkedBlockingQueue =
1626          fj.Function.compose(Java.<Character>List_LinkedBlockingQueue(), Conversions.StringBuffer_List);
1627    
1628      /**
1629       * A function that converts string buffers to priority blocking queues.
1630       */
1631      public static final F<StringBuffer, PriorityBlockingQueue<Character>> StringBuffer_PriorityBlockingQueue =
1632          fj.Function.compose(Java.<Character>List_PriorityBlockingQueue(), Conversions.StringBuffer_List);
1633    
1634      /**
1635       * A function that converts string buffers to synchronous queues.
1636       *
1637       * @param fair The argument to pass to the constructor of the synchronous queue.
1638       * @return A function that converts string buffers to synchronous queues.
1639       */
1640      public static F<StringBuffer, SynchronousQueue<Character>> StringBuffer_SynchronousQueue(final boolean fair) {
1641        return fj.Function.compose(Java.<Character>List_SynchronousQueue(fair), Conversions.StringBuffer_List);
1642      }
1643    
1644      // END StringBuffer ->
1645    
1646      // BEGIN StringBuilder ->
1647    
1648      /**
1649       * A function that converts string builders to array lists.
1650       */
1651      public static final F<StringBuilder, ArrayList<Character>> StringBuilder_ArrayList =
1652          fj.Function.compose(Java.<Character>List_ArrayList(), Conversions.StringBuilder_List);
1653    
1654      /**
1655       * A function that converts string builders to hash sets.
1656       */
1657      public static final F<StringBuilder, HashSet<Character>> StringBuilder_HashSet =
1658          fj.Function.compose(Java.<Character>List_HashSet(), Conversions.StringBuilder_List);
1659    
1660      /**
1661       * A function that converts string builders to linked hash sets.
1662       */
1663      public static final F<StringBuilder, LinkedHashSet<Character>> StringBuilder_LinkedHashSet =
1664          fj.Function.compose(Java.<Character>List_LinkedHashSet(), Conversions.StringBuilder_List);
1665    
1666      /**
1667       * A function that converts string builders to linked lists.
1668       */
1669      public static final F<StringBuilder, LinkedList<Character>> StringBuilder_LinkedList =
1670          fj.Function.compose(Java.<Character>List_LinkedList(), Conversions.StringBuilder_List);
1671    
1672      /**
1673       * A function that converts string builders to priority queues.
1674       */
1675      public static final F<StringBuilder, PriorityQueue<Character>> StringBuilder_PriorityQueue =
1676          fj.Function.compose(Java.<Character>List_PriorityQueue(), Conversions.StringBuilder_List);
1677    
1678      /**
1679       * A function that converts string builders to stacks.
1680       */
1681      public static final F<StringBuilder, Stack<Character>> StringBuilder_Stack =
1682          fj.Function.compose(Java.<Character>List_Stack(), Conversions.StringBuilder_List);
1683    
1684      /**
1685       * A function that converts string builders to tree sets.
1686       */
1687      public static final F<StringBuilder, TreeSet<Character>> StringBuilder_TreeSet =
1688          fj.Function.compose(Java.<Character>List_TreeSet(), Conversions.StringBuilder_List);
1689    
1690      /**
1691       * A function that converts string builders to vectors.
1692       */
1693      public static final F<StringBuilder, Vector<Character>> StringBuilder_Vector =
1694          fj.Function.compose(Java.<Character>List_Vector(), Conversions.StringBuilder_List);
1695    
1696      /**
1697       * A function that converts string builders to array blocking queues.
1698       *
1699       * @param fair The argument to pass to the constructor of the array blocking queue.
1700       * @return A function that converts string builders to array blocking queues.
1701       */
1702      public static F<StringBuilder, ArrayBlockingQueue<Character>> StringBuilder_ArrayBlockingQueue(final boolean fair) {
1703        return fj.Function.compose(Java.<Character>List_ArrayBlockingQueue(fair), Conversions.StringBuilder_List);
1704      }
1705    
1706      /**
1707       * A function that converts string builders to concurrent linked queues.
1708       */
1709      public static final F<StringBuilder, ConcurrentLinkedQueue<Character>> StringBuilder_ConcurrentLinkedQueue =
1710          fj.Function.compose(Java.<Character>List_ConcurrentLinkedQueue(), Conversions.StringBuilder_List);
1711    
1712      /**
1713       * A function that converts string builders to copy on write array lists.
1714       */
1715      public static final F<StringBuilder, CopyOnWriteArrayList<Character>> StringBuilder_CopyOnWriteArrayList =
1716          fj.Function.compose(Java.<Character>List_CopyOnWriteArrayList(), Conversions.StringBuilder_List);
1717    
1718      /**
1719       * A function that converts string builders to copy on write array sets.
1720       */
1721      public static final F<StringBuilder, CopyOnWriteArraySet<Character>> StringBuilder_CopyOnWriteArraySet =
1722          fj.Function.compose(Java.<Character>List_CopyOnWriteArraySet(), Conversions.StringBuilder_List);
1723    
1724      /**
1725       * A function that converts string builders to linked blocking queues.
1726       */
1727      public static final F<StringBuilder, LinkedBlockingQueue<Character>> StringBuilder_LinkedBlockingQueue =
1728          fj.Function.compose(Java.<Character>List_LinkedBlockingQueue(), Conversions.StringBuilder_List);
1729    
1730      /**
1731       * A function that converts string builders to priority blocking queues.
1732       */
1733      public static final F<StringBuilder, PriorityBlockingQueue<Character>> StringBuilder_PriorityBlockingQueue =
1734          fj.Function.compose(Java.<Character>List_PriorityBlockingQueue(), Conversions.StringBuilder_List);
1735    
1736      /**
1737       * A function that converts string builders to synchronous queues.
1738       *
1739       * @param fair The argument to pass to the constructor of the synchronous queue.
1740       * @return A function that converts string builders to synchronous queues.
1741       */
1742      public static F<StringBuilder, SynchronousQueue<Character>> StringBuilder_SynchronousQueue(final boolean fair) {
1743        return fj.Function.compose(Java.<Character>List_SynchronousQueue(fair), Conversions.StringBuilder_List);
1744      }
1745    
1746      // END StringBuffer ->
1747    
1748      // BEGIN ArrayList ->
1749    
1750      /**
1751       * A function that converts array lists to lists.
1752       *
1753       * @return A function that converts array lists to lists.
1754       */
1755      public static <A> F<ArrayList<A>, List<A>> ArrayList_List() {
1756        return new F<ArrayList<A>, List<A>>() {
1757          @SuppressWarnings({"unchecked"})
1758          public List<A> f(final ArrayList<A> as) {
1759            return list(as.toArray((A[]) new Object[as.size()]));
1760          }
1761        };
1762      }
1763    
1764      // todo
1765    
1766      // END ArrayList ->
1767    
1768      // BEGIN BitSet ->
1769    
1770      /**
1771       * A function that converts bit sets to lists.
1772       */
1773      public static final F<BitSet, List<Boolean>> BitSet_List = new F<BitSet, List<Boolean>>() {
1774        public List<Boolean> f(final BitSet s) {
1775          return List.unfold(new F<Integer, Option<P2<Boolean, Integer>>>() {
1776            public Option<P2<Boolean, Integer>> f(final Integer i) {
1777              return i == s.length() ?
1778                  Option.<P2<Boolean, Integer>>none() :
1779                  some(p(s.get(i), i + 1));
1780            }
1781          }, 0);
1782        }
1783      };
1784    
1785      // todo
1786    
1787      // END BitSet ->
1788    
1789      // BEGIN EnumSet ->
1790    
1791      /**
1792       * A function that converts enum sets to lists.
1793       *
1794       * @return A function that converts enum sets to lists.
1795       */
1796      public static <A extends Enum<A>> F<EnumSet<A>, List<A>> EnumSet_List() {
1797        return new F<EnumSet<A>, List<A>>() {
1798          @SuppressWarnings({"unchecked"})
1799          public List<A> f(final EnumSet<A> as) {
1800            return list(as.toArray((A[]) new Object[as.size()]));
1801          }
1802        };
1803      }
1804    
1805      // todo
1806    
1807      // END EnumSet ->
1808    
1809      // BEGIN HashSet ->
1810    
1811      /**
1812       * A function that converts hash sets to lists.
1813       *
1814       * @return A function that converts hash sets to lists.
1815       */
1816      public static <A> F<HashSet<A>, List<A>> HashSet_List() {
1817        return new F<HashSet<A>, List<A>>() {
1818          @SuppressWarnings({"unchecked"})
1819          public List<A> f(final HashSet<A> as) {
1820            return list(as.toArray((A[]) new Object[as.size()]));
1821          }
1822        };
1823      }
1824    
1825      // todo
1826    
1827      // END HashSet ->
1828    
1829      // BEGIN LinkedHashSet ->
1830    
1831      /**
1832       * A function that converts linked hash sets to lists.
1833       *
1834       * @return A function that converts linked hash sets to lists.
1835       */
1836      public static <A> F<LinkedHashSet<A>, List<A>> LinkedHashSet_List() {
1837        return new F<LinkedHashSet<A>, List<A>>() {
1838          @SuppressWarnings({"unchecked"})
1839          public List<A> f(final LinkedHashSet<A> as) {
1840            return list(as.toArray((A[]) new Object[as.size()]));
1841          }
1842        };
1843      }
1844    
1845      // todo
1846    
1847      // END LinkedHashSet ->
1848    
1849      // BEGIN Linked List ->
1850    
1851      /**
1852       * A function that converts linked lists to lists.
1853       *
1854       * @return A function that converts linked lists to lists.
1855       */
1856      public static <A> F<LinkedList<A>, List<A>> LinkedList_List() {
1857        return new F<LinkedList<A>, List<A>>() {
1858          @SuppressWarnings({"unchecked"})
1859          public List<A> f(final LinkedList<A> as) {
1860            return list(as.toArray((A[]) new Object[as.size()]));
1861          }
1862        };
1863      }
1864    
1865      // todo
1866    
1867      // END Linked List ->
1868    
1869      // BEGIN PriorityQueue ->
1870    
1871      /**
1872       * A function that converts priority queues to lists.
1873       *
1874       * @return A function that converts priority queues to lists.
1875       */
1876      public static <A> F<PriorityQueue<A>, List<A>> PriorityQueue_List() {
1877        return new F<PriorityQueue<A>, List<A>>() {
1878          @SuppressWarnings({"unchecked"})
1879          public List<A> f(final PriorityQueue<A> as) {
1880            return list(as.toArray((A[]) new Object[as.size()]));
1881          }
1882        };
1883      }
1884    
1885      // todo
1886    
1887      // END PriorityQueue ->
1888    
1889      // BEGIN Stack ->
1890    
1891      /**
1892       * A function that converts stacks to lists.
1893       *
1894       * @return A function that converts stacks to lists.
1895       */
1896      public static <A> F<Stack<A>, List<A>> Stack_List() {
1897        return new F<Stack<A>, List<A>>() {
1898          @SuppressWarnings({"unchecked"})
1899          public List<A> f(final Stack<A> as) {
1900            return list(as.toArray((A[]) new Object[as.size()]));
1901          }
1902        };
1903      }
1904    
1905      // todo
1906    
1907      // END Stack ->
1908    
1909      // BEGIN TreeSet ->
1910    
1911      /**
1912       * A function that converts tree sets to lists.
1913       *
1914       * @return A function that converts tree sets to lists.
1915       */
1916      public static <A> F<TreeSet<A>, List<A>> TreeSet_List() {
1917        return new F<TreeSet<A>, List<A>>() {
1918          @SuppressWarnings({"unchecked"})
1919          public List<A> f(final TreeSet<A> as) {
1920            return list(as.toArray((A[]) new Object[as.size()]));
1921          }
1922        };
1923      }
1924    
1925      // todo
1926    
1927      // END TreeSet ->
1928    
1929      // BEGIN Vector ->
1930    
1931      /**
1932       * A function that converts vectors to lists.
1933       *
1934       * @return A function that converts vectors to lists.
1935       */
1936      public static <A> F<Vector<A>, List<A>> Vector_List() {
1937        return new F<Vector<A>, List<A>>() {
1938          @SuppressWarnings({"unchecked", "UseOfObsoleteCollectionType"})
1939          public List<A> f(final Vector<A> as) {
1940            return list(as.toArray((A[]) new Object[as.size()]));
1941          }
1942        };
1943      }
1944    
1945      // todo
1946    
1947      // END Vector ->
1948    
1949      // BEGIN ArrayBlockingQueue ->
1950    
1951      /**
1952       * A function that converts array blocking queues to lists.
1953       *
1954       * @return A function that converts array blocking queues to lists.
1955       */
1956      public static <A> F<ArrayBlockingQueue<A>, List<A>> ArrayBlockingQueue_List() {
1957        return new F<ArrayBlockingQueue<A>, List<A>>() {
1958          @SuppressWarnings({"unchecked"})
1959          public List<A> f(final ArrayBlockingQueue<A> as) {
1960            return list(as.toArray((A[]) new Object[as.size()]));
1961          }
1962        };
1963      }
1964    
1965      // todo
1966    
1967      // END ArrayBlockingQueue ->
1968    
1969      // BEGIN ConcurrentLinkedQueue ->
1970    
1971      /**
1972       * A function that converts concurrent linked queues to lists.
1973       *
1974       * @return A function that converts concurrent linked queues to lists.
1975       */
1976      public static <A> F<ConcurrentLinkedQueue<A>, List<A>> ConcurrentLinkedQueue_List() {
1977        return new F<ConcurrentLinkedQueue<A>, List<A>>() {
1978          @SuppressWarnings({"unchecked"})
1979          public List<A> f(final ConcurrentLinkedQueue<A> as) {
1980            return list(as.toArray((A[]) new Object[as.size()]));
1981          }
1982        };
1983      }
1984    
1985      // todo
1986    
1987      // END ConcurrentLinkedQueue ->
1988    
1989      // BEGIN CopyOnWriteArrayList ->
1990    
1991      /**
1992       * A function that converts copy on write array lists to lists.
1993       *
1994       * @return A function that converts copy on write array lists to lists.
1995       */
1996      public static <A> F<CopyOnWriteArrayList<A>, List<A>> CopyOnWriteArrayList_List() {
1997        return new F<CopyOnWriteArrayList<A>, List<A>>() {
1998          @SuppressWarnings({"unchecked"})
1999          public List<A> f(final CopyOnWriteArrayList<A> as) {
2000            return list(as.toArray((A[]) new Object[as.size()]));
2001          }
2002        };
2003      }
2004    
2005      // todo
2006    
2007      // END CopyOnWriteArrayList ->
2008    
2009      // BEGIN CopyOnWriteArraySet ->
2010    
2011      /**
2012       * A function that converts copy on write array sets to lists.
2013       *
2014       * @return A function that converts copy on write array sets to lists.
2015       */
2016      public static <A> F<CopyOnWriteArraySet<A>, List<A>> CopyOnWriteArraySet_List() {
2017        return new F<CopyOnWriteArraySet<A>, List<A>>() {
2018          @SuppressWarnings({"unchecked"})
2019          public List<A> f(final CopyOnWriteArraySet<A> as) {
2020            return list(as.toArray((A[]) new Object[as.size()]));
2021          }
2022        };
2023      }
2024    
2025      // todo
2026    
2027      // END CopyOnWriteArraySet ->
2028    
2029      // BEGIN DelayQueue ->
2030    
2031      /**
2032       * A function that converts delay queues to lists.
2033       *
2034       * @return A function that converts delay queues to lists.
2035       */
2036      public static <A extends Delayed> F<DelayQueue<A>, List<A>> DelayQueue_List() {
2037        return new F<DelayQueue<A>, List<A>>() {
2038          @SuppressWarnings({"unchecked"})
2039          public List<A> f(final DelayQueue<A> as) {
2040            return list(as.toArray((A[]) new Object[as.size()]));
2041          }
2042        };
2043      }
2044    
2045      // todo
2046    
2047      // END DelayQueue ->
2048    
2049      // BEGIN LinkedBlockingQueue ->
2050    
2051      /**
2052       * A function that converts linked blocking queues to lists.
2053       *
2054       * @return A function that converts linked blocking queues to lists.
2055       */
2056      public static <A> F<LinkedBlockingQueue<A>, List<A>> LinkedBlockingQueue_List() {
2057        return new F<LinkedBlockingQueue<A>, List<A>>() {
2058          @SuppressWarnings({"unchecked"})
2059          public List<A> f(final LinkedBlockingQueue<A> as) {
2060            return list(as.toArray((A[]) new Object[as.size()]));
2061          }
2062        };
2063      }
2064    
2065      // todo
2066    
2067      // END LinkedBlockingQueue ->
2068    
2069      // BEGIN PriorityBlockingQueue ->
2070    
2071      /**
2072       * A function that converts priority blocking queues to lists.
2073       *
2074       * @return A function that converts priority blocking queues to lists.
2075       */
2076      public static <A> F<PriorityBlockingQueue<A>, List<A>> PriorityBlockingQueue_List() {
2077        return new F<PriorityBlockingQueue<A>, List<A>>() {
2078          @SuppressWarnings({"unchecked"})
2079          public List<A> f(final PriorityBlockingQueue<A> as) {
2080            return list(as.toArray((A[]) new Object[as.size()]));
2081          }
2082        };
2083      }
2084    
2085      // todo
2086    
2087      // END PriorityBlockingQueue ->
2088    
2089      // BEGIN SynchronousQueue ->
2090    
2091      /**
2092       * A function that converts synchronous queues to lists.
2093       *
2094       * @return A function that converts synchronous queues to lists.
2095       */
2096      public static <A> F<SynchronousQueue<A>, List<A>> SynchronousQueue_List() {
2097        return new F<SynchronousQueue<A>, List<A>>() {
2098          @SuppressWarnings({"unchecked"})
2099          public List<A> f(final SynchronousQueue<A> as) {
2100            return list(as.toArray((A[]) new Object[as.size()]));
2101          }
2102        };
2103      }
2104    
2105      // todo
2106    
2107      // END SynchronousQueue ->
2108    
2109      // BEGIN Callable ->
2110    
2111      public static <A> F<P1<A>, Callable<A>> P1_Callable() {
2112        return new F<P1<A>, Callable<A>>() {
2113          public Callable<A> f(final P1<A> a) {
2114            return new Callable<A>() {
2115              public A call() {
2116                return a._1();
2117              }
2118            };
2119          }
2120        };
2121      }
2122    
2123    // END Callable ->
2124    
2125    // BEGIN Future ->
2126    
2127      public static <A> F<Future<A>, P1<Either<Exception, A>>> Future_P1() {
2128        return new F<Future<A>, P1<Either<Exception, A>>>() {
2129          public P1<Either<Exception, A>> f(final Future<A> a) {
2130            return new P1<Either<Exception, A>>() {
2131              public Either<Exception, A> _1() {
2132                Either<Exception, A> r;
2133                try {
2134                  r = Either.right(a.get());
2135                }
2136                catch (Exception e) {
2137                  r = Either.left(e);
2138                }
2139                return r;
2140              }
2141            };
2142          }
2143        };
2144      }
2145    
2146      // END Future ->
2147    }