hydra.compute.StatelessCoder Maven / Gradle / Ivy
package hydra.compute;
import hydra.Flows;
import hydra.core.Unit;
/**
* A convenience class for stateless coders; 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 StatelessCoder extends Coder {
public StatelessCoder(
java.util.function.Function> encode,
java.util.function.Function> decode) {
super(encode, decode);
}
/**
* Construct a stateless coder.
*/
public static StatelessCoder of(
java.util.function.Function> encode,
java.util.function.Function> decode) {
return new StatelessCoder(encode, decode);
}
/**
* Construct a unidirectional coder; encoding follows the provided function, while decoding will fail gracefully.
*/
public static StatelessCoder unidirectional(
java.util.function.Function> encode) {
return StatelessCoder.of(encode, v2 -> Flows.fail("decoding is not supported"));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy