// the second argument (a one argument function) to
// every element in the first argument (a collection).
public Object apply(Object[] args) {
try {
Collection c = _theContext.getCollection(args[0]);
FunctionToken f = (FunctionToken) args[1];
Object[] argument = new Object[1];
List res = new ArrayList();
for (Iterator i = c.iterator(); i.hasNext();) {
argument[0] = i.next();
Object listFragment = _theContext.applyFunction(f,
argument);
res.addAll(_theContext.getCollection(listFragment));
}
return _theContext.createList(res);
} catch (Exception ex) {
throw new FunctionCallException("Failed to create list.",
args[0], args[1], ex);
}
}
public int arity() {
return 2;
}
}));
env.bind("$createSet", _theContext.createFunction(new Function() {
// Create a set that contains the results of applying
// the second argument (a one argument function) to
// every element in the first argument (a collection).
public Object apply(Object[] args) {
try {
Collection c = _theContext.getCollection(args[0]);
FunctionToken f = (FunctionToken) args[1];
Object[] argument = new Object[1];
Set res = new HashSet();
for (Iterator i = c.iterator(); i.hasNext();) {
argument[0] = i.next();
Object setFragment = _theContext.applyFunction(f,
argument);
res.addAll(_theContext.getCollection(setFragment));
}
return _theContext.createSet(res);
} catch (Exception ex) {
throw new FunctionCallException("Failed to create set.",
args[0], args[1], ex);
}
}
public int arity() {
return 2;
}
}));
env.bind("$createMap", _theContext.createFunction(new Function() {
// Create a map that contains the results of applying
// the second argument (a one argument function) to
// every element in the first argument (a collection).
public Object apply(Object[] args) {
try {
Collection c = _theContext.getCollection(args[0]);
FunctionToken f = (FunctionToken) args[1];
Object[] argument = new Object[1];
Map res = new HashMap();
for (Iterator i = c.iterator(); i.hasNext();) {
argument[0] = i.next();