AList extends AbstractACollection<T, AList<T>> implements Serializable { public AList<T> cons(T el) { return new AHead<>(el, this); } protected  AList(int size); @SuppressWarnings("unchecked") static AList<T> nil(); static AList<T> create(Iterable<T> elements); static AList<T> create(List<T> elements); @SafeVarargs static AList<T> create(T... elements); java.util.List<T> asJavaUtilList(); @Override Collection<T> asJavaUtilCollection(); abstract AOption<T> optHead(); abstract T head(); abstract AList<T> tail(); AList<T> cons(T el); AList<T> reverse(); int size(); @Override AList<T> toList(); @Override AList<X> map(AFunction1<? super T, ? extends X, E> f); @Override AList<X> flatMap(AFunction1<? super T, ? extends Iterable<X>, E> f); @SuppressWarnings("unchecked") @Override AList<X> flatten(); @Override AList<X> collect(APartialFunction<? super T, ? extends X, E> pf); @Override Iterator<T> iterator(); static final AList nil; }
@Test public void testCons() { AList<String> l0 = AList.nil(); final AList<String> l1 = l0.cons("a"); final AList<String> l2 = l0.cons("x").cons("y"); assertEquals(1, l1.size()); assertEquals(2, l2.size()); assertEquals(Arrays.<String>asList(), l0.asJavaUtilList()); assertEquals(Arrays.asList("a"), l1.asJavaUtilList()); assertEquals(Arrays.asList("y", "x"), l2.asJavaUtilList()); }