예제 #1
0
 /**
  * Specialised version of Tuple.spanFrom for when the typechecker determines that it can do better
  * than the generic one that returns a Sequential. Here we return a Tuple, although our type
  * signature hides this.
  */
 public static Sequential tuple_spanFrom(Ranged tuple, ceylon.language.Integer index) {
   Sequential seq = (Sequential) tuple;
   long i = index.longValue();
   while (i-- > 0) {
     seq = seq.getRest();
   }
   return seq;
 }
예제 #2
0
 /**
  * Return {@link empty_#getEmpty$ empty} or an {@link ArraySequence} wrapping the given elements,
  * depending on whether the given array and varargs are empty
  *
  * @param rest The elements at the end of the sequence
  * @param elements the elements at the start of the sequence
  * @return A Sequential
  */
 public static <T> Sequential<? extends T> sequentialInstance(
     TypeDescriptor $reifiedT, Sequential<? extends T> rest, T... elements) {
   if (elements.length == 0) {
     if (rest.getEmpty()) {
       return (Sequential) empty_.getEmpty$();
     }
     return rest;
   }
   // elements is not empty
   if (rest.getEmpty()) return ArraySequence.<T>instance($reifiedT, elements);
   // we have both, let's find the total size
   int total = (int) (rest.getSize() + elements.length);
   java.lang.Object[] newArray = new java.lang.Object[total];
   System.arraycopy(elements, 0, newArray, 0, elements.length);
   Iterator<? extends T> iterator = rest.iterator();
   int i = elements.length;
   for (Object elem; (elem = iterator.next()) != finished_.getFinished$(); i++) {
     newArray[i] = elem;
   }
   return ArraySequence.<T>instance($reifiedT, newArray);
 }