diff --git a/src/main/java/com/mojang/datafixers/optics/Affine.java b/src/main/java/com/mojang/datafixers/optics/Affine.java
index 9f7e4fee..4b64505a 100644
--- a/src/main/java/com/mojang/datafixers/optics/Affine.java
+++ b/src/main/java/com/mojang/datafixers/optics/Affine.java
@@ -32,9 +32,7 @@ default
FunctionType, App2> eval(final App
return input -> cartesian.dimap(
cocartesian.left(cartesian.rmap(cartesian.first(input), p -> set(p.getFirst(), p.getSecond()))),
(S s) -> preview(s).map(Either::right, a -> Either.left(Pair.of(a, s))),
- (Either e) -> {
- return e.map(Function.identity(), Function.identity());
- }
+ Either::unwrap
);
}
diff --git a/src/main/java/com/mojang/serialization/Codec.java b/src/main/java/com/mojang/serialization/Codec.java
index 3a570a89..47a4a1ad 100644
--- a/src/main/java/com/mojang/serialization/Codec.java
+++ b/src/main/java/com/mojang/serialization/Codec.java
@@ -132,7 +132,7 @@ static Codec withAlternative(final Codec primary, final Codec extend
primary,
alternative
).xmap(
- either -> either.map(v -> v, v -> v),
+ Either::unwrap,
Either::left
);
}
diff --git a/src/main/java/com/mojang/serialization/DataResult.java b/src/main/java/com/mojang/serialization/DataResult.java
index e2504df1..b2531817 100644
--- a/src/main/java/com/mojang/serialization/DataResult.java
+++ b/src/main/java/com/mojang/serialization/DataResult.java
@@ -126,6 +126,12 @@ default DataResult addLifecycle(final Lifecycle lifecycle) {
return setLifecycle(lifecycle().add(lifecycle));
}
+ boolean isSuccess();
+
+ default boolean isError() {
+ return !isSuccess();
+ }
+
record Success(R value, Lifecycle lifecycle) implements DataResult {
@Override
public Optional result() {
@@ -223,6 +229,11 @@ public DataResult setLifecycle(final Lifecycle lifecycle) {
return new Success<>(value, lifecycle);
}
+ @Override
+ public boolean isSuccess() {
+ return true;
+ }
+
@Override
public String toString() {
return "DataResult.Success[" + value + "]";
@@ -361,6 +372,11 @@ public Error setLifecycle(final Lifecycle lifecycle) {
return new Error<>(messageSupplier, partialValue, lifecycle);
}
+ @Override
+ public boolean isSuccess() {
+ return false;
+ }
+
@Override
public String toString() {
return "DataResult.Error['" + message() + "'" + partialValue.map(value -> ": " + value).orElse("") + "]";
diff --git a/src/main/java/com/mojang/serialization/DynamicOps.java b/src/main/java/com/mojang/serialization/DynamicOps.java
index 951ab9b8..a7bd844a 100644
--- a/src/main/java/com/mojang/serialization/DynamicOps.java
+++ b/src/main/java/com/mojang/serialization/DynamicOps.java
@@ -151,7 +151,7 @@ default DataResult>> getList(final T input) {
default DataResult getByteBuffer(final T input) {
return getStream(input).flatMap(stream -> {
final List list = stream.collect(Collectors.toList());
- if (list.stream().allMatch(element -> getNumberValue(element).result().isPresent())) {
+ if (list.stream().allMatch(element -> getNumberValue(element).isSuccess())) {
final ByteBuffer buffer = ByteBuffer.wrap(new byte[list.size()]);
for (int i = 0; i < list.size(); i++) {
buffer.put(i, getNumberValue(list.get(i)).result().get().byteValue());
@@ -168,9 +168,9 @@ default T createByteList(final ByteBuffer input) {
default DataResult getIntStream(final T input) {
return getStream(input).flatMap(stream -> {
- final List list = stream.collect(Collectors.toList());
- if (list.stream().allMatch(element -> getNumberValue(element).result().isPresent())) {
- return DataResult.success(list.stream().mapToInt(element -> getNumberValue(element).result().get().intValue()));
+ final List list = stream.toList();
+ if (list.stream().allMatch(element -> getNumberValue(element).isSuccess())) {
+ return DataResult.success(list.stream().mapToInt(element -> getNumberValue(element).getOrThrow().intValue()));
}
return DataResult.error(() -> "Some elements are not ints: " + input);
});
@@ -182,9 +182,9 @@ default T createIntList(final IntStream input) {
default DataResult getLongStream(final T input) {
return getStream(input).flatMap(stream -> {
- final List list = stream.collect(Collectors.toList());
- if (list.stream().allMatch(element -> getNumberValue(element).result().isPresent())) {
- return DataResult.success(list.stream().mapToLong(element -> getNumberValue(element).result().get().longValue()));
+ final List list = stream.toList();
+ if (list.stream().allMatch(element -> getNumberValue(element).isSuccess())) {
+ return DataResult.success(list.stream().mapToLong(element -> getNumberValue(element).getOrThrow().longValue()));
}
return DataResult.error(() -> "Some elements are not longs: " + input);
});
diff --git a/src/main/java/com/mojang/serialization/codecs/BaseMapCodec.java b/src/main/java/com/mojang/serialization/codecs/BaseMapCodec.java
index 3050ee94..89835b64 100644
--- a/src/main/java/com/mojang/serialization/codecs/BaseMapCodec.java
+++ b/src/main/java/com/mojang/serialization/codecs/BaseMapCodec.java
@@ -42,7 +42,7 @@ default DataResult