com.github.basking2.sdsai.itrex.functions.ThreadFunction 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.EvaluationContext;
import com.github.basking2.sdsai.itrex.SExprRuntimeException;
import com.github.basking2.sdsai.itrex.iterators.FutureIterator;
import java.util.Iterator;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import static com.github.basking2.sdsai.itrex.iterators.Iterators.toIterator;
/**
* This takes a single iterator and, for each element in that iterator, returns a single element wrapped in a Future.
*
* Use join to unwrap the value in that future.
*/
public class ThreadFunction implements FunctionInterface>> {
private final Executor executor;
public ThreadFunction(final Executor executor) {
this.executor= executor;
}
@Override
public Iterator> apply(final Iterator> iterator, final EvaluationContext evaluationContext) {
if (!iterator.hasNext()) {
throw new SExprRuntimeException("Thread function requires 1 argument that is an iterator or iterable.");
}
final Iterator
© 2015 - 2024 Weber Informatics LLC | Privacy Policy