com.github.basking2.sdsai.itrex.functions.Functions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdsai-itrex Show documentation
Show all versions of sdsai-itrex Show documentation
An S-Expression inspiried library focused on iterators.
package com.github.basking2.sdsai.itrex.functions;
import com.github.basking2.sdsai.itrex.SExprRuntimeException;
import java.util.Iterator;
import java.util.function.BiFunction;
/**
* A collection of utilities for functions.
*/
public class Functions {
public static AbstractAggregatingFunction aggregator(
final R initial,
final BiFunction f
) {
return new AbstractAggregatingFunction(initial) {
@Override
public Result applyT(R r, T t) {
return new Result(true, f.apply(r, t));
}
};
}
public static T getArgument(final Iterator> iterator, final String argumentName) {
if (!iterator.hasNext()) {
throw new SExprRuntimeException("Function missing required argument "+argumentName+".");
}
final Object o = iterator.next();
@SuppressWarnings("unchecked")
final T arg = (T) o;
return arg;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy