public override IValue interpret(Context context) { IType sourceType = source.check(context); if (!(sourceType is IterableType)) { throw new InternalError("Illegal source type: " + sourceType.GetTypeName()); } IType itemType = ((IterableType)sourceType).GetItemType(); IValue value = source.interpret(context); if (value == null) { throw new NullReferenceError(); } if (!(value is IFilterable)) { throw new InternalError("Illegal fetch source: " + source); } IFilterable list = (IFilterable)value; ArrowExpression arrow = predicate.ToArrowExpression(); Predicate <IValue> filter = arrow.GetFilter(context, itemType); return(list.Filter(filter)); }
IValue interpretPredicate(Context context) { IValue lval = left.interpret(context); if (lval is IContainer) { IType itemType = ((ContainerType)lval.GetIType()).GetItemType(); ArrowExpression arrow = ((PredicateExpression)right).ToArrowExpression(); Predicate <IValue> predicate = arrow.GetFilter(context, itemType); return(interpretPredicate(context, (IContainer)lval, predicate)); } else { throw new SyntaxError("Expecting collection"); } }