01: package kawa.standard;
02:
03: import gnu.mapping.*;
04:
05: public class call_with_values extends Procedure2 {
06: public static final call_with_values callWithValues = new call_with_values();
07: static {
08: callWithValues.setName("call-with-values");
09: }
10:
11: public static Object callWithValues(Procedure producer,
12: Procedure consumer) throws Throwable {
13: Object values = producer.apply0();
14: if (values instanceof Values)
15: return ((Values) values).call_with(consumer);
16: else
17: return consumer.apply1(values);
18: }
19:
20: public Object apply2(Object producer, Object consumer)
21: throws Throwable {
22: return callWithValues((Procedure) producer,
23: (Procedure) consumer);
24: }
25:
26: public void apply(CallContext ctx) throws Throwable {
27: Procedure.checkArgCount(this , 2);
28: Object[] args = ctx.getArgs();
29: Object values = ((Procedure) args[0]).apply0();
30: Procedure consumer = (Procedure) args[1];
31: if (values instanceof Values) {
32: args = ((Values) values).getValues();
33: consumer.checkN(args, ctx);
34: } else {
35: consumer.check1(values, ctx);
36: }
37: }
38: }
|