/** * Invokes this closure once by applying the given set of variables to it. * @param vars The set of variables used to invoke this closure once * @return The result of the closure invocation * @throws WrongClosureInvocationException if the number of the passed variables doesn't correspond to one * with which this closure has been defined */ Object closeOne(Object... vars) throws WrongClosureInvocationException { if (invokables.isEmpty()) { unhandeledInvocations.add(vars); return null; } List<Object[]> boundParams = bindParams(vars); Object result = isClosedOnFreeVar() ? vars[0] : closed; Iterator<Object[]> argsIterator = boundParams != null ? boundParams.iterator() : null; for (Invokable invokable : invokables) { result = invokable.invoke(result, argsIterator != null ? argsIterator.next() : null); } return result; }