All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fj.data.Java Maven / Gradle / Ivy

Go to download

Functional Java is an open source library that supports closures for the Java programming language

There is a newer version: 5.0
Show newest version
package fj.data;

import fj.*;

import static fj.P.p;

import fj.function.Effect1;

import static fj.data.List.list;
import static fj.data.Option.some;

import java.util.Arrays;
import java.util.Collection;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Stack;
import java.util.TreeSet;
import java.util.Vector;
import java.util.Iterator;
import java.util.NoSuchElementException;
import static java.util.EnumSet.copyOf;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.SynchronousQueue;

/**
 * Functions that convert between types from the core Java API.
 *
 * @version %build.number%
 */
public final class Java {
  private Java() {
    throw new UnsupportedOperationException();
  }

  // BEGIN List ->

  /**
   * A function that converts lists to array lists.
   *
   * @return A function that converts lists to array lists.
   */
  public static  F, ArrayList> List_ArrayList() {
    return as -> new ArrayList(as.toCollection());
  }

  /**
   * A function that converts lists to bit sets.
   */
  public static final F, BitSet> List_BitSet = bs -> {
    final BitSet s = new BitSet(bs.length());
    bs.zipIndex().foreachDoEffect(bi -> {
        s.set(bi._2(), bi._1());
    });
    return s;
  };

  /**
   * A function that converts lists to array enum sets.
   *
   * @return A function that converts lists to enum sets.
   */
  public static > F, EnumSet> List_EnumSet() {
    return as -> copyOf(as.toCollection());
  }

  /**
   * A function that converts lists to hash sets.
   *
   * @return A function that converts lists to hash sets.
   */
  public static  F, HashSet> List_HashSet() {
    return as -> new HashSet(as.toCollection());
  }

  /**
   * A function that converts lists to linked hash sets.
   *
   * @return A function that converts lists to linked hash sets.
   */
  public static  F, LinkedHashSet> List_LinkedHashSet() {
    return as -> new LinkedHashSet(as.toCollection());
  }

  /**
   * A function that converts lists to linked lists.
   *
   * @return A function that converts lists to linked lists.
   */
  public static  F, LinkedList> List_LinkedList() {
    return as -> new LinkedList(as.toCollection());
  }

  /**
   * A function that converts lists to priority queues.
   *
   * @return A function that converts lists to priority queues.
   */
  public static  F, PriorityQueue> List_PriorityQueue() {
    return as -> new PriorityQueue(as.toCollection());
  }

  /**
   * A function that converts lists to stacks.
   *
   * @return A function that converts lists to stacks.
   */
  public static  F, Stack> List_Stack() {
    return as -> {
      final Stack s = new Stack();
      s.addAll(as.toCollection());
      return s;
    };
  }

  /**
   * A function that converts lists to stacks.
   *
   * @return A function that converts lists to stacks.
   */
  public static  F, TreeSet> List_TreeSet() {
    return as -> new TreeSet(as.toCollection());
  }

  /**
   * A function that converts lists to vectors.
   *
   * @return A function that converts lists to vectors.
   */
  public static  F, Vector> List_Vector() {
    return as -> new Vector(as.toCollection());
  }

  /**
   * A function that converts lists to array blocking queue.
   *
   * @param fair The argument to pass to the constructor of the array blocking queue.
   * @return A function that converts lists to array blocking queue.
   */
  public static  F, ArrayBlockingQueue> List_ArrayBlockingQueue(final boolean fair) {
    return as -> new ArrayBlockingQueue(as.length(), fair, as.toCollection());
  }

  /**
   * A function that converts lists to concurrent linked queues.
   *
   * @return A function that converts lists to concurrent linked queues.
   */
  public static  F, ConcurrentLinkedQueue> List_ConcurrentLinkedQueue() {
    return as -> new ConcurrentLinkedQueue(as.toCollection());
  }

  /**
   * A function that converts lists to copy on write array lists.
   *
   * @return A function that converts lists to copy on write array lists.
   */
  public static  F, CopyOnWriteArrayList> List_CopyOnWriteArrayList() {
    return as -> new CopyOnWriteArrayList(as.toCollection());
  }

  /**
   * A function that converts lists to copy on write array sets.
   *
   * @return A function that converts lists to copy on write array sets.
   */
  public static  F, CopyOnWriteArraySet> List_CopyOnWriteArraySet() {
    return as -> new CopyOnWriteArraySet(as.toCollection());
  }

  /**
   * A function that converts lists to delay queues.
   *
   * @return A function that converts lists to delay queues.
   */
  public static  F, DelayQueue> List_DelayQueue() {
    return as -> new DelayQueue(as.toCollection());
  }

  /**
   * A function that converts lists to linked blocking queues.
   *
   * @return A function that converts lists to linked blocking queues.
   */
  public static  F, LinkedBlockingQueue> List_LinkedBlockingQueue() {
    return as -> new LinkedBlockingQueue(as.toCollection());
  }

  /**
   * A function that converts lists to priority blocking queues.
   *
   * @return A function that converts lists to priority blocking queues.
   */
  public static  F, PriorityBlockingQueue> List_PriorityBlockingQueue() {
    return as -> new PriorityBlockingQueue(as.toCollection());
  }

  /**
   * A function that converts lists to synchronous queues.
   *
   * @param fair The argument to pass to the constructor of the synchronous queue.
   * @return A function that converts lists to synchronous queues.
   */
  public static  F, SynchronousQueue> List_SynchronousQueue(final boolean fair) {
    return as -> {
      final SynchronousQueue q = new SynchronousQueue(fair);
      q.addAll(as.toCollection());
      return q;
    };
  }

  // END List ->

  // BEGIN Array ->

  /**
   * A function that converts arrays to array lists.
   *
   * @return A function that converts arrays to array lists.
   */
  public static  F, ArrayList> Array_ArrayList() {
    return as -> new ArrayList(as.toCollection());
  }

  /**
   * A function that converts arrays to bit sets.
   */
  public static final F, BitSet> Array_BitSet = bs -> {
    final BitSet s = new BitSet(bs.length());

    bs.zipIndex().foreachDoEffect(bi -> {
      s.set(bi._2(), bi._1());
    });
    return s;
  };

  /**
   * A function that converts arrays to enum sets.
   *
   * @return A function that converts arrays to enum sets.
   */
  public static > F, EnumSet> Array_EnumSet() {
    return as -> copyOf(as.toCollection());
  }

  /**
   * A function that converts arrays to hash sets.
   *
   * @return A function that converts arrays to hash sets.
   */
  public static  F, HashSet> Array_HashSet() {
    return as -> new HashSet(as.toCollection());
  }

  /**
   * A function that converts arrays to linked hash sets.
   *
   * @return A function that converts arrays to linked hash sets.
   */
  public static  F, LinkedHashSet> Array_LinkedHashSet() {
    return as -> new LinkedHashSet(as.toCollection());
  }

  /**
   * A function that converts arrays to linked lists.
   *
   * @return A function that converts arrays to linked lists.
   */
  public static  F, LinkedList> Array_LinkedList() {
    return as -> new LinkedList(as.toCollection());
  }

  /**
   * A function that converts arrays to priority queues.
   *
   * @return A function that converts arrays to priority queues.
   */
  public static  F, PriorityQueue> Array_PriorityQueue() {
    return as -> new PriorityQueue(as.toCollection());
  }

  /**
   * A function that converts arrays to stacks.
   *
   * @return A function that converts arrays to stacks.
   */
  public static  F, Stack> Array_Stack() {
    return as -> {
      final Stack s = new Stack();
      s.addAll(as.toCollection());
      return s;
    };
  }

  /**
   * A function that converts arrays to tree sets.
   *
   * @return A function that converts arrays to tree sets.
   */
  public static  F, TreeSet> Array_TreeSet() {
    return as -> new TreeSet(as.toCollection());
  }

  /**
   * A function that converts arrays to vectors.
   *
   * @return A function that converts arrays to vectors.
   */
  public static  F, Vector> Array_Vector() {
    return as -> new Vector(as.toCollection());
  }

  /**
   * A function that converts arrays to array blocking queues.
   *
   * @param fair The argument to pass to the constructor of the array blocking queue.
   * @return A function that converts arrays to array blocking queues.
   */
  public static  F, ArrayBlockingQueue> Array_ArrayBlockingQueue(final boolean fair) {
    return as -> new ArrayBlockingQueue(as.length(), fair, as.toCollection());
  }

  /**
   * A function that converts arrays to concurrent linked queues.
   *
   * @return A function that converts arrays to concurrent linked queues.
   */
  public static  F, ConcurrentLinkedQueue> Array_ConcurrentLinkedQueue() {
    return as -> new ConcurrentLinkedQueue(as.toCollection());
  }

  /**
   * A function that converts arrays to copy on write array lists.
   *
   * @return A function that converts arrays to copy on write array lists.
   */
  public static  F, CopyOnWriteArrayList> Array_CopyOnWriteArrayList() {
    return as -> new CopyOnWriteArrayList(as.toCollection());
  }

  /**
   * A function that converts arrays to copy on write array sets.
   *
   * @return A function that converts arrays to copy on write array sets.
   */
  public static  F, CopyOnWriteArraySet> Array_CopyOnWriteArraySet() {
    return as -> new CopyOnWriteArraySet(as.toCollection());
  }

  /**
   * A function that converts arrays to delay queues.
   *
   * @return A function that converts arrays to delay queues.
   */
  public static  F, DelayQueue> Array_DelayQueue() {
    return as -> new DelayQueue(as.toCollection());
  }

  /**
   * A function that converts arrays to linked blocking queues.
   *
   * @return A function that converts arrays to linked blocking queues.
   */
  public static  F, LinkedBlockingQueue> Array_LinkedBlockingQueue() {
    return as -> new LinkedBlockingQueue(as.toCollection());
  }

  /**
   * A function that converts arrays to priority blocking queues.
   *
   * @return A function that converts arrays to priority blocking queues.
   */
  public static  F, PriorityBlockingQueue> Array_PriorityBlockingQueue() {
    return as -> new PriorityBlockingQueue(as.toCollection());
  }

  /**
   * A function that converts arrays to synchronous queues.
   *
   * @param fair The argument to pass to the constructor of the synchronous queue.
   * @return A function that converts arrays to synchronous queues.
   */
  public static  F, SynchronousQueue> Array_SynchronousQueue(final boolean fair) {
    return as -> {
      final SynchronousQueue q = new SynchronousQueue(fair);
      q.addAll(as.toCollection());
      return q;
    };
  }

  // END Array ->

  // BEGIN Stream ->

  /**
   * A function that converts streams to iterable.
   *
   * @return A function that converts streams to iterable.
   */
  public static  F, Iterable> Stream_Iterable() {
    return as -> () -> new Iterator() {
      private Stream x = as;

      public boolean hasNext() {
        return x.isNotEmpty();
      }

      public A next() {
        if (x.isEmpty())
          throw new NoSuchElementException("Empty iterator");
        else {
          final A a = x.head();
          x = x.tail()._1();
          return a;
        }
      }

      public void remove() {
        throw new UnsupportedOperationException();
      }
    };
  }

  /**
   * A function that converts streams to array lists.
   *
   * @return A function that converts streams to array lists.
   */
  public static  F, ArrayList> Stream_ArrayList() {
    return as -> new ArrayList(as.toCollection());
  }

  /**
   * A function that converts streams to bit sets.
   */
  public static final F, BitSet> Stream_BitSet = bs -> {
    final BitSet s = new BitSet(bs.length());
    bs.zipIndex().foreachDoEffect(bi -> {
      s.set(bi._2(), bi._1());
    });
    return s;
  };

  /**
   * A function that converts streams to enum sets.
   *
   * @return A function that converts streams to enum sets.
   */
  public static > F, EnumSet> Stream_EnumSet() {
    return as -> copyOf(as.toCollection());
  }

  /**
   * A function that converts streams to hash sets.
   *
   * @return A function that converts streams to hash sets.
   */
  public static  F, HashSet> Stream_HashSet() {
    return as -> new HashSet(as.toCollection());
  }

  /**
   * A function that converts streams to linked hash sets.
   *
   * @return A function that converts streams to linked hash sets.
   */
  public static  F, LinkedHashSet> Stream_LinkedHashSet() {
    return as -> new LinkedHashSet(as.toCollection());
  }

  /**
   * A function that converts streams to linked lists.
   *
   * @return A function that converts streams to linked lists.
   */
  public static  F, LinkedList> Stream_LinkedList() {
    return as -> new LinkedList(as.toCollection());
  }

  /**
   * A function that converts streams to priority queues.
   *
   * @return A function that converts streams to priority queues.
   */
  public static  F, PriorityQueue> Stream_PriorityQueue() {
    return as -> new PriorityQueue(as.toCollection());
  }

  /**
   * A function that converts streams to stacks.
   *
   * @return A function that converts streams to stacks.
   */
  public static  F, Stack> Stream_Stack() {
    return as -> {
      final Stack s = new Stack();
      s.addAll(as.toCollection());
      return s;
    };
  }

  /**
   * A function that converts streams to tree sets.
   *
   * @return A function that converts streams to tree sets.
   */
  public static  F, TreeSet> Stream_TreeSet() {
    return as -> new TreeSet(as.toCollection());
  }

  /**
   * A function that converts streams to vectors.
   *
   * @return A function that converts streams to vectors.
   */
  public static  F, Vector> Stream_Vector() {
    return as -> new Vector(as.toCollection());
  }

  /**
   * A function that converts streams to array blocking queues.
   *
   * @param fair The argument to pass to the constructor of the array blocking queue.
   * @return A function that converts streams to array blocking queues.
   */
  public static  F, ArrayBlockingQueue> Stream_ArrayBlockingQueue(final boolean fair) {
    return as -> new ArrayBlockingQueue(as.length(), fair, as.toCollection());
  }

  /**
   * A function that converts streams to concurrent linked queues.
   *
   * @return A function that converts streams to concurrent linked queues.
   */
  public static  F, ConcurrentLinkedQueue> Stream_ConcurrentLinkedQueue() {
    return as -> new ConcurrentLinkedQueue(as.toCollection());
  }

  /**
   * A function that converts streams to copy on write array lists.
   *
   * @return A function that converts streams to copy on write array lists.
   */
  public static  F, CopyOnWriteArrayList> Stream_CopyOnWriteArrayList() {
    return as -> new CopyOnWriteArrayList(as.toCollection());
  }

  /**
   * A function that converts streams to copy on write array sets.
   *
   * @return A function that converts streams to copy on write array sets.
   */
  public static  F, CopyOnWriteArraySet> Stream_CopyOnWriteArraySet() {
    return as -> new CopyOnWriteArraySet(as.toCollection());
  }

  /**
   * A function that converts streams to delay queues.
   *
   * @return A function that converts streams to delay queues.
   */
  public static  F, DelayQueue> Stream_DelayQueue() {
    return as -> new DelayQueue(as.toCollection());
  }

  /**
   * A function that converts streams to linked blocking queues.
   *
   * @return A function that converts streams to linked blocking queues.
   */
  public static  F, LinkedBlockingQueue> Stream_LinkedBlockingQueue() {
    return as -> new LinkedBlockingQueue(as.toCollection());
  }

  /**
   * A function that converts streams to priority blocking queues.
   *
   * @return A function that converts streams to priority blocking queues.
   */
  public static  F, PriorityBlockingQueue> Stream_PriorityBlockingQueue() {
    return as -> new PriorityBlockingQueue(as.toCollection());
  }

  /**
   * A function that converts streams to synchronous queues.
   *
   * @param fair The argument to pass to the constructor of the synchronous queue.
   * @return A function that converts streams to synchronous queues.
   */
  public static  F, SynchronousQueue> Stream_SynchronousQueue(final boolean fair) {
    return as -> {
      final SynchronousQueue q = new SynchronousQueue(fair);
      q.addAll(as.toCollection());
      return q;
    };
  }

  // END Stream ->

  // BEGIN Option ->

  /**
   * A function that converts options to array lists.
   *
   * @return A function that converts options to array lists.
   */
  public static  F, ArrayList> Option_ArrayList() {
    return as -> new ArrayList(as.toCollection());
  }

  /**
   * A function that converts options to bit sets.
   */
  public static final F, BitSet> Option_BitSet = bs -> {
    final BitSet s = new BitSet(bs.length());

    bs.foreachDoEffect(b -> {
      if (b)
        s.set(0);
    });
    return s;
  };

  /**
   * A function that converts options to enum sets.
   *
   * @return A function that converts options to enum sets.
   */
  public static > F, EnumSet> Option_EnumSet() {
    return as -> copyOf(as.toCollection());
  }

  /**
   * A function that converts options to hash sets.
   *
   * @return A function that converts options to hash sets.
   */
  public static  F, HashSet> Option_HashSet() {
    return as -> new HashSet(as.toCollection());
  }

  /**
   * A function that converts options to linked hash sets.
   *
   * @return A function that converts options to linked hash sets.
   */
  public static  F, LinkedHashSet> Option_LinkedHashSet() {
    return as -> new LinkedHashSet(as.toCollection());
  }

  /**
   * A function that converts options to linked lists.
   *
   * @return A function that converts options to linked lists.
   */
  public static  F, LinkedList> Option_LinkedList() {
    return as -> new LinkedList(as.toCollection());
  }

  /**
   * A function that converts options to priority queues.
   *
   * @return A function that converts options to priority queues.
   */
  public static  F, PriorityQueue> Option_PriorityQueue() {
    return as -> new PriorityQueue(as.toCollection());
  }

  /**
   * A function that converts options to stacks.
   *
   * @return A function that converts options to stacks.
   */
  public static  F, Stack> Option_Stack() {
    return as -> {
      final Stack s = new Stack();
      s.addAll(as.toCollection());
      return s;
    };
  }

  /**
   * A function that converts options to tree sets.
   *
   * @return A function that converts options to tree sets.
   */
  public static  F, TreeSet> Option_TreeSet() {
    return as -> new TreeSet(as.toCollection());
  }

  /**
   * A function that converts options to vectors.
   *
   * @return A function that converts options to vectors.
   */
  public static  F, Vector> Option_Vector() {
    return as -> new Vector(as.toCollection());
  }

  /**
   * A function that converts options to array blocking queues.
   *
   * @param fair The argument to pass to the constructor of the array blocking queue.
   * @return A function that converts options to array blocking queues.
   */
  public static  F, ArrayBlockingQueue> Option_ArrayBlockingQueue(final boolean fair) {
    return as -> new ArrayBlockingQueue(as.length(), fair, as.toCollection());
  }

  /**
   * A function that converts options to concurrent linked queues.
   *
   * @return A function that converts options to concurrent linked queues.
   */
  public static  F, ConcurrentLinkedQueue> Option_ConcurrentLinkedQueue() {
    return as -> new ConcurrentLinkedQueue(as.toCollection());
  }

  /**
   * A function that converts options to copy on write array lists.
   *
   * @return A function that converts options to copy on write array lists.
   */
  public static  F, CopyOnWriteArrayList> Option_CopyOnWriteArrayList() {
    return as -> new CopyOnWriteArrayList(as.toCollection());
  }

  /**
   * A function that converts options to copy on write array sets.
   *
   * @return A function that converts options to copy on write array sets.
   */
  public static  F, CopyOnWriteArraySet> Option_CopyOnWriteArraySet() {
    return as -> new CopyOnWriteArraySet(as.toCollection());
  }

  /**
   * A function that converts options to delay queues.
   *
   * @return A function that converts options to delay queues.
   */
  public static  F, DelayQueue> Option_DelayQueue() {
    return as -> new DelayQueue(as.toCollection());
  }

  /**
   * A function that converts options to linked blocking queues.
   *
   * @return A function that converts options to linked blocking queues.
   */
  public static  F, LinkedBlockingQueue> Option_LinkedBlockingQueue() {
    return as -> new LinkedBlockingQueue(as.toCollection());
  }

  /**
   * A function that converts options to priority blocking queues.
   *
   * @return A function that converts options to priority blocking queues.
   */
  public static  F, PriorityBlockingQueue> Option_PriorityBlockingQueue() {
    return as -> new PriorityBlockingQueue(as.toCollection());
  }

  /**
   * A function that converts options to synchronous queues.
   *
   * @param fair The argument to pass to the constructor of the synchronous queue.
   * @return A function that converts options to synchronous queues.
   */
  public static  F, SynchronousQueue> Option_SynchronousQueue(final boolean fair) {
    return as -> {
      final SynchronousQueue q = new SynchronousQueue(fair);
      q.addAll(as.toCollection());
      return q;
    };
  }

  // END Option ->

  // BEGIN Either ->

  /**
   * A function that converts eithers to array lists.
   *
   * @return A function that converts eithers to array lists.
   */
  public static  F, ArrayList> Either_ArrayListA() {
    return Function.compose(Java.Option_ArrayList(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to array lists.
   *
   * @return A function that converts eithers to array lists.
   */
  public static  F, ArrayList> Either_ArrayListB() {
    return Function.compose(Java.Option_ArrayList(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to bit sets.
   *
   * @return A function that converts eithers to bit sets.
   */
  public static  F, BitSet> Either_BitSetA() {
    return Function.compose(Option_BitSet, Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to bit sets.
   *
   * @return A function that converts eithers to bit sets.
   */
  public static  F, BitSet> Either_BitSetB() {
    return Function.compose(Option_BitSet, Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to enum sets.
   *
   * @return A function that converts eithers to enum sets.
   */
  public static , B> F, EnumSet> Either_EnumSetA() {
    return Function.compose(Java.Option_EnumSet(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to enum sets.
   *
   * @return A function that converts eithers to enum sets.
   */
  public static > F, EnumSet> Either_EnumSetB() {
    return Function.compose(Java.Option_EnumSet(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to hash sets.
   *
   * @return A function that converts eithers to hash sets.
   */
  public static  F, HashSet> Either_HashSetA() {
    return Function.compose(Java.Option_HashSet(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to hash sets.
   *
   * @return A function that converts eithers to hash sets.
   */
  public static  F, HashSet> Either_HashSetB() {
    return Function.compose(Java.Option_HashSet(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to linked hash sets.
   *
   * @return A function that converts eithers to linked hash sets.
   */
  public static  F, LinkedHashSet> Either_LinkedHashSetA() {
    return Function.compose(Java.Option_LinkedHashSet(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to linked hash sets.
   *
   * @return A function that converts eithers to linked hash sets.
   */
  public static  F, LinkedHashSet> Either_LinkedHashSetB() {
    return Function.compose(Java.Option_LinkedHashSet(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to linked lists.
   *
   * @return A function that converts eithers to linked lists.
   */
  public static  F, LinkedList> Either_LinkedListA() {
    return Function.compose(Java.Option_LinkedList(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to priority queues.
   *
   * @return A function that eithers options to priority queues.
   */
  public static  F, PriorityQueue> Option_PriorityQueueA() {
    return Function.compose(Java.Option_PriorityQueue(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to priority queues.
   *
   * @return A function that eithers options to priority queues.
   */
  public static  F, PriorityQueue> Option_PriorityQueueB() {
    return Function.compose(Java.Option_PriorityQueue(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to linked lists.
   *
   * @return A function that converts eithers to linked lists.
   */
  public static  F, LinkedList> Either_LinkedListB() {
    return Function.compose(Java.Option_LinkedList(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to stacks.
   *
   * @return A function that converts eithers to stacks.
   */
  public static  F, Stack> Either_StackA() {
    return Function.compose(Java.Option_Stack(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to stacks.
   *
   * @return A function that converts eithers to stacks.
   */
  public static  F, Stack> Either_StackB() {
    return Function.compose(Java.Option_Stack(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to tree sets.
   *
   * @return A function that converts eithers to tree sets.
   */
  public static  F, TreeSet> Either_TreeSetA() {
    return Function.compose(Java.Option_TreeSet(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to tree sets.
   *
   * @return A function that converts eithers to tree sets.
   */
  public static  F, TreeSet> Either_TreeSetB() {
    return Function.compose(Java.Option_TreeSet(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to vectors.
   *
   * @return A function that converts eithers to vectors.
   */
  public static  F, Vector> Either_VectorA() {
    return Function.compose(Java.Option_Vector(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to vectors.
   *
   * @return A function that converts eithers to vectors.
   */
  public static  F, Vector> Either_VectorB() {
    return Function.compose(Java.Option_Vector(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to array blocking queues.
   *
   * @param fair The argument to pass to the constructor of the array blocking queue.
   * @return A function that converts eithers to array blocking queues.
   */
  public static  F, ArrayBlockingQueue> Either_ArrayBlockingQueueA(final boolean fair) {
    return Function.compose(Java.Option_ArrayBlockingQueue(fair), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to array blocking queues.
   *
   * @param fair The argument to pass to the constructor of the array blocking queue.
   * @return A function that converts eithers to array blocking queues.
   */
  public static  F, ArrayBlockingQueue> Either_ArrayBlockingQueueB(final boolean fair) {
    return Function.compose(Java.Option_ArrayBlockingQueue(fair), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to concurrent linked queues.
   *
   * @return A function that converts eithers to concurrent linked queues.
   */
  public static  F, ConcurrentLinkedQueue> Either_ConcurrentLinkedQueueA() {
    return Function.compose(Java.Option_ConcurrentLinkedQueue(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to concurrent linked queues.
   *
   * @return A function that converts eithers to concurrent linked queues.
   */
  public static  F, ConcurrentLinkedQueue> Either_ConcurrentLinkedQueueB() {
    return Function.compose(Java.Option_ConcurrentLinkedQueue(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to copy on write array lists.
   *
   * @return A function that converts eithers to copy on write array lists.
   */
  public static  F, CopyOnWriteArrayList> Either_CopyOnWriteArrayListA() {
    return Function.compose(Java.Option_CopyOnWriteArrayList(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to copy on write array lists.
   *
   * @return A function that converts eithers to copy on write array lists.
   */
  public static  F, CopyOnWriteArrayList> Either_CopyOnWriteArrayListB() {
    return Function.compose(Java.Option_CopyOnWriteArrayList(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to copy on write array sets.
   *
   * @return A function that converts eithers to copy on write array sets.
   */
  public static  F, CopyOnWriteArraySet> Either_CopyOnWriteArraySetA() {
    return Function.compose(Java.Option_CopyOnWriteArraySet(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to copy on write array sets.
   *
   * @return A function that converts eithers to copy on write array sets.
   */
  public static  F, CopyOnWriteArraySet> Either_CopyOnWriteArraySetB() {
    return Function.compose(Java.Option_CopyOnWriteArraySet(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to delay queues.
   *
   * @return A function that converts eithers to delay queues.
   */
  public static  F, DelayQueue> Either_DelayQueueA() {
    return Function.compose(Java.Option_DelayQueue(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to delay queues.
   *
   * @return A function that converts eithers to delay queues.
   */
  public static  F, DelayQueue> Either_DelayQueueB() {
    return Function.compose(Java.Option_DelayQueue(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to linked blocking queues.
   *
   * @return A function that converts eithers to linked blocking queues.
   */
  public static  F, LinkedBlockingQueue> Either_LinkedBlockingQueueA() {
    return Function.compose(Java.Option_LinkedBlockingQueue(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to linked blocking queues.
   *
   * @return A function that converts eithers to linked blocking queues.
   */
  public static  F, LinkedBlockingQueue> Either_LinkedBlockingQueueB() {
    return Function.compose(Java.Option_LinkedBlockingQueue(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to priority blocking queues.
   *
   * @return A function that converts eithers to priority blocking queues.
   */
  public static  F, PriorityBlockingQueue> Either_PriorityBlockingQueueA() {
    return Function.compose(Java.Option_PriorityBlockingQueue(), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to priority blocking queues.
   *
   * @return A function that converts eithers to priority blocking queues.
   */
  public static  F, PriorityBlockingQueue> Either_PriorityBlockingQueueB() {
    return Function.compose(Java.Option_PriorityBlockingQueue(), Conversions.Either_OptionB());
  }

  /**
   * A function that converts eithers to synchronous queues.
   *
   * @param fair The argument to pass to the constructor of the synchronous queue.
   * @return A function that converts eithers to synchronous queues.
   */
  public static  F, SynchronousQueue> Either_SynchronousQueueA(final boolean fair) {
    return Function.compose(Java.Option_SynchronousQueue(fair), Conversions.Either_OptionA());
  }

  /**
   * A function that converts eithers to synchronous queues.
   *
   * @param fair The argument to pass to the constructor of the synchronous queue.
   * @return A function that converts eithers to synchronous queues.
   */
  public static  F, SynchronousQueue> Either_SynchronousQueueB(final boolean fair) {
    return Function.compose(Java.Option_SynchronousQueue(fair), Conversions.Either_OptionB());
  }

  // END Either ->

  // BEGIN String ->

  /**
   * A function that converts strings to array lists.
   */
  public static final F> String_ArrayList =
      Function.compose(Java.List_ArrayList(), Conversions.String_List);

  /**
   * A function that converts strings to hash sets.
   */
  public static final F> String_HashSet =
      Function.compose(Java.List_HashSet(), Conversions.String_List);

  /**
   * A function that converts strings to linked hash sets.
   */
  public static final F> String_LinkedHashSet =
      Function.compose(Java.List_LinkedHashSet(), Conversions.String_List);

  /**
   * A function that converts strings to linked lists.
   */
  public static final F> String_LinkedList =
      Function.compose(Java.List_LinkedList(), Conversions.String_List);

  /**
   * A function that converts strings to priority queues.
   */
  public static final F> String_PriorityQueue =
      Function.compose(Java.List_PriorityQueue(), Conversions.String_List);

  /**
   * A function that converts strings to stacks.
   */
  public static final F> String_Stack =
      Function.compose(Java.List_Stack(), Conversions.String_List);

  /**
   * A function that converts strings to tree sets.
   */
  public static final F> String_TreeSet =
      Function.compose(Java.List_TreeSet(), Conversions.String_List);

  /**
   * A function that converts strings to vectors.
   */
  public static final F> String_Vector =
      Function.compose(Java.List_Vector(), Conversions.String_List);

  /**
   * A function that converts strings to array blocking queues.
   *
   * @param fair The argument to pass to the constructor of the array blocking queue.
   * @return A function that converts strings to array blocking queues.
   */
  public static F> String_ArrayBlockingQueue(final boolean fair) {
    return Function.compose(Java.List_ArrayBlockingQueue(fair), Conversions.String_List);
  }

  /**
   * A function that converts strings to concurrent linked queues.
   */
  public static final F> String_ConcurrentLinkedQueue =
      Function.compose(Java.List_ConcurrentLinkedQueue(), Conversions.String_List);

  /**
   * A function that converts strings to copy on write array lists.
   */
  public static final F> String_CopyOnWriteArrayList =
      Function.compose(Java.List_CopyOnWriteArrayList(), Conversions.String_List);

  /**
   * A function that converts strings to copy on write array sets.
   */
  public static final F> String_CopyOnWriteArraySet =
      Function.compose(Java.List_CopyOnWriteArraySet(), Conversions.String_List);

  /**
   * A function that converts strings to linked blocking queues.
   */
  public static final F> String_LinkedBlockingQueue =
      Function.compose(Java.List_LinkedBlockingQueue(), Conversions.String_List);

  /**
   * A function that converts strings to priority blocking queues.
   */
  public static final F> String_PriorityBlockingQueue =
      Function.compose(Java.List_PriorityBlockingQueue(), Conversions.String_List);

  /**
   * A function that converts strings to synchronous queues.
   *
   * @param fair The argument to pass to the constructor of the synchronous queue.
   * @return A function that converts strings to synchronous queues.
   */
  public static F> String_SynchronousQueue(final boolean fair) {
    return Function.compose(Java.List_SynchronousQueue(fair), Conversions.String_List);
  }

  // END String ->

  // BEGIN StringBuffer ->

  /**
   * A function that converts string buffers to array lists.
   */
  public static final F> StringBuffer_ArrayList =
      Function.compose(Java.List_ArrayList(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to hash sets.
   */
  public static final F> StringBuffer_HashSet =
      Function.compose(Java.List_HashSet(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to linked hash sets.
   */
  public static final F> StringBuffer_LinkedHashSet =
      Function.compose(Java.List_LinkedHashSet(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to linked lists.
   */
  public static final F> StringBuffer_LinkedList =
      Function.compose(Java.List_LinkedList(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to priority queues.
   */
  public static final F> StringBuffer_PriorityQueue =
      Function.compose(Java.List_PriorityQueue(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to stacks.
   */
  public static final F> StringBuffer_Stack =
      Function.compose(Java.List_Stack(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to tree sets.
   */
  public static final F> StringBuffer_TreeSet =
      Function.compose(Java.List_TreeSet(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to vectors.
   */
  public static final F> StringBuffer_Vector =
      Function.compose(Java.List_Vector(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to array blocking queues.
   *
   * @param fair The argument to pass to the constructor of the array blocking queue.
   * @return A function that converts string buffers to array blocking queues.
   */
  public static F> StringBuffer_ArrayBlockingQueue(final boolean fair) {
    return Function.compose(Java.List_ArrayBlockingQueue(fair), Conversions.StringBuffer_List);
  }

  /**
   * A function that converts string buffers to concurrent linked queues.
   */
  public static final F> StringBuffer_ConcurrentLinkedQueue =
      Function.compose(Java.List_ConcurrentLinkedQueue(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to copy on write array lists.
   */
  public static final F> StringBuffer_CopyOnWriteArrayList =
      Function.compose(Java.List_CopyOnWriteArrayList(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to copy on write array sets.
   */
  public static final F> StringBuffer_CopyOnWriteArraySet =
      Function.compose(Java.List_CopyOnWriteArraySet(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to linked blocking queues.
   */
  public static final F> StringBuffer_LinkedBlockingQueue =
      Function.compose(Java.List_LinkedBlockingQueue(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to priority blocking queues.
   */
  public static final F> StringBuffer_PriorityBlockingQueue =
      Function.compose(Java.List_PriorityBlockingQueue(), Conversions.StringBuffer_List);

  /**
   * A function that converts string buffers to synchronous queues.
   *
   * @param fair The argument to pass to the constructor of the synchronous queue.
   * @return A function that converts string buffers to synchronous queues.
   */
  public static F> StringBuffer_SynchronousQueue(final boolean fair) {
    return Function.compose(Java.List_SynchronousQueue(fair), Conversions.StringBuffer_List);
  }

  // END StringBuffer ->

  // BEGIN StringBuilder ->

  /**
   * A function that converts string builders to array lists.
   */
  public static final F> StringBuilder_ArrayList =
      Function.compose(Java.List_ArrayList(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to hash sets.
   */
  public static final F> StringBuilder_HashSet =
      Function.compose(Java.List_HashSet(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to linked hash sets.
   */
  public static final F> StringBuilder_LinkedHashSet =
      Function.compose(Java.List_LinkedHashSet(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to linked lists.
   */
  public static final F> StringBuilder_LinkedList =
      Function.compose(Java.List_LinkedList(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to priority queues.
   */
  public static final F> StringBuilder_PriorityQueue =
      Function.compose(Java.List_PriorityQueue(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to stacks.
   */
  public static final F> StringBuilder_Stack =
      Function.compose(Java.List_Stack(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to tree sets.
   */
  public static final F> StringBuilder_TreeSet =
      Function.compose(Java.List_TreeSet(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to vectors.
   */
  public static final F> StringBuilder_Vector =
      Function.compose(Java.List_Vector(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to array blocking queues.
   *
   * @param fair The argument to pass to the constructor of the array blocking queue.
   * @return A function that converts string builders to array blocking queues.
   */
  public static F> StringBuilder_ArrayBlockingQueue(final boolean fair) {
    return Function.compose(Java.List_ArrayBlockingQueue(fair), Conversions.StringBuilder_List);
  }

  /**
   * A function that converts string builders to concurrent linked queues.
   */
  public static final F> StringBuilder_ConcurrentLinkedQueue =
      Function.compose(Java.List_ConcurrentLinkedQueue(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to copy on write array lists.
   */
  public static final F> StringBuilder_CopyOnWriteArrayList =
      Function.compose(Java.List_CopyOnWriteArrayList(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to copy on write array sets.
   */
  public static final F> StringBuilder_CopyOnWriteArraySet =
      Function.compose(Java.List_CopyOnWriteArraySet(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to linked blocking queues.
   */
  public static final F> StringBuilder_LinkedBlockingQueue =
      Function.compose(Java.List_LinkedBlockingQueue(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to priority blocking queues.
   */
  public static final F> StringBuilder_PriorityBlockingQueue =
      Function.compose(Java.List_PriorityBlockingQueue(), Conversions.StringBuilder_List);

  /**
   * A function that converts string builders to synchronous queues.
   *
   * @param fair The argument to pass to the constructor of the synchronous queue.
   * @return A function that converts string builders to synchronous queues.
   */
  public static F> StringBuilder_SynchronousQueue(final boolean fair) {
    return Function.compose(Java.List_SynchronousQueue(fair), Conversions.StringBuilder_List);
  }

  // END StringBuffer ->

  // BEGIN ArrayList ->

  /**
   * A function that converts array lists to lists.
   *
   * @return A function that converts array lists to lists.
   */
  public static  F, List> ArrayList_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END ArrayList ->

  /**
   * A function that converts Java lists to lists.
   * @deprecated As of 4.3, use {@link #JavaList_List}
   *
   * @return A function that converts Java lists to lists.
   */
  public static  F, List> JUList_List() {
    return as -> JavaList_List(as);
  }

  public static  F, List> JavaList_List() {
    return as -> JavaList_List(as);
  }

  public static  List JavaList_List(java.util.List list) {
    return List.list(list);
  }

  // BEGIN BitSet ->

  /**
   * A function that converts bit sets to lists.
   */
  public static final F> BitSet_List = s -> List.unfold(i -> i == s.length() ?
      Option.>none() :
      some(p(s.get(i), i + 1)), 0);

  // todo

  // END BitSet ->

  // BEGIN EnumSet ->

  /**
   * A function that converts enum sets to lists.
   *
   * @return A function that converts enum sets to lists.
   */
  public static > F, List> EnumSet_List() {
	  return as -> Collection_List(as);
  }

	public static  List Collection_List(Collection c) {
		return Java.Collection_List().f(c);
	}

	public static  F, List> Collection_List() {
		return c -> List.list(c.toArray(array(c.size())));
	}

	@SafeVarargs
	private static  E[] array(int length, E... array) {
		return Arrays.copyOf(array, length);
	}

  // todo

  // END EnumSet ->

  // BEGIN HashSet ->

  /**
   * A function that converts hash sets to lists.
   *
   * @return A function that converts hash sets to lists.
   */
  public static  F, List> HashSet_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END HashSet ->

  // BEGIN LinkedHashSet ->

  /**
   * A function that converts linked hash sets to lists.
   *
   * @return A function that converts linked hash sets to lists.
   */
  public static  F, List> LinkedHashSet_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END LinkedHashSet ->

  // BEGIN Linked List ->

  /**
   * A function that converts linked lists to lists.
   *
   * @return A function that converts linked lists to lists.
   */
  public static  F, List> LinkedList_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END Linked List ->

  // BEGIN PriorityQueue ->

  /**
   * A function that converts priority queues to lists.
   *
   * @return A function that converts priority queues to lists.
   */
  public static  F, List> PriorityQueue_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END PriorityQueue ->

  // BEGIN Stack ->

  /**
   * A function that converts stacks to lists.
   *
   * @return A function that converts stacks to lists.
   */
  public static  F, List> Stack_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END Stack ->

  // BEGIN TreeSet ->

  /**
   * A function that converts tree sets to lists.
   *
   * @return A function that converts tree sets to lists.
   */
  public static  F, List> TreeSet_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END TreeSet ->

  // BEGIN Vector ->

  /**
   * A function that converts vectors to lists.
   *
   * @return A function that converts vectors to lists.
   */
  public static  F, List> Vector_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END Vector ->

  // BEGIN ArrayBlockingQueue ->

  /**
   * A function that converts array blocking queues to lists.
   *
   * @return A function that converts array blocking queues to lists.
   */
  public static  F, List> ArrayBlockingQueue_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END ArrayBlockingQueue ->

  // BEGIN ConcurrentLinkedQueue ->

  /**
   * A function that converts concurrent linked queues to lists.
   *
   * @return A function that converts concurrent linked queues to lists.
   */
  public static  F, List> ConcurrentLinkedQueue_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END ConcurrentLinkedQueue ->

  // BEGIN CopyOnWriteArrayList ->

  /**
   * A function that converts copy on write array lists to lists.
   *
   * @return A function that converts copy on write array lists to lists.
   */
  public static  F, List> CopyOnWriteArrayList_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END CopyOnWriteArrayList ->

  // BEGIN CopyOnWriteArraySet ->

  /**
   * A function that converts copy on write array sets to lists.
   *
   * @return A function that converts copy on write array sets to lists.
   */
  public static  F, List> CopyOnWriteArraySet_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END CopyOnWriteArraySet ->

  // BEGIN DelayQueue ->

  /**
   * A function that converts delay queues to lists.
   *
   * @return A function that converts delay queues to lists.
   */
  public static  F, List> DelayQueue_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END DelayQueue ->

  // BEGIN LinkedBlockingQueue ->

  /**
   * A function that converts linked blocking queues to lists.
   *
   * @return A function that converts linked blocking queues to lists.
   */
  public static  F, List> LinkedBlockingQueue_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END LinkedBlockingQueue ->

  // BEGIN PriorityBlockingQueue ->

  /**
   * A function that converts priority blocking queues to lists.
   *
   * @return A function that converts priority blocking queues to lists.
   */
  public static  F, List> PriorityBlockingQueue_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END PriorityBlockingQueue ->

  // BEGIN SynchronousQueue ->

  /**
   * A function that converts synchronous queues to lists.
   *
   * @return A function that converts synchronous queues to lists.
   */
  public static  F, List> SynchronousQueue_List() {
    return as -> Collection_List(as);
  }

  // todo

  // END SynchronousQueue ->

  // BEGIN Callable ->

  public static  F, Callable> P1_Callable() {
    return a -> () -> a._1();
  }

// END Callable ->

// BEGIN Future ->

  public static  F, P1>> Future_P1() {
    return a -> P.lazy(() -> {
        Either r;
        try {
          r = Either.right(a.get());
        }
        catch (Exception e) {
          r = Either.left(e);
        }
        return r;
      });
  }

  // END Future ->
}