interface Builder.<T, Self> {
  function add(x: T): void;
  function result(): Self;
}
mixin Enumerable.<T, Self> {
  abstract function newBuilder(): Builder.<T, Self>;
  abstract function each(f: (T) -> void): void;
  function filter(pred: (T) -> boolean): Self {
    var b = this.newBuilder();
    this.each((x) -> {
      if (pred(x)) b.add(x);
    });
    return b.result;
  }
}
class SArrayBuilder.<T> implements Builder.<T, SArrayBuilder.<T>> {
  var _xs = []: T[];
  override function add(x: T): void {
    this._xs.push(x);
  }
  override function result(): SArrayBuilder.<T> {
    return new SArray.<T>(this._xs);
  }
}
class SArray.<T> implements Enumerable.<T, SArray.<T>> {
  var _xs: T[];
  function constructor(xs: T[]) {
    this._xs = xs;
  }
  override function newBuilder(): SArrayBuilder.<T> {
    return new SArrayBuilder.<T>();
  }
  override function each(f: (T) -> void): void {
    for (var x in this._xs) f(this._xs[x] as T);
  }
}
class _Main {
  static function main(args: string[]): void {
    var xs = new SArray.<number>([1, 2, 3]);
    log xs.filter((x) -> x % 2 != 0);
  }
}
