Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added cons

  • Loading branch information...
commit 5bae2d6de7aece7dc78d10592eacd8f73b276e54 1 parent a96a0af
Gareth Davis authored
32 src/main/java/com/logicalpractice/persistentcollections/Sequences.java
View
@@ -23,7 +23,39 @@
public static <T> Iterable<T> headlessIterable(Sequence<T> sequence){
return new HeadlessIterable<T>(sequence);
}
+
+ public static <T> Sequence<T> construct(T obj){
+ return new DefaultSequence<T>(obj);
+ }
+
+ public static <T> Sequence<T> construct(T obj, Sequence<T> sequence){
+ return new DefaultSequence<T>(obj, sequence);
+ }
+
+ private static class DefaultSequence<T> implements Sequence<T> {
+ private final T value;
+ private final Sequence<T> rest;
+
+ public DefaultSequence(T value, Sequence<T> rest){
+ this.value = value;
+ this.rest = rest;
+ }
+
+ public DefaultSequence(T value) {
+ this(value, null);
+ }
+
+ @Override
+ public T first() {
+ return value;
+ }
+ @Override
+ public Sequence<T> rest() {
+ return rest; // maybe null at end of sequence
+ }
+ }
+
private static class IterableSequence<T> implements Iterable<T> {
private final Sequence<T> sequence;
Please sign in to comment.
Something went wrong with that request. Please try again.