Exemple #1
0
    protected override DyObject IterateOp(ExecutionContext ctx, DyObject self)
    {
        if (self is IEnumerable <DyObject> seq)
        {
            return(DyIterator.Create(seq));
        }

        return(Nil);
    }
Exemple #2
0
    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)
        });
Exemple #3
0
 protected override DyObject AddOp(ExecutionContext ctx, DyObject left, DyObject right) => DyIterator.Create(Concat(ctx, left, right));
Exemple #4
0
 private static DyObject Iterate(ExecutionContext ctx, DyObject self) =>
 DyIterator.Create(((DyClass)self).Fields);