!7

// an example
static class E {
  S in, out;
}

// Note the use of the clever group function to initialize a bunch of
// objects with minimal typing.
static L<E> examples = group(E, splitAtSpace("in out"), ll(
  "0", "00",
  "1", "11",
  "5", "55",
  "a", "aa",
  "b", "bb"));
  
p {
  printStruct(examples);
}

static <A> L<A> group(Class<A> theClass, L<S> fields, L data) {
  new L<A> l;
  try {
  for (int i = 0; i < l(data); i += l(fields)) {
    A o = newObject(theClass);
    for (int j = 0; j < min(l(fields), l(data)-i); j++) {
      S field = fields.get(j);
      O item = data.get(i+j);
      setOpt(o, field, item);
    }
    l.add(o);
  }
  } catch e { printStackTrace(e); }
  ret l;
}