hydra.compute.StatelessAdapter Maven / Gradle / Ivy
package hydra.compute;
import hydra.core.Unit;
import java.util.function.Function;
/**
* A convenience class for stateless adapters; we use Hydra's Unit as the state type.
* Note: using Java's Void is problematic because of the interaction of Optional with null values.
*/
public class StatelessAdapter extends Adapter {
public StatelessAdapter(boolean isLossy, T1 source, T2 target, Coder coder) {
super(isLossy, source, target, coder);
}
/**
* Construct a stateless adapter.
*/
public static StatelessAdapter of(boolean isLossy,
T1 source,
T2 target,
Coder coder) {
return new StatelessAdapter(isLossy, source, target, coder);
}
/**
* Construct a unidirectional adapter; encoding follows the provided function, while decoding will fail gracefully.
*/
public static StatelessAdapter unidirectional(
T1 source, T2 target, Function> encode) {
return StatelessAdapter.of(true, source, target, StatelessCoder.unidirectional(encode));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy