From aad6ebad69685abd4b7711039d91d5c19dfbf61f Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sat, 16 Nov 2024 17:20:52 +0100 Subject: chore: create subproject for core --- core/src/main/java/moe/nea/pcj/Codec.java | 6 + core/src/main/java/moe/nea/pcj/Decode.java | 5 + core/src/main/java/moe/nea/pcj/Encode.java | 5 + core/src/main/java/moe/nea/pcj/Operation.java | 4 + core/src/main/java/moe/nea/pcj/Result.java | 165 ++++ core/src/main/java/moe/nea/pcj/Tuple.java | 1030 ++++++++++++++++++++ core/src/main/java/moe/nea/pcj/Unit.java | 5 + core/src/main/java/moe/nea/pcj/json/AtField.java | 4 + core/src/main/java/moe/nea/pcj/json/AtIndex.java | 4 + .../main/java/moe/nea/pcj/json/BasicCodecs.java | 47 + .../java/moe/nea/pcj/json/DuplicateJsonKey.java | 4 + .../java/moe/nea/pcj/json/DuringKeyExtraction.java | 4 + core/src/main/java/moe/nea/pcj/json/InSubType.java | 4 + core/src/main/java/moe/nea/pcj/json/JsonCodec.java | 84 ++ .../main/java/moe/nea/pcj/json/JsonLikeError.java | 4 + .../java/moe/nea/pcj/json/JsonLikeOperations.java | 32 + .../main/java/moe/nea/pcj/json/ListBuilder.java | 9 + core/src/main/java/moe/nea/pcj/json/ListView.java | 14 + core/src/main/java/moe/nea/pcj/json/MapCodec.java | 64 ++ .../src/main/java/moe/nea/pcj/json/MissingKey.java | 4 + .../main/java/moe/nea/pcj/json/NamedObject.java | 4 + .../main/java/moe/nea/pcj/json/RecordBuilder.java | 12 + .../main/java/moe/nea/pcj/json/RecordCodec.java | 23 + .../main/java/moe/nea/pcj/json/RecordJoiners.java | 338 +++++++ .../src/main/java/moe/nea/pcj/json/RecordView.java | 10 + .../moe/nea/pcj/json/UnexpectedJsonElement.java | 7 + .../main/java/moe/nea/pcj/json/UnknownSubtype.java | 10 + .../main/java/moe/nea/pcj/json/package-info.java | 4 + core/src/main/java/moe/nea/pcj/package-info.java | 4 + 29 files changed, 1910 insertions(+) create mode 100644 core/src/main/java/moe/nea/pcj/Codec.java create mode 100644 core/src/main/java/moe/nea/pcj/Decode.java create mode 100644 core/src/main/java/moe/nea/pcj/Encode.java create mode 100644 core/src/main/java/moe/nea/pcj/Operation.java create mode 100644 core/src/main/java/moe/nea/pcj/Result.java create mode 100644 core/src/main/java/moe/nea/pcj/Tuple.java create mode 100644 core/src/main/java/moe/nea/pcj/Unit.java create mode 100644 core/src/main/java/moe/nea/pcj/json/AtField.java create mode 100644 core/src/main/java/moe/nea/pcj/json/AtIndex.java create mode 100644 core/src/main/java/moe/nea/pcj/json/BasicCodecs.java create mode 100644 core/src/main/java/moe/nea/pcj/json/DuplicateJsonKey.java create mode 100644 core/src/main/java/moe/nea/pcj/json/DuringKeyExtraction.java create mode 100644 core/src/main/java/moe/nea/pcj/json/InSubType.java create mode 100644 core/src/main/java/moe/nea/pcj/json/JsonCodec.java create mode 100644 core/src/main/java/moe/nea/pcj/json/JsonLikeError.java create mode 100644 core/src/main/java/moe/nea/pcj/json/JsonLikeOperations.java create mode 100644 core/src/main/java/moe/nea/pcj/json/ListBuilder.java create mode 100644 core/src/main/java/moe/nea/pcj/json/ListView.java create mode 100644 core/src/main/java/moe/nea/pcj/json/MapCodec.java create mode 100644 core/src/main/java/moe/nea/pcj/json/MissingKey.java create mode 100644 core/src/main/java/moe/nea/pcj/json/NamedObject.java create mode 100644 core/src/main/java/moe/nea/pcj/json/RecordBuilder.java create mode 100644 core/src/main/java/moe/nea/pcj/json/RecordCodec.java create mode 100644 core/src/main/java/moe/nea/pcj/json/RecordJoiners.java create mode 100644 core/src/main/java/moe/nea/pcj/json/RecordView.java create mode 100644 core/src/main/java/moe/nea/pcj/json/UnexpectedJsonElement.java create mode 100644 core/src/main/java/moe/nea/pcj/json/UnknownSubtype.java create mode 100644 core/src/main/java/moe/nea/pcj/json/package-info.java create mode 100644 core/src/main/java/moe/nea/pcj/package-info.java (limited to 'core') diff --git a/core/src/main/java/moe/nea/pcj/Codec.java b/core/src/main/java/moe/nea/pcj/Codec.java new file mode 100644 index 0000000..121e05f --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/Codec.java @@ -0,0 +1,6 @@ +package moe.nea.pcj; + +public interface Codec, DeErr, CoErr> + extends Decode, Encode { + +} diff --git a/core/src/main/java/moe/nea/pcj/Decode.java b/core/src/main/java/moe/nea/pcj/Decode.java new file mode 100644 index 0000000..d10c98a --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/Decode.java @@ -0,0 +1,5 @@ +package moe.nea.pcj; + +public interface Decode, Err> { + Result decode(Format format, Op ops); +} diff --git a/core/src/main/java/moe/nea/pcj/Encode.java b/core/src/main/java/moe/nea/pcj/Encode.java new file mode 100644 index 0000000..834ce66 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/Encode.java @@ -0,0 +1,5 @@ +package moe.nea.pcj; + +public interface Encode, Err> { + Result encode(Typ data, Op ops); +} diff --git a/core/src/main/java/moe/nea/pcj/Operation.java b/core/src/main/java/moe/nea/pcj/Operation.java new file mode 100644 index 0000000..90995ef --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/Operation.java @@ -0,0 +1,4 @@ +package moe.nea.pcj; + +public interface Operation { +} diff --git a/core/src/main/java/moe/nea/pcj/Result.java b/core/src/main/java/moe/nea/pcj/Result.java new file mode 100644 index 0000000..a9c2494 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/Result.java @@ -0,0 +1,165 @@ +package moe.nea.pcj; + +import org.jspecify.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; + +public sealed interface Result permits Result.Ok, Result.Fail { + default boolean isOk() { + return errors().isEmpty(); + } + + Optional value(); + + Optional partial(); + + default Optional valueOrPartial() { + return value().or(this::partial); + } + + List errors(); + + default Result map(Function mapper) { + return flatMap(mapper.andThen(Result::ok)); + } + + Result flatMap(Function> mapper); + + default Result mapError(Function mapper) { + return mapErrors(it -> it.stream().map(mapper).toList()); + } + + Result mapErrors(Function, List> mapper); + + default Result appendError(Bad error) { + return appendErrors(List.of(error)); + } + + Result appendErrors(List error); + + record Ok(Good okValue) implements Result { + @Override + public Result appendErrors(List errors) { + if (errors.isEmpty()) return new Ok<>(okValue); + return new Fail<>(okValue, errors); + } + + @Override + public Result mapErrors(Function, List> mapper) { + return new Ok<>(okValue); + } + + @Override + public Optional partial() { + return Optional.empty(); + } + + @Override + public List errors() { + return List.of(); + } + + @Override + public Result flatMap(Function> mapper) { + return Result.cast(mapper.apply(okValue)); + } + + @Override + public Optional value() { + return Optional.of(okValue); + } + + @Override + public int hashCode() { + return Objects.hash(okValue); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj instanceof Result.Ok ok) { + return Objects.equals(ok.okValue, this.okValue); + } + return false; + } + } + + record Fail(@Nullable Good partialValue, List badValue) implements Result { + public Fail { + if (badValue.isEmpty()) + throw new IllegalArgumentException("Cannot create failure without any error values"); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj instanceof Result.Fail fail) { + return Objects.equals(partialValue, fail.partialValue) && badValue.equals(fail.badValue); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(partialValue, badValue); + } + + @Override + public Optional value() { + return Optional.empty(); + } + + @Override + public Optional partial() { + return Optional.ofNullable(partialValue); + } + + @Override + public List errors() { + return Collections.unmodifiableList(badValue); + } + + @Override + public Result flatMap(Function> mapper) { + if (partialValue != null) { + return Result.cast(mapper.apply(partialValue)).appendErrors(badValue); + } + return new Fail<>(null, badValue); + } + + @Override + public Result mapErrors(Function, List> mapper) { + return new Fail<>(partialValue, mapper.apply(badValue)); + } + + @Override + public Result appendErrors(List errors) { + var nextErrors = new ArrayList<>(badValue); + nextErrors.addAll(errors); + return new Fail<>(partialValue, nextErrors); + } + } + + static Result ok(Good value) { + return new Ok<>(value); + } + + static Result.Fail fail(Bad error) { + return new Fail<>(null, List.of(error)); + } + + + static Result cast(Result c) { + //noinspection unchecked + return (Result) c; + } + + static Result.Fail partial(@Nullable Good partial, Bad error) { + return new Fail<>(partial, List.of(error)); + } +} diff --git a/core/src/main/java/moe/nea/pcj/Tuple.java b/core/src/main/java/moe/nea/pcj/Tuple.java new file mode 100644 index 0000000..e6207ff --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/Tuple.java @@ -0,0 +1,1030 @@ +// @generated by gentuples.ts +package moe.nea.pcj; + +@SuppressWarnings("unused") +public interface Tuple { + class Tuple0 implements Tuple { + public R applyTo(Func0 func) { + return func.apply(); + } + + public static Result collect(Tuple0 tuple) { + return + Result.ok(new Tuple0()) + ; + } + + public Tuple0 map() { + return new Tuple0(); + } + + public Tuple0 join(Tuple0 other) { + return new Tuple0(); + } + + public Tuple1 join(Tuple1 other) { + return new Tuple1<>(other.element0); + } + + public Tuple2 join(Tuple2 other) { + return new Tuple2<>(other.element0, other.element1); + } + + public Tuple3 join(Tuple3 other) { + return new Tuple3<>(other.element0, other.element1, other.element2); + } + + public Tuple4 join(Tuple4 other) { + return new Tuple4<>(other.element0, other.element1, other.element2, other.element3); + } + + public Tuple5 join(Tuple5 other) { + return new Tuple5<>(other.element0, other.element1, other.element2, other.element3, other.element4); + } + + public Tuple6 join(Tuple6 other) { + return new Tuple6<>(other.element0, other.element1, other.element2, other.element3, other.element4, other.element5); + } + + public Tuple7 join(Tuple7 other) { + return new Tuple7<>(other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6); + } + + public Tuple8 join(Tuple8 other) { + return new Tuple8<>(other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7); + } + + public Tuple9 join(Tuple9 other) { + return new Tuple9<>(other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8); + } + + public Tuple10 join(Tuple10 other) { + return new Tuple10<>(other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9); + } + + public Tuple11 join(Tuple11 other) { + return new Tuple11<>(other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9, other.element10); + } + + public Tuple12 join(Tuple12 other) { + return new Tuple12<>(other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9, other.element10, other.element11); + } + + public Tuple13 join(Tuple13 other) { + return new Tuple13<>(other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9, other.element10, other.element11, other.element12); + } + + public Tuple14 join(Tuple14 other) { + return new Tuple14<>(other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9, other.element10, other.element11, other.element12, other.element13); + } + } + + @FunctionalInterface + interface Func0 { + R apply(); + } + + record Tuple1(T0 element0) { + public R applyTo(Func1 func) { + return func.apply(this.element0); + } + + public static Result, R> collect(Tuple1> tuple) { + return + tuple.element0.flatMap(element0 -> + Result.ok(new Tuple1<>(element0)) + ) + ; + } + + public Tuple1 map(Func1 map0) { + return new Tuple1<>(map0.apply(this.element0)); + } + + public Tuple1 join(Tuple0 other) { + return new Tuple1<>(this.element0); + } + + public Tuple2 join(Tuple1 other) { + return new Tuple2<>(this.element0, other.element0); + } + + public Tuple3 join(Tuple2 other) { + return new Tuple3<>(this.element0, other.element0, other.element1); + } + + public Tuple4 join(Tuple3 other) { + return new Tuple4<>(this.element0, other.element0, other.element1, other.element2); + } + + public Tuple5 join(Tuple4 other) { + return new Tuple5<>(this.element0, other.element0, other.element1, other.element2, other.element3); + } + + public Tuple6 join(Tuple5 other) { + return new Tuple6<>(this.element0, other.element0, other.element1, other.element2, other.element3, other.element4); + } + + public Tuple7 join(Tuple6 other) { + return new Tuple7<>(this.element0, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5); + } + + public Tuple8 join(Tuple7 other) { + return new Tuple8<>(this.element0, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6); + } + + public Tuple9 join(Tuple8 other) { + return new Tuple9<>(this.element0, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7); + } + + public Tuple10 join(Tuple9 other) { + return new Tuple10<>(this.element0, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8); + } + + public Tuple11 join(Tuple10 other) { + return new Tuple11<>(this.element0, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9); + } + + public Tuple12 join(Tuple11 other) { + return new Tuple12<>(this.element0, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9, other.element10); + } + + public Tuple13 join(Tuple12 other) { + return new Tuple13<>(this.element0, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9, other.element10, other.element11); + } + + public Tuple14 join(Tuple13 other) { + return new Tuple14<>(this.element0, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9, other.element10, other.element11, other.element12); + } + } + + @FunctionalInterface + interface Func1 { + R apply(T0 arg0); + } + + record Tuple2(T0 element0, T1 element1) { + public R applyTo(Func2 func) { + return func.apply(this.element0, this.element1); + } + + public static Result, R> collect(Tuple2, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + Result.ok(new Tuple2<>(element0, element1)) + ) + ) + ; + } + + public Tuple2 map(Func1 map0, Func1 map1) { + return new Tuple2<>(map0.apply(this.element0), map1.apply(this.element1)); + } + + public Tuple2 join(Tuple0 other) { + return new Tuple2<>(this.element0, this.element1); + } + + public Tuple3 join(Tuple1 other) { + return new Tuple3<>(this.element0, this.element1, other.element0); + } + + public Tuple4 join(Tuple2 other) { + return new Tuple4<>(this.element0, this.element1, other.element0, other.element1); + } + + public Tuple5 join(Tuple3 other) { + return new Tuple5<>(this.element0, this.element1, other.element0, other.element1, other.element2); + } + + public Tuple6 join(Tuple4 other) { + return new Tuple6<>(this.element0, this.element1, other.element0, other.element1, other.element2, other.element3); + } + + public Tuple7 join(Tuple5 other) { + return new Tuple7<>(this.element0, this.element1, other.element0, other.element1, other.element2, other.element3, other.element4); + } + + public Tuple8 join(Tuple6 other) { + return new Tuple8<>(this.element0, this.element1, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5); + } + + public Tuple9 join(Tuple7 other) { + return new Tuple9<>(this.element0, this.element1, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6); + } + + public Tuple10 join(Tuple8 other) { + return new Tuple10<>(this.element0, this.element1, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7); + } + + public Tuple11 join(Tuple9 other) { + return new Tuple11<>(this.element0, this.element1, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8); + } + + public Tuple12 join(Tuple10 other) { + return new Tuple12<>(this.element0, this.element1, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9); + } + + public Tuple13 join(Tuple11 other) { + return new Tuple13<>(this.element0, this.element1, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9, other.element10); + } + + public Tuple14 join(Tuple12 other) { + return new Tuple14<>(this.element0, this.element1, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9, other.element10, other.element11); + } + } + + @FunctionalInterface + interface Func2 { + R apply(T0 arg0, T1 arg1); + } + + record Tuple3(T0 element0, T1 element1, T2 element2) { + public R applyTo(Func3 func) { + return func.apply(this.element0, this.element1, this.element2); + } + + public static Result, R> collect(Tuple3, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + Result.ok(new Tuple3<>(element0, element1, element2)) + ) + ) + ) + ; + } + + public Tuple3 map(Func1 map0, Func1 map1, Func1 map2) { + return new Tuple3<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2)); + } + + public Tuple3 join(Tuple0 other) { + return new Tuple3<>(this.element0, this.element1, this.element2); + } + + public Tuple4 join(Tuple1 other) { + return new Tuple4<>(this.element0, this.element1, this.element2, other.element0); + } + + public Tuple5 join(Tuple2 other) { + return new Tuple5<>(this.element0, this.element1, this.element2, other.element0, other.element1); + } + + public Tuple6 join(Tuple3 other) { + return new Tuple6<>(this.element0, this.element1, this.element2, other.element0, other.element1, other.element2); + } + + public Tuple7 join(Tuple4 other) { + return new Tuple7<>(this.element0, this.element1, this.element2, other.element0, other.element1, other.element2, other.element3); + } + + public Tuple8 join(Tuple5 other) { + return new Tuple8<>(this.element0, this.element1, this.element2, other.element0, other.element1, other.element2, other.element3, other.element4); + } + + public Tuple9 join(Tuple6 other) { + return new Tuple9<>(this.element0, this.element1, this.element2, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5); + } + + public Tuple10 join(Tuple7 other) { + return new Tuple10<>(this.element0, this.element1, this.element2, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6); + } + + public Tuple11 join(Tuple8 other) { + return new Tuple11<>(this.element0, this.element1, this.element2, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7); + } + + public Tuple12 join(Tuple9 other) { + return new Tuple12<>(this.element0, this.element1, this.element2, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8); + } + + public Tuple13 join(Tuple10 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9); + } + + public Tuple14 join(Tuple11 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9, other.element10); + } + } + + @FunctionalInterface + interface Func3 { + R apply(T0 arg0, T1 arg1, T2 arg2); + } + + record Tuple4(T0 element0, T1 element1, T2 element2, T3 element3) { + public R applyTo(Func4 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3); + } + + public static Result, R> collect(Tuple4, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + Result.ok(new Tuple4<>(element0, element1, element2, element3)) + ) + ) + ) + ) + ; + } + + public Tuple4 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3) { + return new Tuple4<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3)); + } + + public Tuple4 join(Tuple0 other) { + return new Tuple4<>(this.element0, this.element1, this.element2, this.element3); + } + + public Tuple5 join(Tuple1 other) { + return new Tuple5<>(this.element0, this.element1, this.element2, this.element3, other.element0); + } + + public Tuple6 join(Tuple2 other) { + return new Tuple6<>(this.element0, this.element1, this.element2, this.element3, other.element0, other.element1); + } + + public Tuple7 join(Tuple3 other) { + return new Tuple7<>(this.element0, this.element1, this.element2, this.element3, other.element0, other.element1, other.element2); + } + + public Tuple8 join(Tuple4 other) { + return new Tuple8<>(this.element0, this.element1, this.element2, this.element3, other.element0, other.element1, other.element2, other.element3); + } + + public Tuple9 join(Tuple5 other) { + return new Tuple9<>(this.element0, this.element1, this.element2, this.element3, other.element0, other.element1, other.element2, other.element3, other.element4); + } + + public Tuple10 join(Tuple6 other) { + return new Tuple10<>(this.element0, this.element1, this.element2, this.element3, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5); + } + + public Tuple11 join(Tuple7 other) { + return new Tuple11<>(this.element0, this.element1, this.element2, this.element3, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6); + } + + public Tuple12 join(Tuple8 other) { + return new Tuple12<>(this.element0, this.element1, this.element2, this.element3, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7); + } + + public Tuple13 join(Tuple9 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, this.element3, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8); + } + + public Tuple14 join(Tuple10 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8, other.element9); + } + } + + @FunctionalInterface + interface Func4 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3); + } + + record Tuple5(T0 element0, T1 element1, T2 element2, T3 element3, T4 element4) { + public R applyTo(Func5 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3, this.element4); + } + + public static Result, R> collect(Tuple5, Result, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + tuple.element4.flatMap(element4 -> + Result.ok(new Tuple5<>(element0, element1, element2, element3, element4)) + ) + ) + ) + ) + ) + ; + } + + public Tuple5 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3, Func1 map4) { + return new Tuple5<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3), map4.apply(this.element4)); + } + + public Tuple5 join(Tuple0 other) { + return new Tuple5<>(this.element0, this.element1, this.element2, this.element3, this.element4); + } + + public Tuple6 join(Tuple1 other) { + return new Tuple6<>(this.element0, this.element1, this.element2, this.element3, this.element4, other.element0); + } + + public Tuple7 join(Tuple2 other) { + return new Tuple7<>(this.element0, this.element1, this.element2, this.element3, this.element4, other.element0, other.element1); + } + + public Tuple8 join(Tuple3 other) { + return new Tuple8<>(this.element0, this.element1, this.element2, this.element3, this.element4, other.element0, other.element1, other.element2); + } + + public Tuple9 join(Tuple4 other) { + return new Tuple9<>(this.element0, this.element1, this.element2, this.element3, this.element4, other.element0, other.element1, other.element2, other.element3); + } + + public Tuple10 join(Tuple5 other) { + return new Tuple10<>(this.element0, this.element1, this.element2, this.element3, this.element4, other.element0, other.element1, other.element2, other.element3, other.element4); + } + + public Tuple11 join(Tuple6 other) { + return new Tuple11<>(this.element0, this.element1, this.element2, this.element3, this.element4, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5); + } + + public Tuple12 join(Tuple7 other) { + return new Tuple12<>(this.element0, this.element1, this.element2, this.element3, this.element4, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6); + } + + public Tuple13 join(Tuple8 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, this.element3, this.element4, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7); + } + + public Tuple14 join(Tuple9 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, this.element4, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7, other.element8); + } + } + + @FunctionalInterface + interface Func5 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4); + } + + record Tuple6(T0 element0, T1 element1, T2 element2, T3 element3, T4 element4, + T5 element5) { + public R applyTo(Func6 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5); + } + + public static Result, R> collect(Tuple6, Result, Result, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + tuple.element4.flatMap(element4 -> + tuple.element5.flatMap(element5 -> + Result.ok(new Tuple6<>(element0, element1, element2, element3, element4, element5)) + ) + ) + ) + ) + ) + ) + ; + } + + public Tuple6 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3, Func1 map4, Func1 map5) { + return new Tuple6<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3), map4.apply(this.element4), map5.apply(this.element5)); + } + + public Tuple6 join(Tuple0 other) { + return new Tuple6<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5); + } + + public Tuple7 join(Tuple1 other) { + return new Tuple7<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, other.element0); + } + + public Tuple8 join(Tuple2 other) { + return new Tuple8<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, other.element0, other.element1); + } + + public Tuple9 join(Tuple3 other) { + return new Tuple9<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, other.element0, other.element1, other.element2); + } + + public Tuple10 join(Tuple4 other) { + return new Tuple10<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, other.element0, other.element1, other.element2, other.element3); + } + + public Tuple11 join(Tuple5 other) { + return new Tuple11<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, other.element0, other.element1, other.element2, other.element3, other.element4); + } + + public Tuple12 join(Tuple6 other) { + return new Tuple12<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5); + } + + public Tuple13 join(Tuple7 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6); + } + + public Tuple14 join(Tuple8 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6, other.element7); + } + } + + @FunctionalInterface + interface Func6 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); + } + + record Tuple7(T0 element0, T1 element1, T2 element2, T3 element3, T4 element4, + T5 element5, T6 element6) { + public R applyTo(Func7 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6); + } + + public static Result, R> collect(Tuple7, Result, Result, Result, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + tuple.element4.flatMap(element4 -> + tuple.element5.flatMap(element5 -> + tuple.element6.flatMap(element6 -> + Result.ok(new Tuple7<>(element0, element1, element2, element3, element4, element5, element6)) + ) + ) + ) + ) + ) + ) + ) + ; + } + + public Tuple7 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3, Func1 map4, Func1 map5, Func1 map6) { + return new Tuple7<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3), map4.apply(this.element4), map5.apply(this.element5), map6.apply(this.element6)); + } + + public Tuple7 join(Tuple0 other) { + return new Tuple7<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6); + } + + public Tuple8 join(Tuple1 other) { + return new Tuple8<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, other.element0); + } + + public Tuple9 join(Tuple2 other) { + return new Tuple9<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, other.element0, other.element1); + } + + public Tuple10 join(Tuple3 other) { + return new Tuple10<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, other.element0, other.element1, other.element2); + } + + public Tuple11 join(Tuple4 other) { + return new Tuple11<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, other.element0, other.element1, other.element2, other.element3); + } + + public Tuple12 join(Tuple5 other) { + return new Tuple12<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, other.element0, other.element1, other.element2, other.element3, other.element4); + } + + public Tuple13 join(Tuple6 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5); + } + + public Tuple14 join(Tuple7 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5, other.element6); + } + } + + @FunctionalInterface + interface Func7 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); + } + + record Tuple8(T0 element0, T1 element1, T2 element2, T3 element3, T4 element4, + T5 element5, T6 element6, T7 element7) { + public R applyTo(Func8 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7); + } + + public static Result, R> collect(Tuple8, Result, Result, Result, Result, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + tuple.element4.flatMap(element4 -> + tuple.element5.flatMap(element5 -> + tuple.element6.flatMap(element6 -> + tuple.element7.flatMap(element7 -> + Result.ok(new Tuple8<>(element0, element1, element2, element3, element4, element5, element6, element7)) + ) + ) + ) + ) + ) + ) + ) + ) + ; + } + + public Tuple8 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3, Func1 map4, Func1 map5, Func1 map6, Func1 map7) { + return new Tuple8<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3), map4.apply(this.element4), map5.apply(this.element5), map6.apply(this.element6), map7.apply(this.element7)); + } + + public Tuple8 join(Tuple0 other) { + return new Tuple8<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7); + } + + public Tuple9 join(Tuple1 other) { + return new Tuple9<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, other.element0); + } + + public Tuple10 join(Tuple2 other) { + return new Tuple10<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, other.element0, other.element1); + } + + public Tuple11 join(Tuple3 other) { + return new Tuple11<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, other.element0, other.element1, other.element2); + } + + public Tuple12 join(Tuple4 other) { + return new Tuple12<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, other.element0, other.element1, other.element2, other.element3); + } + + public Tuple13 join(Tuple5 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, other.element0, other.element1, other.element2, other.element3, other.element4); + } + + public Tuple14 join(Tuple6 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, other.element0, other.element1, other.element2, other.element3, other.element4, other.element5); + } + } + + @FunctionalInterface + interface Func8 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); + } + + record Tuple9(T0 element0, T1 element1, T2 element2, T3 element3, T4 element4, + T5 element5, T6 element6, T7 element7, T8 element8) { + public R applyTo(Func9 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8); + } + + public static Result, R> collect(Tuple9, Result, Result, Result, Result, Result, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + tuple.element4.flatMap(element4 -> + tuple.element5.flatMap(element5 -> + tuple.element6.flatMap(element6 -> + tuple.element7.flatMap(element7 -> + tuple.element8.flatMap(element8 -> + Result.ok(new Tuple9<>(element0, element1, element2, element3, element4, element5, element6, element7, element8)) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ; + } + + public Tuple9 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3, Func1 map4, Func1 map5, Func1 map6, Func1 map7, Func1 map8) { + return new Tuple9<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3), map4.apply(this.element4), map5.apply(this.element5), map6.apply(this.element6), map7.apply(this.element7), map8.apply(this.element8)); + } + + public Tuple9 join(Tuple0 other) { + return new Tuple9<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8); + } + + public Tuple10 join(Tuple1 other) { + return new Tuple10<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, other.element0); + } + + public Tuple11 join(Tuple2 other) { + return new Tuple11<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, other.element0, other.element1); + } + + public Tuple12 join(Tuple3 other) { + return new Tuple12<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, other.element0, other.element1, other.element2); + } + + public Tuple13 join(Tuple4 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, other.element0, other.element1, other.element2, other.element3); + } + + public Tuple14 join(Tuple5 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, other.element0, other.element1, other.element2, other.element3, other.element4); + } + } + + @FunctionalInterface + interface Func9 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); + } + + record Tuple10(T0 element0, T1 element1, T2 element2, T3 element3, + T4 element4, T5 element5, T6 element6, T7 element7, + T8 element8, T9 element9) { + public R applyTo(Func10 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9); + } + + public static Result, R> collect(Tuple10, Result, Result, Result, Result, Result, Result, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + tuple.element4.flatMap(element4 -> + tuple.element5.flatMap(element5 -> + tuple.element6.flatMap(element6 -> + tuple.element7.flatMap(element7 -> + tuple.element8.flatMap(element8 -> + tuple.element9.flatMap(element9 -> + Result.ok(new Tuple10<>(element0, element1, element2, element3, element4, element5, element6, element7, element8, element9)) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ; + } + + public Tuple10 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3, Func1 map4, Func1 map5, Func1 map6, Func1 map7, Func1 map8, Func1 map9) { + return new Tuple10<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3), map4.apply(this.element4), map5.apply(this.element5), map6.apply(this.element6), map7.apply(this.element7), map8.apply(this.element8), map9.apply(this.element9)); + } + + public Tuple10 join(Tuple0 other) { + return new Tuple10<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9); + } + + public Tuple11 join(Tuple1 other) { + return new Tuple11<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, other.element0); + } + + public Tuple12 join(Tuple2 other) { + return new Tuple12<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, other.element0, other.element1); + } + + public Tuple13 join(Tuple3 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, other.element0, other.element1, other.element2); + } + + public Tuple14 join(Tuple4 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, other.element0, other.element1, other.element2, other.element3); + } + } + + @FunctionalInterface + interface Func10 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); + } + + record Tuple11(T0 element0, T1 element1, T2 element2, T3 element3, + T4 element4, T5 element5, T6 element6, T7 element7, + T8 element8, T9 element9, T10 element10) { + public R applyTo(Func11 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10); + } + + public static Result, R> collect(Tuple11, Result, Result, Result, Result, Result, Result, Result, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + tuple.element4.flatMap(element4 -> + tuple.element5.flatMap(element5 -> + tuple.element6.flatMap(element6 -> + tuple.element7.flatMap(element7 -> + tuple.element8.flatMap(element8 -> + tuple.element9.flatMap(element9 -> + tuple.element10.flatMap(element10 -> + Result.ok(new Tuple11<>(element0, element1, element2, element3, element4, element5, element6, element7, element8, element9, element10)) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ; + } + + public Tuple11 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3, Func1 map4, Func1 map5, Func1 map6, Func1 map7, Func1 map8, Func1 map9, Func1 map10) { + return new Tuple11<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3), map4.apply(this.element4), map5.apply(this.element5), map6.apply(this.element6), map7.apply(this.element7), map8.apply(this.element8), map9.apply(this.element9), map10.apply(this.element10)); + } + + public Tuple11 join(Tuple0 other) { + return new Tuple11<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10); + } + + public Tuple12 join(Tuple1 other) { + return new Tuple12<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, other.element0); + } + + public Tuple13 join(Tuple2 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, other.element0, other.element1); + } + + public Tuple14 join(Tuple3 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, other.element0, other.element1, other.element2); + } + } + + @FunctionalInterface + interface Func11 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10); + } + + record Tuple12(T0 element0, T1 element1, T2 element2, T3 element3, + T4 element4, T5 element5, T6 element6, T7 element7, + T8 element8, T9 element9, T10 element10, + T11 element11) { + public R applyTo(Func12 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, this.element11); + } + + public static Result, R> collect(Tuple12, Result, Result, Result, Result, Result, Result, Result, Result, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + tuple.element4.flatMap(element4 -> + tuple.element5.flatMap(element5 -> + tuple.element6.flatMap(element6 -> + tuple.element7.flatMap(element7 -> + tuple.element8.flatMap(element8 -> + tuple.element9.flatMap(element9 -> + tuple.element10.flatMap(element10 -> + tuple.element11.flatMap(element11 -> + Result.ok(new Tuple12<>(element0, element1, element2, element3, element4, element5, element6, element7, element8, element9, element10, element11)) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ; + } + + public Tuple12 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3, Func1 map4, Func1 map5, Func1 map6, Func1 map7, Func1 map8, Func1 map9, Func1 map10, Func1 map11) { + return new Tuple12<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3), map4.apply(this.element4), map5.apply(this.element5), map6.apply(this.element6), map7.apply(this.element7), map8.apply(this.element8), map9.apply(this.element9), map10.apply(this.element10), map11.apply(this.element11)); + } + + public Tuple12 join(Tuple0 other) { + return new Tuple12<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, this.element11); + } + + public Tuple13 join(Tuple1 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, this.element11, other.element0); + } + + public Tuple14 join(Tuple2 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, this.element11, other.element0, other.element1); + } + } + + @FunctionalInterface + interface Func12 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11); + } + + record Tuple13(T0 element0, T1 element1, T2 element2, + T3 element3, T4 element4, T5 element5, + T6 element6, T7 element7, T8 element8, + T9 element9, T10 element10, T11 element11, + T12 element12) { + public R applyTo(Func13 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, this.element11, this.element12); + } + + public static Result, R> collect(Tuple13, Result, Result, Result, Result, Result, Result, Result, Result, Result, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + tuple.element4.flatMap(element4 -> + tuple.element5.flatMap(element5 -> + tuple.element6.flatMap(element6 -> + tuple.element7.flatMap(element7 -> + tuple.element8.flatMap(element8 -> + tuple.element9.flatMap(element9 -> + tuple.element10.flatMap(element10 -> + tuple.element11.flatMap(element11 -> + tuple.element12.flatMap(element12 -> + Result.ok(new Tuple13<>(element0, element1, element2, element3, element4, element5, element6, element7, element8, element9, element10, element11, element12)) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ; + } + + public Tuple13 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3, Func1 map4, Func1 map5, Func1 map6, Func1 map7, Func1 map8, Func1 map9, Func1 map10, Func1 map11, Func1 map12) { + return new Tuple13<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3), map4.apply(this.element4), map5.apply(this.element5), map6.apply(this.element6), map7.apply(this.element7), map8.apply(this.element8), map9.apply(this.element9), map10.apply(this.element10), map11.apply(this.element11), map12.apply(this.element12)); + } + + public Tuple13 join(Tuple0 other) { + return new Tuple13<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, this.element11, this.element12); + } + + public Tuple14 join(Tuple1 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, this.element11, this.element12, other.element0); + } + } + + @FunctionalInterface + interface Func13 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12); + } + + record Tuple14(T0 element0, T1 element1, T2 element2, + T3 element3, T4 element4, T5 element5, + T6 element6, T7 element7, T8 element8, + T9 element9, T10 element10, + T11 element11, T12 element12, + T13 element13) { + public R applyTo(Func14 func) { + return func.apply(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, this.element11, this.element12, this.element13); + } + + public static Result, R> collect(Tuple14, Result, Result, Result, Result, Result, Result, Result, Result, Result, Result, Result, Result, Result> tuple) { + return + tuple.element0.flatMap(element0 -> + tuple.element1.flatMap(element1 -> + tuple.element2.flatMap(element2 -> + tuple.element3.flatMap(element3 -> + tuple.element4.flatMap(element4 -> + tuple.element5.flatMap(element5 -> + tuple.element6.flatMap(element6 -> + tuple.element7.flatMap(element7 -> + tuple.element8.flatMap(element8 -> + tuple.element9.flatMap(element9 -> + tuple.element10.flatMap(element10 -> + tuple.element11.flatMap(element11 -> + tuple.element12.flatMap(element12 -> + tuple.element13.flatMap(element13 -> + Result.ok(new Tuple14<>(element0, element1, element2, element3, element4, element5, element6, element7, element8, element9, element10, element11, element12, element13)) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ; + } + + public Tuple14 map(Func1 map0, Func1 map1, Func1 map2, Func1 map3, Func1 map4, Func1 map5, Func1 map6, Func1 map7, Func1 map8, Func1 map9, Func1 map10, Func1 map11, Func1 map12, Func1 map13) { + return new Tuple14<>(map0.apply(this.element0), map1.apply(this.element1), map2.apply(this.element2), map3.apply(this.element3), map4.apply(this.element4), map5.apply(this.element5), map6.apply(this.element6), map7.apply(this.element7), map8.apply(this.element8), map9.apply(this.element9), map10.apply(this.element10), map11.apply(this.element11), map12.apply(this.element12), map13.apply(this.element13)); + } + + public Tuple14 join(Tuple0 other) { + return new Tuple14<>(this.element0, this.element1, this.element2, this.element3, this.element4, this.element5, this.element6, this.element7, this.element8, this.element9, this.element10, this.element11, this.element12, this.element13); + } + } + + @FunctionalInterface + interface Func14 { + R apply(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13); + } +} diff --git a/core/src/main/java/moe/nea/pcj/Unit.java b/core/src/main/java/moe/nea/pcj/Unit.java new file mode 100644 index 0000000..435d763 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/Unit.java @@ -0,0 +1,5 @@ +package moe.nea.pcj; + +public enum Unit { + INSTANCE; +} diff --git a/core/src/main/java/moe/nea/pcj/json/AtField.java b/core/src/main/java/moe/nea/pcj/json/AtField.java new file mode 100644 index 0000000..3780e38 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/AtField.java @@ -0,0 +1,4 @@ +package moe.nea.pcj.json; + +public record AtField(String field, JsonLikeError error) implements JsonLikeError { +} diff --git a/core/src/main/java/moe/nea/pcj/json/AtIndex.java b/core/src/main/java/moe/nea/pcj/json/AtIndex.java new file mode 100644 index 0000000..ec01112 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/AtIndex.java @@ -0,0 +1,4 @@ +package moe.nea.pcj.json; + +public record AtIndex(int index, JsonLikeError error) implements JsonLikeError { +} diff --git a/core/src/main/java/moe/nea/pcj/json/BasicCodecs.java b/core/src/main/java/moe/nea/pcj/json/BasicCodecs.java new file mode 100644 index 0000000..565711d --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/BasicCodecs.java @@ -0,0 +1,47 @@ +package moe.nea.pcj.json; + +import moe.nea.pcj.Result; + +public class BasicCodecs { + protected BasicCodecs() {} + + public static BasicCodecs create() { + return new BasicCodecs<>(); + } + + public final JsonCodec STRING = new JsonCodec<>() { + @Override + public Result decode(Format format, JsonLikeOperations ops) { + return ops.getString(format); + } + + @Override + public Result encode(String data, JsonLikeOperations ops) { + return Result.ok(ops.createString(data)); + } + }; + + public final JsonCodec FLOAT = new JsonCodec() { + @Override + public Result decode(Format format, JsonLikeOperations ops) { + return ops.getNumeric(format).map(Number::floatValue); + } + + @Override + public Result encode(Float data, JsonLikeOperations ops) { + return Result.ok(ops.createNumeric(data)); + } + }; + + public final JsonCodec INTEGER = new JsonCodec<>() { + @Override + public Result decode(Format format, JsonLikeOperations ops) { + return ops.getNumeric(format).map(Number::intValue); // TODO: filter for valid ints + } + + @Override + public Result encode(Integer data, JsonLikeOperations ops) { + return Result.ok(ops.createNumeric(data)); + } + }; +} \ No newline at end of file diff --git a/core/src/main/java/moe/nea/pcj/json/DuplicateJsonKey.java b/core/src/main/java/moe/nea/pcj/json/DuplicateJsonKey.java new file mode 100644 index 0000000..13d81db --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/DuplicateJsonKey.java @@ -0,0 +1,4 @@ +package moe.nea.pcj.json; + +public record DuplicateJsonKey(String key) implements JsonLikeError { +} diff --git a/core/src/main/java/moe/nea/pcj/json/DuringKeyExtraction.java b/core/src/main/java/moe/nea/pcj/json/DuringKeyExtraction.java new file mode 100644 index 0000000..859f98f --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/DuringKeyExtraction.java @@ -0,0 +1,4 @@ +package moe.nea.pcj.json; + +public record DuringKeyExtraction(JsonLikeError error) implements JsonLikeError { +} diff --git a/core/src/main/java/moe/nea/pcj/json/InSubType.java b/core/src/main/java/moe/nea/pcj/json/InSubType.java new file mode 100644 index 0000000..ae62a73 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/InSubType.java @@ -0,0 +1,4 @@ +package moe.nea.pcj.json; + +public record InSubType(T typeTag, JsonLikeError error) implements JsonLikeError { +} diff --git a/core/src/main/java/moe/nea/pcj/json/JsonCodec.java b/core/src/main/java/moe/nea/pcj/json/JsonCodec.java new file mode 100644 index 0000000..c5c750b --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/JsonCodec.java @@ -0,0 +1,84 @@ +package moe.nea.pcj.json; + +import moe.nea.pcj.Codec; +import moe.nea.pcj.Result; + +import java.util.ArrayList; +import java.util.List; + +public interface JsonCodec extends Codec< + T, Format, JsonLikeOperations, + JsonLikeError, JsonLikeError> { + + default JsonCodec, Format> listOf() { + return new JsonCodec<>() { + @Override + public Result encode(List data, JsonLikeOperations ops) { + var list = ops.createList(); + var erros = new ArrayList(); + for (int i = 0; i < data.size(); i++) { + var datum = data.get(i); + final var index = i; + var result = JsonCodec.this.encode(datum, ops) + .mapError(it -> new AtIndex(index, it)); + erros.addAll(result.errors()); + result.valueOrPartial().ifPresent(list::add); + } + return Result.ok(list.complete()).appendErrors(erros); + } + + @Override + public Result, JsonLikeError> decode(Format format, JsonLikeOperations ops) { + var view = Result., JsonLikeError>cast(ops.getList(format)); + return view.flatMap(elements -> { + var acc = new ArrayList(elements.length()); + var errors = new ArrayList(); + for (int i = 0; i < elements.length(); i++) { + final var index = i; + var result = JsonCodec.this.decode(elements.getUnsafe(i), ops) + .mapError(it -> new AtIndex(index, it)); + errors.addAll(result.errors()); + result.valueOrPartial().ifPresent(acc::add); + } + return Result., JsonLikeError>ok(acc).appendErrors(errors); + }); + } + }; + } + + default JsonCodec named(String name) { + return new JsonCodec<>() { + @Override + public Result decode(Format format, JsonLikeOperations ops) { + return JsonCodec.this.decode(format, ops).mapError(it -> new NamedObject(name, it)); + } + + @Override + public Result encode(T data, JsonLikeOperations ops) { + return JsonCodec.this.encode(data, ops).mapError(it -> new NamedObject(name, it)); + } + }; + } + + default MapCodec fieldOf(String key) { + return new MapCodec<>() { + @Override + public Result decode(RecordView record, JsonLikeOperations ops) { + return record.get(key) + .map(element -> Result.cast( + JsonCodec.this.decode(element, ops) + .mapError(it -> new AtField(key, it)))) + .orElseGet(() -> Result.fail(new MissingKey(key))); + } + + @Override + public Result, JsonLikeError> encode(T value, JsonLikeOperations ops) { + var record = ops.createObject(); + return Result.cast(JsonCodec.this.encode(value, ops)) + .mapError(it -> new AtField(key, it)) + .flatMap(json -> Result.cast(record.add(key, json).map(unit -> record))); + } + + }; + } +} diff --git a/core/src/main/java/moe/nea/pcj/json/JsonLikeError.java b/core/src/main/java/moe/nea/pcj/json/JsonLikeError.java new file mode 100644 index 0000000..609bd84 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/JsonLikeError.java @@ -0,0 +1,4 @@ +package moe.nea.pcj.json; + +public interface JsonLikeError { +} diff --git a/core/src/main/java/moe/nea/pcj/json/JsonLikeOperations.java b/core/src/main/java/moe/nea/pcj/json/JsonLikeOperations.java new file mode 100644 index 0000000..ffefeda --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/JsonLikeOperations.java @@ -0,0 +1,32 @@ +package moe.nea.pcj.json; + +import moe.nea.pcj.Operation; +import moe.nea.pcj.Result; +import moe.nea.pcj.Unit; + +public interface JsonLikeOperations extends Operation { + + Format createNull(Unit value); + + Result getNull(Format element); + + Format createNumeric(Number value); + + Result getNumeric(Format element); + + Format createString(String value); + + Result getString(Format element); + + Format createBoolean(boolean value); + + Result getBoolean(Format format); + + RecordBuilder createObject(); + + Result, ? extends JsonLikeError> getObject(Format format); + + ListBuilder createList(); + + Result, ? extends JsonLikeError> getList(Format format); +} diff --git a/core/src/main/java/moe/nea/pcj/json/ListBuilder.java b/core/src/main/java/moe/nea/pcj/json/ListBuilder.java new file mode 100644 index 0000000..fd2a407 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/ListBuilder.java @@ -0,0 +1,9 @@ +package moe.nea.pcj.json; + +public interface ListBuilder extends ListView { + ElementFormat complete(); + + void add(ElementFormat value); + + void set(int index, ElementFormat value); +} diff --git a/core/src/main/java/moe/nea/pcj/json/ListView.java b/core/src/main/java/moe/nea/pcj/json/ListView.java new file mode 100644 index 0000000..dcc6e37 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/ListView.java @@ -0,0 +1,14 @@ +package moe.nea.pcj.json; + +import java.util.Optional; + +public interface ListView { + int length(); + + default Optional getSafe(int index) { + if (index < 0 || index >= length()) return Optional.empty(); + return Optional.of(getUnsafe(index)); + } + + Format getUnsafe(int index); +} diff --git a/core/src/main/java/moe/nea/pcj/json/MapCodec.java b/core/src/main/java/moe/nea/pcj/json/MapCodec.java new file mode 100644 index 0000000..9f343fd --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/MapCodec.java @@ -0,0 +1,64 @@ +package moe.nea.pcj.json; + +import moe.nea.pcj.Result; + +import java.util.function.Function; + +public interface MapCodec { + Result decode( + RecordView record, + JsonLikeOperations ops); + + Result, JsonLikeError> encode(T value, JsonLikeOperations ops); + + default MapCodec dispatch( + Function keyExtractor, + Function, ? extends JsonLikeError>> codecGenerator + ) { + // TODO: the codecGenerator function is not exactly typesafe. there should be some limit on keyExtractor and codecGenerator working in tandem + return new MapCodec<>() { + @Override + public Result decode(RecordView record, JsonLikeOperations ops) { // TODO: map errors + return MapCodec.this.decode(record, ops) + .flatMap(key -> codecGenerator + .apply(key) + .mapError(DuringKeyExtraction::new) + .flatMap(codec -> codec.decode(record, ops) + .mapError(it -> new InSubType<>(key, it)))); + } + + @Override + public Result, JsonLikeError> encode(O value, JsonLikeOperations ops) { + var key = keyExtractor.apply(value); + return Result., JsonLikeError>cast( + codecGenerator.apply(key) + .mapError(DuringKeyExtraction::new)) + .flatMap(codec -> MapCodec.this + .encode(key, ops) + .flatMap(keyEncoded -> ((MapCodec) codec) + .encode(value, ops) + .mapError(it -> new InSubType<>(key, it)) + .flatMap(keyEncoded::mergeWith))); + } + }; + } + + default JsonCodec codec() { + return new JsonCodec<>() { + @Override + public Result decode(Format format, JsonLikeOperations ops) { + return Result., JsonLikeError>cast(ops.getObject(format)) + .flatMap(record -> MapCodec.this.decode(record, ops)); + } + + @Override + public Result encode(T data, JsonLikeOperations ops) { + return Result.cast(MapCodec.this.encode(data, ops)).map(RecordBuilder::complete); + } + }; + } + + default RecordCodec withGetter(Function getter) { + return new RecordCodec<>(this, getter); + } +} diff --git a/core/src/main/java/moe/nea/pcj/json/MissingKey.java b/core/src/main/java/moe/nea/pcj/json/MissingKey.java new file mode 100644 index 0000000..3dad05c --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/MissingKey.java @@ -0,0 +1,4 @@ +package moe.nea.pcj.json; + +public record MissingKey(String missingKey) implements JsonLikeError { +} diff --git a/core/src/main/java/moe/nea/pcj/json/NamedObject.java b/core/src/main/java/moe/nea/pcj/json/NamedObject.java new file mode 100644 index 0000000..aedc87b --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/NamedObject.java @@ -0,0 +1,4 @@ +package moe.nea.pcj.json; + +public record NamedObject(String name, JsonLikeError error) implements JsonLikeError { +} diff --git a/core/src/main/java/moe/nea/pcj/json/RecordBuilder.java b/core/src/main/java/moe/nea/pcj/json/RecordBuilder.java new file mode 100644 index 0000000..c610f27 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/RecordBuilder.java @@ -0,0 +1,12 @@ +package moe.nea.pcj.json; + +import moe.nea.pcj.Result; +import moe.nea.pcj.Unit; + +public interface RecordBuilder extends RecordView { + Result add(String key, ElementFormat value); + + Result, JsonLikeError> mergeWith(RecordBuilder other); + + ElementFormat complete(); +} diff --git a/core/src/main/java/moe/nea/pcj/json/RecordCodec.java b/core/src/main/java/moe/nea/pcj/json/RecordCodec.java new file mode 100644 index 0000000..fa7aac7 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/RecordCodec.java @@ -0,0 +1,23 @@ +package moe.nea.pcj.json; + +import moe.nea.pcj.Result; + +import java.util.function.Function; + +public record RecordCodec( + MapCodec codec, + Function getter +) { + + Result, JsonLikeError> enc(O data, JsonLikeOperations ops) { + return codec().encode(getter().apply(data), ops); + } + + Result dec(RecordView data, JsonLikeOperations ops) { + return Result.cast(codec().decode(data, ops)); + } + + static Result, JsonLikeError> merge(Result, JsonLikeError> left, Result, JsonLikeError> right) { + return left.flatMap(l -> right.flatMap(l::mergeWith)); + } +} diff --git a/core/src/main/java/moe/nea/pcj/json/RecordJoiners.java b/core/src/main/java/moe/nea/pcj/json/RecordJoiners.java new file mode 100644 index 0000000..57bdd63 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/RecordJoiners.java @@ -0,0 +1,338 @@ +// @generated by genrecord.ts +package moe.nea.pcj.json; + +import moe.nea.pcj.*; +import java.util.stream.*; + +@SuppressWarnings("unused") +public class RecordJoiners { + public static MapCodec join( + RecordCodec arg0, + Tuple.Func1 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple1.collect(new Tuple.Tuple1<>(arg0.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + Tuple.Func2 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple2.collect(new Tuple.Tuple2<>(arg0.dec(format, ops), arg1.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + Tuple.Func3 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple3.collect(new Tuple.Tuple3<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + Tuple.Func4 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple4.collect(new Tuple.Tuple4<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + RecordCodec arg4, + Tuple.Func5 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops), arg4.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple5.collect(new Tuple.Tuple5<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops), arg4.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + RecordCodec arg4, + RecordCodec arg5, + Tuple.Func6 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops), arg4.enc(data, ops), arg5.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple6.collect(new Tuple.Tuple6<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops), arg4.dec(format, ops), arg5.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + RecordCodec arg4, + RecordCodec arg5, + RecordCodec arg6, + Tuple.Func7 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops), arg4.enc(data, ops), arg5.enc(data, ops), arg6.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple7.collect(new Tuple.Tuple7<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops), arg4.dec(format, ops), arg5.dec(format, ops), arg6.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + RecordCodec arg4, + RecordCodec arg5, + RecordCodec arg6, + RecordCodec arg7, + Tuple.Func8 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops), arg4.enc(data, ops), arg5.enc(data, ops), arg6.enc(data, ops), arg7.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple8.collect(new Tuple.Tuple8<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops), arg4.dec(format, ops), arg5.dec(format, ops), arg6.dec(format, ops), arg7.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + RecordCodec arg4, + RecordCodec arg5, + RecordCodec arg6, + RecordCodec arg7, + RecordCodec arg8, + Tuple.Func9 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops), arg4.enc(data, ops), arg5.enc(data, ops), arg6.enc(data, ops), arg7.enc(data, ops), arg8.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple9.collect(new Tuple.Tuple9<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops), arg4.dec(format, ops), arg5.dec(format, ops), arg6.dec(format, ops), arg7.dec(format, ops), arg8.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + RecordCodec arg4, + RecordCodec arg5, + RecordCodec arg6, + RecordCodec arg7, + RecordCodec arg8, + RecordCodec arg9, + Tuple.Func10 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops), arg4.enc(data, ops), arg5.enc(data, ops), arg6.enc(data, ops), arg7.enc(data, ops), arg8.enc(data, ops), arg9.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple10.collect(new Tuple.Tuple10<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops), arg4.dec(format, ops), arg5.dec(format, ops), arg6.dec(format, ops), arg7.dec(format, ops), arg8.dec(format, ops), arg9.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + RecordCodec arg4, + RecordCodec arg5, + RecordCodec arg6, + RecordCodec arg7, + RecordCodec arg8, + RecordCodec arg9, + RecordCodec arg10, + Tuple.Func11 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops), arg4.enc(data, ops), arg5.enc(data, ops), arg6.enc(data, ops), arg7.enc(data, ops), arg8.enc(data, ops), arg9.enc(data, ops), arg10.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple11.collect(new Tuple.Tuple11<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops), arg4.dec(format, ops), arg5.dec(format, ops), arg6.dec(format, ops), arg7.dec(format, ops), arg8.dec(format, ops), arg9.dec(format, ops), arg10.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + RecordCodec arg4, + RecordCodec arg5, + RecordCodec arg6, + RecordCodec arg7, + RecordCodec arg8, + RecordCodec arg9, + RecordCodec arg10, + RecordCodec arg11, + Tuple.Func12 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops), arg4.enc(data, ops), arg5.enc(data, ops), arg6.enc(data, ops), arg7.enc(data, ops), arg8.enc(data, ops), arg9.enc(data, ops), arg10.enc(data, ops), arg11.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple12.collect(new Tuple.Tuple12<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops), arg4.dec(format, ops), arg5.dec(format, ops), arg6.dec(format, ops), arg7.dec(format, ops), arg8.dec(format, ops), arg9.dec(format, ops), arg10.dec(format, ops), arg11.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + RecordCodec arg4, + RecordCodec arg5, + RecordCodec arg6, + RecordCodec arg7, + RecordCodec arg8, + RecordCodec arg9, + RecordCodec arg10, + RecordCodec arg11, + RecordCodec arg12, + Tuple.Func13 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops), arg4.enc(data, ops), arg5.enc(data, ops), arg6.enc(data, ops), arg7.enc(data, ops), arg8.enc(data, ops), arg9.enc(data, ops), arg10.enc(data, ops), arg11.enc(data, ops), arg12.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple13.collect(new Tuple.Tuple13<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops), arg4.dec(format, ops), arg5.dec(format, ops), arg6.dec(format, ops), arg7.dec(format, ops), arg8.dec(format, ops), arg9.dec(format, ops), arg10.dec(format, ops), arg11.dec(format, ops), arg12.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } + public static MapCodec join( + RecordCodec arg0, + RecordCodec arg1, + RecordCodec arg2, + RecordCodec arg3, + RecordCodec arg4, + RecordCodec arg5, + RecordCodec arg6, + RecordCodec arg7, + RecordCodec arg8, + RecordCodec arg9, + RecordCodec arg10, + RecordCodec arg11, + RecordCodec arg12, + RecordCodec arg13, + Tuple.Func14 joiner + ) { + return new MapCodec<>() { + @Override + public Result, JsonLikeError> encode(O data, JsonLikeOperations ops) { + return Stream.of(arg0.enc(data, ops), arg1.enc(data, ops), arg2.enc(data, ops), arg3.enc(data, ops), arg4.enc(data, ops), arg5.enc(data, ops), arg6.enc(data, ops), arg7.enc(data, ops), arg8.enc(data, ops), arg9.enc(data, ops), arg10.enc(data, ops), arg11.enc(data, ops), arg12.enc(data, ops), arg13.enc(data, ops)) + .reduce(Result.ok(ops.createObject()), RecordCodec::merge); + } + @Override + public Result decode(RecordView format, JsonLikeOperations ops) { + return Tuple.Tuple14.collect(new Tuple.Tuple14<>(arg0.dec(format, ops), arg1.dec(format, ops), arg2.dec(format, ops), arg3.dec(format, ops), arg4.dec(format, ops), arg5.dec(format, ops), arg6.dec(format, ops), arg7.dec(format, ops), arg8.dec(format, ops), arg9.dec(format, ops), arg10.dec(format, ops), arg11.dec(format, ops), arg12.dec(format, ops), arg13.dec(format, ops))) + .map(it -> it.applyTo(joiner)); + } + }; + } +} diff --git a/core/src/main/java/moe/nea/pcj/json/RecordView.java b/core/src/main/java/moe/nea/pcj/json/RecordView.java new file mode 100644 index 0000000..968a936 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/RecordView.java @@ -0,0 +1,10 @@ +package moe.nea.pcj.json; + +import java.util.Collection; +import java.util.Optional; + +public interface RecordView { + Collection getKeys(); + + Optional get(String key); +} diff --git a/core/src/main/java/moe/nea/pcj/json/UnexpectedJsonElement.java b/core/src/main/java/moe/nea/pcj/json/UnexpectedJsonElement.java new file mode 100644 index 0000000..7bee7c1 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/UnexpectedJsonElement.java @@ -0,0 +1,7 @@ +package moe.nea.pcj.json; + +public record UnexpectedJsonElement( + String expectedType, + Object actualJsonObject +) implements JsonLikeError { +} diff --git a/core/src/main/java/moe/nea/pcj/json/UnknownSubtype.java b/core/src/main/java/moe/nea/pcj/json/UnknownSubtype.java new file mode 100644 index 0000000..942a7dc --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/UnknownSubtype.java @@ -0,0 +1,10 @@ +package moe.nea.pcj.json; + +import java.util.Set; + +public record UnknownSubtype(T actual, Set expectedTypes) implements JsonLikeError { + @SafeVarargs + public UnknownSubtype(T actual, T... expected) { + this(actual, Set.of(expected)); + } +} diff --git a/core/src/main/java/moe/nea/pcj/json/package-info.java b/core/src/main/java/moe/nea/pcj/json/package-info.java new file mode 100644 index 0000000..a5aace0 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/json/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package moe.nea.pcj.json; + +import org.jspecify.annotations.NullMarked; \ No newline at end of file diff --git a/core/src/main/java/moe/nea/pcj/package-info.java b/core/src/main/java/moe/nea/pcj/package-info.java new file mode 100644 index 0000000..8adfc56 --- /dev/null +++ b/core/src/main/java/moe/nea/pcj/package-info.java @@ -0,0 +1,4 @@ +@NullMarked +package moe.nea.pcj; + +import org.jspecify.annotations.NullMarked; \ No newline at end of file -- cgit