protected override DyObject IterateOp(ExecutionContext ctx, DyObject self) { if (self is IEnumerable <DyObject> seq) { return(DyIterator.Create(seq)); } return(Nil); }
protected override DyObject CastOp(ExecutionContext ctx, DyObject self, DyTypeInfo targetType) { if (targetType.ReflectedTypeId == self.TypeId) { return(self); } var xs = (DyCollection)self; return(targetType.ReflectedTypeId switch { Dy.Tuple => new DyTuple(xs.ToArray()), Dy.Array => new DyArray(xs.ToArray()), Dy.Iterator => DyIterator.Create(xs), Dy.Set => new DySet(new HashSet <DyObject>(xs.ToArray())), _ => base.CastOp(ctx, self, targetType) });
protected override DyObject AddOp(ExecutionContext ctx, DyObject left, DyObject right) => DyIterator.Create(Concat(ctx, left, right));
private static DyObject Iterate(ExecutionContext ctx, DyObject self) => DyIterator.Create(((DyClass)self).Fields);