
dev.lukebemish.codecextras.structured.Interpreter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of codecextras Show documentation
Show all versions of codecextras Show documentation
Various extensions and utilities for Mojang's DFU library
The newest version!
package dev.lukebemish.codecextras.structured;
import com.mojang.datafixers.kinds.App;
import com.mojang.datafixers.kinds.Const;
import com.mojang.datafixers.kinds.K1;
import com.mojang.datafixers.util.Either;
import com.mojang.datafixers.util.Unit;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Dynamic;
import dev.lukebemish.codecextras.StringRepresentation;
import dev.lukebemish.codecextras.types.Identity;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
public interface Interpreter {
DataResult>> list(App single);
DataResult> keyed(Key key);
DataResult> record(List> fields, Function creator);
DataResult> flatXmap(App input, Function> to, Function> from);
DataResult> annotate(Structure original, Keys annotations);
DataResult> dispatch(String key, Structure keyStructure, Function super E, ? extends DataResult> function, Supplier> keys, Function>> structures);
default Stream> keyConsumers() {
return Stream.of();
}
public interface KeyConsumer {
Key key();
App convert(App input);
}
default DataResult> bounded(Structure input, Supplier> values) {
Function> validator = a -> {
if (values.get().contains(a)) {
return DataResult.success(a);
}
return DataResult.error(() -> "Invalid value: " + a);
};
return input.interpret(this).flatMap(a -> flatXmap(a, validator, validator));
}
DataResult>> unboundedMap(App key, App value);
Key UNIT = Key.create("UNIT");
Key BOOL = Key.create("BOOL");
Key BYTE = Key.create("BYTE");
Key SHORT = Key.create("SHORT");
Key INT = Key.create("INT");
Key LONG = Key.create("LONG");
Key FLOAT = Key.create("FLOAT");
Key DOUBLE = Key.create("DOUBLE");
Key STRING = Key.create("STRING");
Key> PASSTHROUGH = Key.create("PASSTHROUGH");
Key EMPTY_MAP = Key.create("EMPTY_MAP");
Key EMPTY_LIST = Key.create("EMPTY_LIST");
DataResult>> parametricallyKeyed(Key2 key, App parameter);
Key2>, Const.Mu> INT_IN_RANGE = Key2.create("int_in_range");
Key2>, Const.Mu> BYTE_IN_RANGE = Key2.create("byte_in_range");
Key2>, Const.Mu> SHORT_IN_RANGE = Key2.create("short_in_range");
Key2>, Const.Mu> LONG_IN_RANGE = Key2.create("long_in_range");
Key2>, Const.Mu> FLOAT_IN_RANGE = Key2.create("float_in_range");
Key2>, Const.Mu> DOUBLE_IN_RANGE = Key2.create("double_in_range");
Key2 STRING_REPRESENTABLE = Key2.create("enum");
DataResult>> either(App left, App right);
DataResult>> xor(App left, App right);
DataResult>> dispatchedMap(Structure keyStructure, Supplier> keys, Function>> valueStructures);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy