├── .gitignore ├── How to release.md ├── Ideas.md ├── LICENSE ├── README.md ├── docs └── src │ ├── Anatomy of class.monopic │ └── Contravariance.monopic ├── json ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── nl │ │ └── wernerdegroot │ │ └── applicatives │ │ └── json │ │ ├── Errors.java │ │ ├── Failure.java │ │ ├── Json.java │ │ ├── JsonBigDecimalFormat.java │ │ ├── JsonBigIntegerFormat.java │ │ ├── JsonDoubleFormat.java │ │ ├── JsonFormat.java │ │ ├── JsonFormats.java │ │ ├── JsonIntFormat.java │ │ ├── JsonListReader.java │ │ ├── JsonListWriter.java │ │ ├── JsonLongFormat.java │ │ ├── JsonObjectFormat.java │ │ ├── JsonObjectReader.java │ │ ├── JsonObjectWriter.java │ │ ├── JsonOptionalReader.java │ │ ├── JsonOptionalWriter.java │ │ ├── JsonReader.java │ │ ├── JsonReaders.java │ │ ├── JsonStringFormat.java │ │ ├── JsonWriter.java │ │ ├── JsonWriters.java │ │ ├── Key.java │ │ ├── ReadResult.java │ │ ├── Validation.java │ │ ├── ValidationContext.java │ │ └── Verification.java │ └── test │ └── java │ └── nl │ └── wernerdegroot │ └── applicatives │ └── json │ ├── EnergyType.java │ ├── JsonObjectFormatTest.java │ ├── JsonObjectReaderTest.java │ ├── JsonObjectWriterTest.java │ ├── Move.java │ ├── PokemonCard.java │ └── TypeHierarchiesTest.java ├── pom.xml ├── prelude ├── pom.xml └── src │ ├── main │ └── java │ │ └── nl │ │ └── wernerdegroot │ │ └── applicatives │ │ └── prelude │ │ ├── CartesianCollectable.java │ │ ├── CartesianIterable.java │ │ ├── Collectors.java │ │ ├── Comparators.java │ │ ├── CompletableFutures.java │ │ ├── Functions.java │ │ ├── Lists.java │ │ ├── Maps.java │ │ ├── MergeMap.java │ │ ├── Optionals.java │ │ ├── Sets.java │ │ ├── UnaryOperators.java │ │ ├── ZipList.java │ │ └── ZipLists.java │ └── test │ └── java │ └── nl │ └── wernerdegroot │ └── applicatives │ └── prelude │ ├── CartesianCollectableTest.java │ ├── CartesianIterableTest.java │ ├── CollectorsTest.java │ ├── CompletableFuturesTest.java │ ├── EnergyType.java │ ├── FunctionsReturningString.java │ ├── FunctionsTest.java │ ├── ListsTest.java │ ├── MapsTest.java │ ├── Move.java │ ├── OptionalsTest.java │ ├── Person.java │ ├── PokemonCard.java │ ├── UnaryOperatorsTest.java │ ├── ZipListTest.java │ └── ZipListsTest.java ├── processor ├── pom.xml └── src │ ├── main │ └── java │ │ └── nl │ │ └── wernerdegroot │ │ └── applicatives │ │ └── processor │ │ ├── AbstractProcessor.java │ │ ├── BuilderProcessorTemplate.java │ │ ├── Classes.java │ │ ├── ContravariantBuilderProcessor.java │ │ ├── ContravariantMethodProcessor.java │ │ ├── ContravariantProcessorTemplate.java │ │ ├── CovariantBuilderProcessor.java │ │ ├── CovariantMethodProcessor.java │ │ ├── CovariantProcessorTemplate.java │ │ ├── InvariantBuilderProcessor.java │ │ ├── InvariantMethodProcessor.java │ │ ├── InvariantProcessorTemplate.java │ │ ├── MethodProcessorTemplate.java │ │ ├── Options.java │ │ ├── Ordinals.java │ │ ├── ProcessorTemplate.java │ │ ├── conflicts │ │ ├── ConflictFinder.java │ │ └── Conflicts.java │ │ ├── converters │ │ ├── ContainingClassConverter.java │ │ ├── ContainingConverter.java │ │ ├── EnclosedMethodsConverter.java │ │ ├── MethodConverter.java │ │ ├── ModifierConverter.java │ │ ├── TypeConverter.java │ │ └── TypeParameterConverter.java │ │ ├── domain │ │ ├── Accumulator.java │ │ ├── ClassName.java │ │ ├── Finalizer.java │ │ ├── FullyQualifiedName.java │ │ ├── HasReplaceableTypeParameterNames.java │ │ ├── Initializer.java │ │ ├── MayContainReferenceToTypeParameter.java │ │ ├── Method.java │ │ ├── Modifier.java │ │ ├── PackageName.java │ │ ├── Parameter.java │ │ ├── README.md │ │ ├── TypeBuilder.java │ │ ├── TypeParameter.java │ │ ├── TypeParameterName.java │ │ ├── Variance.java │ │ ├── containing │ │ │ ├── Containing.java │ │ │ ├── ContainingClass.java │ │ │ └── ContainingPackage.java │ │ ├── type │ │ │ ├── ArrayType.java │ │ │ ├── ConcreteType.java │ │ │ ├── GenericType.java │ │ │ ├── Type.java │ │ │ └── TypeArgument.java │ │ └── typeconstructor │ │ │ ├── ArrayTypeConstructor.java │ │ │ ├── ConcreteTypeConstructor.java │ │ │ ├── GenericTypeConstructor.java │ │ │ ├── PlaceholderTypeConstructor.java │ │ │ ├── TypeConstructor.java │ │ │ └── TypeConstructorArgument.java │ │ ├── generator │ │ ├── BodyGenerator.java │ │ ├── ClassOrInterfaceGenerator.java │ │ ├── ClassType.java │ │ ├── Constants.java │ │ ├── ContainingClassGenerator.java │ │ ├── ContravariantGenerator.java │ │ ├── CovariantGenerator.java │ │ ├── Generator.java │ │ ├── HasThis.java │ │ ├── InvariantGenerator.java │ │ ├── LambdaGenerator.java │ │ ├── Lines.java │ │ ├── MethodCallGenerator.java │ │ ├── MethodGenerator.java │ │ ├── MethodReferenceGenerator.java │ │ ├── ModifiersGenerator.java │ │ ├── ObjectPathGenerator.java │ │ ├── ObjectPathOrTypeGenerator.java │ │ ├── ParameterGenerator.java │ │ ├── ParametersGenerator.java │ │ ├── TypeArgumentGenerator.java │ │ ├── TypeGenerator.java │ │ ├── TypeParameterGenerator.java │ │ ├── TypeParametersGenerator.java │ │ └── VarianceProcessorTemplate.java │ │ ├── logging │ │ ├── Log.java │ │ ├── LoggingBackend.java │ │ ├── MessengerLoggingBackend.java │ │ └── NoLoggingBackend.java │ │ └── validation │ │ ├── AccumulatorValidator.java │ │ ├── ClassValidator.java │ │ ├── Common.java │ │ ├── ConfigValidator.java │ │ ├── ContravariantParametersAndTypeParametersValidator.java │ │ ├── CovariantParametersAndTypeParametersValidator.java │ │ ├── InitializerOrFinalizerValidator.java │ │ ├── InvariantParametersAndTypeParametersValidator.java │ │ ├── ParametersAndTypeParametersValidator.java │ │ ├── Validated.java │ │ └── Validator.java │ └── test │ ├── java │ └── nl │ │ └── wernerdegroot │ │ └── applicatives │ │ └── processor │ │ ├── ContravariantProcessorTemplateTest.java │ │ ├── CovariantProcessorTemplateTest.java │ │ ├── InvariantProcessorTemplateTest.java │ │ ├── ProcessorTemplateTest.java │ │ ├── Utils.java │ │ ├── VarianceProcessorTemplateTest.java │ │ ├── conflicts │ │ └── ConflictFinderTest.java │ │ ├── converters │ │ ├── ClassConverterTest.java │ │ ├── EnclosedMethodConverterTest.java │ │ ├── MethodConverterTest.java │ │ ├── TestAnnotation.java │ │ ├── TestProcessor.java │ │ └── subjects │ │ │ ├── BunchOfNestedClasses.java │ │ │ ├── ClassWithManyMethods.java │ │ │ ├── ComplexMethod.java │ │ │ └── InterfaceWithManyMethods.java │ │ ├── domain │ │ ├── AccumulatorTest.java │ │ ├── ClassNameTest.java │ │ ├── FinalizerTest.java │ │ ├── FullyQualifiedNameTest.java │ │ ├── InitializerTest.java │ │ ├── MethodTest.java │ │ ├── ModifierTest.java │ │ ├── PackageNameTest.java │ │ ├── ParameterTest.java │ │ ├── TypeParameterNameTest.java │ │ ├── TypeParameterTest.java │ │ ├── containing │ │ │ ├── ContainingClassTest.java │ │ │ ├── ContainingPackageTest.java │ │ │ └── ContainingTest.java │ │ ├── type │ │ │ ├── ArrayTypeTest.java │ │ │ ├── ConcreteTypeTest.java │ │ │ ├── GenericTypeTest.java │ │ │ ├── TypeArgumentTest.java │ │ │ └── TypeTest.java │ │ └── typeconstructor │ │ │ ├── ArrayTypeConstructorTest.java │ │ │ ├── ConcreteTypeConstructorTest.java │ │ │ ├── GenericTypeConstructorTest.java │ │ │ ├── PlaceholderTypeConstructorTest.java │ │ │ ├── TypeConstructorArgumentTest.java │ │ │ └── TypeConstructorTest.java │ │ ├── generator │ │ ├── BodyGeneratorTest.java │ │ ├── ClassOrInterfaceGeneratorTest.java │ │ ├── ContainingClassGeneratorTest.java │ │ ├── LambdaGeneratorTest.java │ │ ├── LinesTest.java │ │ ├── MethodCallGeneratorTest.java │ │ ├── MethodGeneratorTest.java │ │ ├── MethodReferenceGeneratorTest.java │ │ ├── ModifiersGeneratorTest.java │ │ ├── ObjectPathGeneratorTest.java │ │ ├── ObjectPathOrTypeGeneratorTest.java │ │ ├── ParameterGeneratorTest.java │ │ ├── ParametersGeneratorTest.java │ │ ├── TypeArgumentGeneratorTest.java │ │ ├── TypeGeneratorTest.java │ │ ├── TypeParameterGeneratorTest.java │ │ └── TypeParametersGeneratorTest.java │ │ ├── logging │ │ ├── LogTest.java │ │ ├── NoLoggingBackendTest.java │ │ └── StringBuilderLoggingBackend.java │ │ └── validation │ │ ├── AccumulatorValidatorTest.java │ │ ├── ClassValidatorTest.java │ │ ├── ConfigValidatorTest.java │ │ ├── ContravariantParametersAndTypeParametersValidatorTest.java │ │ ├── CovariantParametersAndTypeParametersValidatorTest.java │ │ ├── InitializerOrFinalizerValidatorTest.java │ │ ├── InvariantParametersAndTypeParametersValidatorTest.java │ │ ├── ParameterAndTypeParametersValidatorTest.java │ │ ├── TemplateClassWithMethodsTest.java │ │ ├── ValidatedTest.java │ │ └── ValidatorTest.java │ └── resources │ ├── BinaryOperatorsOverloads.java │ ├── ComparatorsOverloads.java │ ├── CompletableFuturesOverloads.java │ ├── ListsOverloads.java │ ├── MapsOverloads.java │ ├── OptionalsOverloads.java │ ├── ParametersOverloads.java │ ├── PredicatesOverloads.java │ ├── ResultsOverloads.java │ ├── SetsOverloads.java │ └── UnaryOperatorsOverloads.java ├── records ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── nl │ │ └── wernerdegroot │ │ └── applicatives │ │ └── records │ │ ├── Record10.java │ │ ├── Record11.java │ │ ├── Record12.java │ │ ├── Record13.java │ │ ├── Record14.java │ │ ├── Record15.java │ │ ├── Record16.java │ │ ├── Record17.java │ │ ├── Record18.java │ │ ├── Record19.java │ │ ├── Record2.java │ │ ├── Record20.java │ │ ├── Record21.java │ │ ├── Record22.java │ │ ├── Record23.java │ │ ├── Record24.java │ │ ├── Record25.java │ │ ├── Record26.java │ │ ├── Record3.java │ │ ├── Record4.java │ │ ├── Record5.java │ │ ├── Record6.java │ │ ├── Record7.java │ │ ├── Record8.java │ │ ├── Record9.java │ │ └── Records.java │ └── test │ └── java │ └── nl │ └── wernerdegroot │ └── applicatives │ └── records │ └── Record3Test.java ├── runtime ├── pom.xml └── src │ ├── main │ └── java │ │ └── nl │ │ └── wernerdegroot │ │ └── applicatives │ │ └── runtime │ │ ├── Accumulator.java │ │ ├── Applicatives.java │ │ ├── Contravariant.java │ │ ├── Covariant.java │ │ ├── FastTuple.java │ │ ├── Finalizer.java │ │ ├── Function10.java │ │ ├── Function11.java │ │ ├── Function12.java │ │ ├── Function13.java │ │ ├── Function14.java │ │ ├── Function15.java │ │ ├── Function16.java │ │ ├── Function17.java │ │ ├── Function18.java │ │ ├── Function19.java │ │ ├── Function20.java │ │ ├── Function21.java │ │ ├── Function22.java │ │ ├── Function23.java │ │ ├── Function24.java │ │ ├── Function25.java │ │ ├── Function26.java │ │ ├── Function3.java │ │ ├── Function4.java │ │ ├── Function5.java │ │ ├── Function6.java │ │ ├── Function7.java │ │ ├── Function8.java │ │ ├── Function9.java │ │ ├── Initializer.java │ │ ├── Invariant.java │ │ ├── Tuple.java │ │ ├── Tuple10.java │ │ ├── Tuple11.java │ │ ├── Tuple12.java │ │ ├── Tuple13.java │ │ ├── Tuple14.java │ │ ├── Tuple15.java │ │ ├── Tuple16.java │ │ ├── Tuple17.java │ │ ├── Tuple18.java │ │ ├── Tuple19.java │ │ ├── Tuple2.java │ │ ├── Tuple20.java │ │ ├── Tuple21.java │ │ ├── Tuple22.java │ │ ├── Tuple23.java │ │ ├── Tuple24.java │ │ ├── Tuple25.java │ │ ├── Tuple26.java │ │ ├── Tuple3.java │ │ ├── Tuple4.java │ │ ├── Tuple5.java │ │ ├── Tuple6.java │ │ ├── Tuple7.java │ │ ├── Tuple8.java │ │ ├── Tuple9.java │ │ └── decompositions │ │ ├── Decomposable10.java │ │ ├── Decomposable11.java │ │ ├── Decomposable12.java │ │ ├── Decomposable13.java │ │ ├── Decomposable14.java │ │ ├── Decomposable15.java │ │ ├── Decomposable16.java │ │ ├── Decomposable17.java │ │ ├── Decomposable18.java │ │ ├── Decomposable19.java │ │ ├── Decomposable2.java │ │ ├── Decomposable20.java │ │ ├── Decomposable21.java │ │ ├── Decomposable22.java │ │ ├── Decomposable23.java │ │ ├── Decomposable24.java │ │ ├── Decomposable25.java │ │ ├── Decomposable26.java │ │ ├── Decomposable3.java │ │ ├── Decomposable4.java │ │ ├── Decomposable5.java │ │ ├── Decomposable6.java │ │ ├── Decomposable7.java │ │ ├── Decomposable8.java │ │ ├── Decomposable9.java │ │ ├── Decomposition.java │ │ ├── Decomposition10.java │ │ ├── Decomposition11.java │ │ ├── Decomposition12.java │ │ ├── Decomposition13.java │ │ ├── Decomposition14.java │ │ ├── Decomposition15.java │ │ ├── Decomposition16.java │ │ ├── Decomposition17.java │ │ ├── Decomposition18.java │ │ ├── Decomposition19.java │ │ ├── Decomposition2.java │ │ ├── Decomposition20.java │ │ ├── Decomposition21.java │ │ ├── Decomposition22.java │ │ ├── Decomposition23.java │ │ ├── Decomposition24.java │ │ ├── Decomposition25.java │ │ ├── Decomposition26.java │ │ ├── Decomposition3.java │ │ ├── Decomposition4.java │ │ ├── Decomposition5.java │ │ ├── Decomposition6.java │ │ ├── Decomposition7.java │ │ ├── Decomposition8.java │ │ └── Decomposition9.java │ └── test │ └── java │ └── nl │ └── wernerdegroot │ └── applicatives │ └── runtime │ └── FastTupleTest.java └── untitled ├── .idea ├── .gitignore ├── compiler.xml ├── jarRepositories.xml ├── misc.xml └── vcs.xml ├── pom.xml ├── src └── main │ └── java │ └── lambdas │ └── Test.java └── target └── classes └── lambdas ├── CoolThing.class └── Test.class /.gitignore: -------------------------------------------------------------------------------- 1 | # Everything from target folders 2 | /target 3 | /runtime/target 4 | /processor/target 5 | /prelude/target 6 | /json/target 7 | /records/target 8 | 9 | # IntelliJ 10 | /.idea 11 | /records/.idea 12 | *.iml 13 | 14 | # Log file 15 | *.log 16 | 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Werner de Groot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/src/Anatomy of class.monopic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wernerdegroot/applicatives/db183ebdaa059efecf2575f1834320a1dc2b04b9/docs/src/Anatomy of class.monopic -------------------------------------------------------------------------------- /docs/src/Contravariance.monopic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wernerdegroot/applicatives/db183ebdaa059efecf2575f1834320a1dc2b04b9/docs/src/Contravariance.monopic -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/Errors.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | public enum Errors { 4 | UNEXPECTED_NULL("json.parse.error.unexpectedNull"), 5 | NOT_A_NUMBER("json.parse.error.notANumber"), 6 | NOT_A_STRING("json.parse.error.notAString"), 7 | NOT_AN_ARRAY("json.parse.error.notAnArray"), 8 | NOT_AN_OBJECT("json.parse.error.nonAnObject"); 9 | 10 | private final String errorMessageKey; 11 | 12 | Errors(String errorMessageKey) { 13 | this.errorMessageKey = errorMessageKey; 14 | } 15 | 16 | public String getErrorMessageKey() { 17 | return errorMessageKey; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/Failure.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import java.util.Arrays; 4 | import java.util.Objects; 5 | 6 | public class Failure { 7 | private final String path; 8 | private final String errorMessageKey; 9 | private final Object[] arguments; 10 | 11 | public Failure(String path, String errorMessageKey, Object[] arguments) { 12 | this.path = path; 13 | this.errorMessageKey = errorMessageKey; 14 | this.arguments = arguments; 15 | } 16 | 17 | public static Failure of(String path, String errorMessageKey, Object... arguments) { 18 | return new Failure(path, errorMessageKey, arguments); 19 | } 20 | 21 | @Override 22 | public boolean equals(Object o) { 23 | if (this == o) return true; 24 | if (o == null || getClass() != o.getClass()) return false; 25 | Failure failure = (Failure) o; 26 | return Objects.equals(path, failure.path) && Objects.equals(errorMessageKey, failure.errorMessageKey) && Arrays.equals(arguments, failure.arguments); 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | int result = Objects.hash(path, errorMessageKey); 32 | result = 31 * result + Arrays.hashCode(arguments); 33 | return result; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "Failure{" + 39 | "path='" + path + '\'' + 40 | ", errorMessageKey='" + errorMessageKey + '\'' + 41 | ", arguments=" + Arrays.toString(arguments) + 42 | '}'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonBigDecimalFormat.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.Json; 4 | import javax.json.JsonNumber; 5 | import javax.json.JsonValue; 6 | import java.math.BigDecimal; 7 | 8 | import static javax.json.JsonValue.ValueType.NUMBER; 9 | import static nl.wernerdegroot.applicatives.json.Errors.NOT_A_NUMBER; 10 | import static nl.wernerdegroot.applicatives.json.Errors.UNEXPECTED_NULL; 11 | 12 | public class JsonBigDecimalFormat implements JsonFormat { 13 | 14 | @Override 15 | public JsonValue write(BigDecimal toWrite) { 16 | return Json.createValue(toWrite); 17 | } 18 | 19 | @Override 20 | public BigDecimal read(JsonValue toRead, ValidationContext ctx) { 21 | if (toRead == null) { 22 | return ctx.notifyFailure(UNEXPECTED_NULL.getErrorMessageKey()); 23 | } 24 | 25 | if (toRead.getValueType() != NUMBER) { 26 | return ctx.notifyFailure(NOT_A_NUMBER.getErrorMessageKey(), toRead.getValueType()); 27 | } 28 | 29 | JsonNumber jsonNumber = (JsonNumber) toRead; 30 | 31 | return jsonNumber.bigDecimalValue(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonBigIntegerFormat.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.Json; 4 | import javax.json.JsonNumber; 5 | import javax.json.JsonValue; 6 | 7 | import java.math.BigInteger; 8 | 9 | import static javax.json.JsonValue.ValueType.NUMBER; 10 | import static nl.wernerdegroot.applicatives.json.Errors.NOT_A_NUMBER; 11 | import static nl.wernerdegroot.applicatives.json.Errors.UNEXPECTED_NULL; 12 | 13 | public class JsonBigIntegerFormat implements JsonFormat { 14 | 15 | @Override 16 | public JsonValue write(BigInteger toWrite) { 17 | return Json.createValue(toWrite); 18 | } 19 | 20 | @Override 21 | public BigInteger read(JsonValue toRead, ValidationContext ctx) { 22 | if (toRead == null) { 23 | return ctx.notifyFailure(UNEXPECTED_NULL.getErrorMessageKey()); 24 | } 25 | 26 | if (toRead.getValueType() != NUMBER) { 27 | return ctx.notifyFailure(NOT_A_NUMBER.getErrorMessageKey(), toRead.getValueType()); 28 | } 29 | 30 | JsonNumber jsonNumber = (JsonNumber) toRead; 31 | 32 | return jsonNumber.bigIntegerValue(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonDoubleFormat.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.Json; 4 | import javax.json.JsonNumber; 5 | import javax.json.JsonValue; 6 | 7 | import static javax.json.JsonValue.ValueType.NUMBER; 8 | import static nl.wernerdegroot.applicatives.json.Errors.NOT_A_NUMBER; 9 | import static nl.wernerdegroot.applicatives.json.Errors.UNEXPECTED_NULL; 10 | 11 | public class JsonDoubleFormat implements JsonFormat { 12 | 13 | @Override 14 | public JsonValue write(Double toWrite) { 15 | return Json.createValue(toWrite); 16 | } 17 | 18 | @Override 19 | public Double read(JsonValue toRead, ValidationContext ctx) { 20 | if (toRead == null) { 21 | return ctx.notifyFailure(UNEXPECTED_NULL.getErrorMessageKey()); 22 | } 23 | 24 | if (toRead.getValueType() != NUMBER) { 25 | return ctx.notifyFailure(NOT_A_NUMBER.getErrorMessageKey(), toRead.getValueType()); 26 | } 27 | 28 | JsonNumber jsonNumber = (JsonNumber) toRead; 29 | 30 | return jsonNumber.doubleValue(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonFormat.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.JsonValue; 4 | import java.util.List; 5 | import java.util.Optional; 6 | import java.util.function.Function; 7 | 8 | /** 9 | * A combination of a `JsonReader` and a `JsonWriter`, for when you 10 | * want to serialize the same way as you deserialize (which is most 11 | * of the time). 12 | */ 13 | public interface JsonFormat extends JsonReader, JsonWriter { 14 | 15 | static JsonFormat of(JsonReader reader, JsonWriter writer) { 16 | return new JsonFormat() { 17 | @Override 18 | public T read(JsonValue toRead, ValidationContext ctx) { 19 | return reader.read(toRead, ctx); 20 | } 21 | 22 | @Override 23 | public JsonValue write(T toWrite) { 24 | return writer.write(toWrite); 25 | } 26 | }; 27 | } 28 | 29 | @Override 30 | default JsonFormat> list() { 31 | return of(JsonReader.super.list(), JsonWriter.super.list()); 32 | } 33 | 34 | default JsonFormat verify(Verification verification) { 35 | return JsonFormat.of( 36 | JsonReader.super.verify(verification), 37 | this 38 | ); 39 | } 40 | 41 | @Override 42 | default JsonFormat> optional() { 43 | return of(JsonReader.super.optional(), JsonWriter.super.optional()); 44 | } 45 | 46 | default JsonFormat inmap(Function fn, Function gn) { 47 | return of(map(fn), contramap(gn)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonFormats.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Invariant; 4 | 5 | import java.util.function.BiFunction; 6 | import java.util.function.Function; 7 | 8 | public interface JsonFormats extends JsonFormatsOverloads { 9 | 10 | @Override 11 | @Invariant(liftMethodName = "inlift") 12 | default JsonObjectFormat format( 13 | JsonObjectFormat left, 14 | JsonObjectFormat right, 15 | BiFunction combinator, 16 | Function toIntermediate, 17 | Function extractLeft, 18 | Function extractRight) { 19 | 20 | return JsonObjectFormat.of( 21 | Json.instance().reader(left, right, combinator), 22 | Json.instance().writer(left, right, toIntermediate, extractLeft, extractRight) 23 | ); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonIntFormat.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.Json; 4 | import javax.json.JsonNumber; 5 | import javax.json.JsonValue; 6 | 7 | import static javax.json.JsonValue.ValueType.NUMBER; 8 | import static nl.wernerdegroot.applicatives.json.Errors.NOT_A_NUMBER; 9 | import static nl.wernerdegroot.applicatives.json.Errors.UNEXPECTED_NULL; 10 | 11 | public class JsonIntFormat implements JsonFormat { 12 | 13 | @Override 14 | public JsonValue write(Integer toWrite) { 15 | return Json.createValue(toWrite); 16 | } 17 | 18 | @Override 19 | public Integer read(JsonValue toRead, ValidationContext ctx) { 20 | if (toRead == null) { 21 | return ctx.notifyFailure(UNEXPECTED_NULL.getErrorMessageKey()); 22 | } 23 | 24 | if (toRead.getValueType() != NUMBER) { 25 | return ctx.notifyFailure(NOT_A_NUMBER.getErrorMessageKey(), toRead.getValueType()); 26 | } 27 | 28 | JsonNumber jsonNumber = (JsonNumber) toRead; 29 | 30 | return jsonNumber.intValue(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonListReader.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.JsonArray; 4 | import javax.json.JsonValue; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import static javax.json.JsonValue.ValueType.ARRAY; 9 | import static nl.wernerdegroot.applicatives.json.Errors.NOT_AN_ARRAY; 10 | import static nl.wernerdegroot.applicatives.json.Errors.UNEXPECTED_NULL; 11 | import static nl.wernerdegroot.applicatives.json.ReadResult.SUCCESS; 12 | 13 | public class JsonListReader implements JsonReader> { 14 | 15 | private final JsonReader elementReader; 16 | 17 | public JsonListReader(JsonReader elementReader) { 18 | this.elementReader = elementReader; 19 | } 20 | 21 | @Override 22 | public List read(JsonValue toRead, ValidationContext ctx) { 23 | if (toRead == null) { 24 | return ctx.notifyFailure(UNEXPECTED_NULL.getErrorMessageKey()); 25 | } 26 | 27 | if (toRead.getValueType() != ARRAY) { 28 | return ctx.notifyFailure(NOT_AN_ARRAY.getErrorMessageKey(), toRead.getValueType()); 29 | } 30 | 31 | JsonArray jsonArray = (JsonArray) toRead; 32 | 33 | List elements = new ArrayList<>(); 34 | 35 | ctx.startReading(); 36 | 37 | int index = 0; 38 | for (JsonValue element : jsonArray) { 39 | ctx.pushKey(Integer.toString(index)); 40 | elements.add(elementReader.read(element, ctx)); 41 | ctx.popKey(); 42 | index++; 43 | } 44 | 45 | return ctx.finishReading() == SUCCESS ? elements : null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonListWriter.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.Json; 4 | import javax.json.JsonArrayBuilder; 5 | import javax.json.JsonValue; 6 | import java.util.List; 7 | 8 | public class JsonListWriter implements JsonWriter> { 9 | 10 | private final JsonWriter elementWriter; 11 | 12 | public JsonListWriter(JsonWriter elementWriter) { 13 | this.elementWriter = elementWriter; 14 | } 15 | 16 | @Override 17 | public JsonValue write(List toWrite) { 18 | JsonArrayBuilder builder = Json.createArrayBuilder(); 19 | for (T element : toWrite) { 20 | builder.add(elementWriter.write(element)); 21 | } 22 | return builder.build(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonLongFormat.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.Json; 4 | import javax.json.JsonNumber; 5 | import javax.json.JsonValue; 6 | 7 | import static javax.json.JsonValue.ValueType.NUMBER; 8 | import static nl.wernerdegroot.applicatives.json.Errors.NOT_A_NUMBER; 9 | import static nl.wernerdegroot.applicatives.json.Errors.UNEXPECTED_NULL; 10 | 11 | public class JsonLongFormat implements JsonFormat { 12 | 13 | @Override 14 | public JsonValue write(Long toWrite) { 15 | return Json.createValue(toWrite); 16 | } 17 | 18 | @Override 19 | public Long read(JsonValue toRead, ValidationContext ctx) { 20 | if (toRead == null) { 21 | return ctx.notifyFailure(UNEXPECTED_NULL.getErrorMessageKey()); 22 | } 23 | 24 | if (toRead.getValueType() != NUMBER) { 25 | return ctx.notifyFailure(NOT_A_NUMBER.getErrorMessageKey(), toRead.getValueType()); 26 | } 27 | 28 | JsonNumber jsonNumber = (JsonNumber) toRead; 29 | 30 | return jsonNumber.longValue(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonObjectFormat.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.JsonObjectBuilder; 4 | import javax.json.JsonValue; 5 | 6 | /** 7 | * For reading and writing JSON objects (as opposed to other JSON values). 8 | */ 9 | public interface JsonObjectFormat extends JsonReader, JsonObjectWriter, JsonFormat { 10 | 11 | static JsonObjectFormat of(JsonReader reader, JsonObjectWriter writer) { 12 | return new JsonObjectFormat() { 13 | @Override 14 | public T read(JsonValue toRead, ValidationContext ctx) { 15 | return reader.read(toRead, ctx); 16 | } 17 | 18 | @Override 19 | public void write(JsonObjectBuilder builder, T toWrite) { 20 | writer.write(builder, toWrite); 21 | } 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonObjectReader.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.JsonObject; 4 | import javax.json.JsonValue; 5 | 6 | import static javax.json.JsonValue.ValueType.OBJECT; 7 | import static nl.wernerdegroot.applicatives.json.Errors.NOT_AN_OBJECT; 8 | import static nl.wernerdegroot.applicatives.json.Errors.UNEXPECTED_NULL; 9 | 10 | /** 11 | * For reading JSON objects (as opposed to other JSON values). 12 | */ 13 | public interface JsonObjectReader extends JsonReader { 14 | 15 | T read(JsonObject toRead, ValidationContext ctx); 16 | 17 | @Override 18 | default T read(JsonValue toRead, ValidationContext ctx) { 19 | if (toRead == null) { 20 | ctx.notifyFailure(UNEXPECTED_NULL.getErrorMessageKey()); 21 | return null; 22 | } 23 | 24 | if (toRead.getValueType() != OBJECT) { 25 | ctx.notifyFailure(NOT_AN_OBJECT.getErrorMessageKey(), toRead.getValueType()); 26 | return null; 27 | } 28 | 29 | JsonObject jsonObject = (JsonObject) toRead; 30 | 31 | return read(jsonObject, ctx); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonObjectWriter.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.Json; 4 | import javax.json.JsonObjectBuilder; 5 | import javax.json.JsonValue; 6 | 7 | /** 8 | * For writing JSON objects (as opposed to other JSON values). 9 | */ 10 | public interface JsonObjectWriter extends JsonWriter { 11 | 12 | void write(JsonObjectBuilder builder, T toWrite); 13 | 14 | default JsonObjectWriter withValue(T value) { 15 | return (builder, ignored) -> write(builder, value); 16 | } 17 | 18 | default JsonValue write(T toWrite) { 19 | JsonObjectBuilder builder = Json.createObjectBuilder(); 20 | write(builder, toWrite); 21 | return builder.build(); 22 | } 23 | 24 | default JsonObjectWriter combineWith(JsonObjectWriter that) { 25 | return (builder, toWrite) -> { 26 | this.write(builder, toWrite); 27 | that.write(builder, toWrite); 28 | }; 29 | } 30 | } -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonOptionalReader.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.JsonValue; 4 | import java.util.Optional; 5 | 6 | import static javax.json.JsonValue.ValueType.NULL; 7 | import static nl.wernerdegroot.applicatives.json.ReadResult.SUCCESS; 8 | 9 | public class JsonOptionalReader implements JsonReader> { 10 | 11 | private final JsonReader innerReader; 12 | 13 | public JsonOptionalReader(JsonReader innerReader) { 14 | this.innerReader = innerReader; 15 | } 16 | 17 | @Override 18 | public Optional read(JsonValue toRead, ValidationContext ctx) { 19 | if (toRead == null) { 20 | return Optional.empty(); 21 | } 22 | 23 | if (toRead.getValueType() == NULL) { 24 | return Optional.empty(); 25 | } 26 | 27 | ctx.startReading(); 28 | T inner = innerReader.read(toRead, ctx); 29 | return ctx.finishReading() == SUCCESS ? Optional.of(inner) : null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonOptionalWriter.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.JsonValue; 4 | import java.util.Optional; 5 | 6 | import static javax.json.JsonValue.ValueType.NULL; 7 | import static nl.wernerdegroot.applicatives.json.ReadResult.SUCCESS; 8 | 9 | public class JsonOptionalWriter implements JsonWriter> { 10 | 11 | private final JsonWriter innerWriter; 12 | 13 | public JsonOptionalWriter(JsonWriter innerWriter) { 14 | this.innerWriter = innerWriter; 15 | } 16 | 17 | @Override 18 | public JsonValue write(Optional toWrite) { 19 | return toWrite.map(innerWriter::write).orElse(null); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonReaders.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Covariant; 4 | 5 | import java.util.function.BiFunction; 6 | 7 | import static nl.wernerdegroot.applicatives.json.ReadResult.SUCCESS; 8 | 9 | public interface JsonReaders extends JsonReadersOverloads { 10 | 11 | @Override 12 | @Covariant(className = "JsonReadersOverloads") 13 | default JsonReader reader( 14 | JsonReader left, 15 | JsonReader right, 16 | BiFunction combinator) { 17 | 18 | return (toRead, ctx) -> { 19 | ctx.startReading(); 20 | A fromLeft = left.read(toRead, ctx); 21 | B fromRight = right.read(toRead, ctx); 22 | return ctx.finishReading() == SUCCESS ? combinator.apply(fromLeft, fromRight) : null; 23 | }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonStringFormat.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.Json; 4 | import javax.json.JsonString; 5 | import javax.json.JsonValue; 6 | 7 | import static javax.json.JsonValue.ValueType.STRING; 8 | import static nl.wernerdegroot.applicatives.json.Errors.NOT_A_STRING; 9 | import static nl.wernerdegroot.applicatives.json.Errors.UNEXPECTED_NULL; 10 | 11 | public class JsonStringFormat implements JsonFormat { 12 | 13 | @Override 14 | public JsonValue write(String toWrite) { 15 | return Json.createValue(toWrite); 16 | } 17 | 18 | @Override 19 | public String read(JsonValue toRead, ValidationContext ctx) { 20 | if (toRead == null) { 21 | ctx.notifyFailure(UNEXPECTED_NULL.getErrorMessageKey()); 22 | return null; 23 | } 24 | 25 | if (toRead.getValueType() != STRING) { 26 | ctx.notifyFailure(NOT_A_STRING.getErrorMessageKey(), toRead.getValueType()); 27 | return null; 28 | } 29 | 30 | JsonString jsonString = (JsonString) toRead; 31 | 32 | return jsonString.getString(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonWriter.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.JsonValue; 4 | import java.util.List; 5 | import java.util.Optional; 6 | import java.util.function.Function; 7 | 8 | /** 9 | * A `JsonWriter` is a simple class that transforms a `T` into a `JsonValue`. 10 | */ 11 | public interface JsonWriter { 12 | 13 | JsonValue write(T toWrite); 14 | 15 | default JsonWriter> list() { 16 | return new JsonListWriter<>(this); 17 | } 18 | 19 | default JsonWriter contramap(Function fn) { 20 | return toWrite -> write(fn.apply(toWrite)); 21 | } 22 | 23 | default String writeString(T toWrite) { 24 | return write(toWrite).toString(); 25 | } 26 | 27 | default JsonWriter> optional() { 28 | return new JsonOptionalWriter<>(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/JsonWriters.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Contravariant; 4 | 5 | import java.util.function.Function; 6 | 7 | public interface JsonWriters extends JsonWritersOverloads { 8 | 9 | @Override 10 | @Contravariant(liftMethodName = "contralift") 11 | default JsonObjectWriter writer( 12 | JsonObjectWriter left, 13 | JsonObjectWriter right, 14 | Function toIntermediate, 15 | Function extractLeft, 16 | Function extractRight) { 17 | 18 | return (builder, toWrite) -> { 19 | Intermediate intermediate = toIntermediate.apply(toWrite); 20 | left.write(builder, extractLeft.apply(intermediate)); 21 | right.write(builder, extractRight.apply(intermediate)); 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/Key.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | import javax.json.JsonValue; 4 | 5 | public class Key { 6 | 7 | private final String key; 8 | 9 | public Key(String key) { 10 | this.key = key; 11 | } 12 | 13 | public static Key of(String key) { 14 | return new Key(key); 15 | } 16 | 17 | public static Key key(String key) { 18 | return new Key(key); 19 | } 20 | 21 | public JsonObjectReader using(JsonReader reader) { 22 | return readUsing(reader); 23 | } 24 | 25 | public JsonObjectReader readUsing(JsonReader reader) { 26 | return (toRead, ctx) -> { 27 | ctx.pushKey(key); 28 | T result = reader.read(toRead.get(key), ctx); 29 | ctx.popKey(); 30 | return result; 31 | }; 32 | } 33 | 34 | public JsonObjectWriter using(JsonWriter writer) { 35 | return writeUsing(writer); 36 | } 37 | 38 | public JsonObjectWriter writeUsing(JsonWriter writer) { 39 | return (builder, toWrite) -> { 40 | JsonValue written = writer.write(toWrite); 41 | if (written != null) { 42 | builder.add(key, writer.write(toWrite)); 43 | } 44 | }; 45 | } 46 | 47 | public JsonObjectFormat using(JsonFormat format) { 48 | return formatUsing(format); 49 | } 50 | 51 | public JsonObjectFormat formatUsing(JsonFormat format) { 52 | return JsonObjectFormat.of(readUsing(format), writeUsing(format)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/ReadResult.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | public enum ReadResult { 4 | FAILED, 5 | SUCCESS 6 | } 7 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/Validation.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | public interface Validation { 4 | 5 | B validate(A toValidate, ValidationContext ctx); 6 | } 7 | -------------------------------------------------------------------------------- /json/src/main/java/nl/wernerdegroot/applicatives/json/Verification.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | public interface Verification { 4 | 5 | void verify(T toValidate, ValidationContext ctx); 6 | } 7 | -------------------------------------------------------------------------------- /json/src/test/java/nl/wernerdegroot/applicatives/json/EnergyType.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.json; 2 | 3 | public enum EnergyType { 4 | GRASS, 5 | FIRE, 6 | WATER, 7 | LIGHTNING, 8 | PSYCHIC, 9 | FIGHTING, 10 | COLORLESS 11 | } 12 | -------------------------------------------------------------------------------- /prelude/src/main/java/nl/wernerdegroot/applicatives/prelude/Comparators.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Contravariant; 4 | 5 | import java.util.Comparator; 6 | import java.util.function.Function; 7 | 8 | public class Comparators implements ComparatorsOverloads { 9 | 10 | @Override 11 | @Contravariant 12 | public Comparator combine(Comparator left, Comparator right, Function fn, Function extractFirst, Function extractSecond) { 13 | Comparator comp = Comparator.comparing(extractFirst, left).thenComparing(extractSecond, right); 14 | return Comparator.comparing(fn, comp); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /prelude/src/main/java/nl/wernerdegroot/applicatives/prelude/Lists.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Accumulator; 4 | import nl.wernerdegroot.applicatives.runtime.Covariant; 5 | import nl.wernerdegroot.applicatives.runtime.Finalizer; 6 | import nl.wernerdegroot.applicatives.runtime.Initializer; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Iterator; 10 | import java.util.List; 11 | import java.util.function.BiFunction; 12 | import java.util.stream.Collector; 13 | 14 | @Covariant.Builder 15 | public class Lists implements ListsOverloads { 16 | 17 | private static final Lists INSTANCE = new Lists(); 18 | 19 | public static Lists instance() { 20 | return INSTANCE; 21 | } 22 | 23 | @Override 24 | @Initializer 25 | public CartesianIterable initialize(List value) { 26 | return CartesianIterable.of(value); 27 | } 28 | 29 | @Override 30 | @Accumulator 31 | public CartesianIterable combine(CartesianIterable left, List right, BiFunction fn) { 32 | return CartesianIterable.of(left, right, fn); 33 | } 34 | 35 | @Override 36 | @Finalizer 37 | public List finalize(CartesianIterable toFinalize) { 38 | ArrayList finalized = new ArrayList<>(toFinalize.getSize()); 39 | Iterator iterator = toFinalize.iterator(); 40 | while (iterator.hasNext()) { 41 | finalized.add(iterator.next()); 42 | } 43 | return finalized; 44 | } 45 | 46 | public Collector, ?, List> collector(Collector collector) { 47 | return CartesianCollectable.collector(collector); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /prelude/src/main/java/nl/wernerdegroot/applicatives/prelude/Maps.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Accumulator; 4 | import nl.wernerdegroot.applicatives.runtime.Covariant; 5 | import nl.wernerdegroot.applicatives.runtime.Finalizer; 6 | import nl.wernerdegroot.applicatives.runtime.Initializer; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | import java.util.Set; 11 | import java.util.function.BiFunction; 12 | 13 | @Covariant.Builder 14 | public class Maps implements MapsOverloads { 15 | 16 | private static final Maps INSTANCE = new Maps<>(); 17 | 18 | @SuppressWarnings("unchecked") 19 | public static Maps instance() { 20 | return (Maps) INSTANCE; 21 | } 22 | 23 | @Override 24 | @Initializer 25 | public MergeMap initialize(Map value) { 26 | return MergeMap.of(value); 27 | } 28 | 29 | @Override 30 | @Accumulator 31 | public MergeMap compose(MergeMap left, Map right, BiFunction fn) { 32 | return MergeMap.of(left, right, fn); 33 | } 34 | 35 | @Override 36 | @Finalizer 37 | public Map finalize(MergeMap value) { 38 | Set keys = value.getKeys(); 39 | Map result = new HashMap<>(keys.size()); 40 | keys.forEach(key -> result.put(key, value.getValue(key))); 41 | return result; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /prelude/src/main/java/nl/wernerdegroot/applicatives/prelude/Sets.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Accumulator; 4 | import nl.wernerdegroot.applicatives.runtime.Covariant; 5 | import nl.wernerdegroot.applicatives.runtime.Finalizer; 6 | import nl.wernerdegroot.applicatives.runtime.Initializer; 7 | 8 | import java.util.*; 9 | import java.util.function.BiFunction; 10 | import java.util.stream.Collector; 11 | import java.util.stream.Collectors; 12 | 13 | @Covariant.Builder 14 | public class Sets implements SetsOverloads { 15 | 16 | private static final Sets INSTANCE = new Sets(); 17 | 18 | public static Sets instance() { 19 | return INSTANCE; 20 | } 21 | 22 | @Override 23 | @Initializer 24 | public CartesianIterable initialize(Set value) { 25 | return CartesianIterable.of(value); 26 | } 27 | 28 | @Override 29 | @Accumulator 30 | public CartesianIterable combine(CartesianIterable left, Set right, BiFunction fn) { 31 | return CartesianIterable.of(left, right, fn); 32 | } 33 | 34 | @Override 35 | @Finalizer 36 | public Set finalize(CartesianIterable toFinalize) { 37 | Set finalized = new HashSet<>(toFinalize.getSize()); 38 | Iterator iterator = toFinalize.iterator(); 39 | while (iterator.hasNext()) { 40 | finalized.add(iterator.next()); 41 | } 42 | return finalized; 43 | } 44 | 45 | public Collector, ?, Set> collector(Collector collector) { 46 | return Collectors.collectingAndThen(CartesianCollectable.collector(collector), HashSet::new); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /prelude/src/main/java/nl/wernerdegroot/applicatives/prelude/UnaryOperators.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Invariant; 4 | 5 | import java.util.function.BiFunction; 6 | import java.util.function.Function; 7 | import java.util.function.UnaryOperator; 8 | 9 | public class UnaryOperators implements UnaryOperatorsOverloads { 10 | 11 | private static final UnaryOperators INSTANCE = new UnaryOperators(); 12 | 13 | public static UnaryOperators instance() { 14 | return INSTANCE; 15 | } 16 | 17 | @Override 18 | @Invariant 19 | public UnaryOperator combine( 20 | UnaryOperator left, 21 | UnaryOperator right, 22 | BiFunction combinator, 23 | Function toIntermediate, 24 | Function extractLeft, 25 | Function extractRight) { 26 | 27 | return parameter -> { 28 | Intermediate intermediate = toIntermediate.apply(parameter); 29 | A fromLeft = left.apply(extractLeft.apply(intermediate)); 30 | B fromRight = right.apply(extractRight.apply(intermediate)); 31 | return combinator.apply(fromLeft, fromRight); 32 | }; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /prelude/src/main/java/nl/wernerdegroot/applicatives/prelude/ZipLists.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Accumulator; 4 | import nl.wernerdegroot.applicatives.runtime.Covariant; 5 | import nl.wernerdegroot.applicatives.runtime.Finalizer; 6 | import nl.wernerdegroot.applicatives.runtime.Initializer; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Iterator; 10 | import java.util.List; 11 | import java.util.function.BiFunction; 12 | 13 | @Covariant.Builder 14 | public class ZipLists implements ZipListsOverloads { 15 | 16 | private static final ZipLists INSTANCE = new ZipLists(); 17 | 18 | public static ZipLists instance() { 19 | return INSTANCE; 20 | } 21 | 22 | @Override 23 | @Initializer 24 | public ZipList initialize(List value) { 25 | return ZipList.of(value); 26 | } 27 | 28 | @Override 29 | @Accumulator 30 | public ZipList combine(ZipList left, List right, BiFunction fn) { 31 | return ZipList.of(left, right, fn); 32 | } 33 | 34 | @Override 35 | @Finalizer 36 | public List finalize(ZipList toFinalize) { 37 | ArrayList finalized = new ArrayList<>(toFinalize.getSize()); 38 | Iterator iterator = toFinalize.iterator(); 39 | while (iterator.hasNext()) { 40 | finalized.add(iterator.next()); 41 | } 42 | return finalized; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /prelude/src/test/java/nl/wernerdegroot/applicatives/prelude/CartesianCollectableTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.List; 6 | import java.util.Set; 7 | import java.util.stream.Stream; 8 | 9 | import static java.util.Arrays.asList; 10 | import static java.util.stream.Collectors.toSet; 11 | import static org.junit.jupiter.api.Assertions.assertEquals; 12 | 13 | public class CartesianCollectableTest { 14 | 15 | @Test 16 | public void test() { 17 | List> toVerify = Stream.of(1, 2, 3) 18 | .map(i -> asList(i, i + 1)) 19 | .collect(CartesianCollectable.collector(toSet())); 20 | 21 | List> expected = asList( 22 | Stream.of(1, 2, 3).collect(toSet()), 23 | Stream.of(1, 2, 4).collect(toSet()), 24 | Stream.of(1, 3).collect(toSet()), 25 | Stream.of(1, 3, 4).collect(toSet()), 26 | Stream.of(2, 3).collect(toSet()), 27 | Stream.of(2, 4).collect(toSet()), 28 | Stream.of(2, 3).collect(toSet()), 29 | Stream.of(2, 3, 4).collect(toSet()) 30 | ); 31 | 32 | assertEquals(expected, toVerify); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /prelude/src/test/java/nl/wernerdegroot/applicatives/prelude/CollectorsTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.stream.Collector; 6 | import java.util.stream.Stream; 7 | 8 | import static java.util.stream.Collectors.summingInt; 9 | import static org.junit.jupiter.api.Assertions.assertTrue; 10 | 11 | public class CollectorsTest { 12 | 13 | @Test 14 | public void combine() { 15 | Collector collectSum = summingInt(this::identity); 16 | Collector collectSumOfSquares = summingInt(this::square); 17 | Collector collectCount = summingInt(this::tally); 18 | Collector collectStandardDeviation = Collectors.instance().combine( 19 | collectSum, 20 | collectSumOfSquares, 21 | collectCount, 22 | (sum, sumOfSquares, count) -> { 23 | double countAsDouble = (double) count; 24 | return Math.sqrt(sumOfSquares / countAsDouble - square(sum / countAsDouble)); 25 | } 26 | ); 27 | 28 | // From https://revisionmaths.com/gcse-maths-revision/statistics-handling-data/standard-deviation 29 | double expected = 3.94; 30 | double toVerify = Stream.of(4, 9, 11, 12, 17, 5, 8, 12, 14).collect(collectStandardDeviation); 31 | assertTrue(Math.abs(expected - toVerify) < 0.005); // Up to rounding error 32 | } 33 | 34 | private int identity(Integer i) { 35 | return i; 36 | } 37 | 38 | private int square(Integer i) { 39 | return i * i; 40 | } 41 | 42 | private double square(Double i) { 43 | return i * i; 44 | } 45 | 46 | private int tally(Integer i) { 47 | return 1; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /prelude/src/test/java/nl/wernerdegroot/applicatives/prelude/EnergyType.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | public enum EnergyType { 4 | GRASS, 5 | FIRE, 6 | WATER, 7 | LIGHTNING, 8 | PSYCHIC, 9 | FIGHTING, 10 | COLORLESS 11 | } 12 | -------------------------------------------------------------------------------- /prelude/src/test/java/nl/wernerdegroot/applicatives/prelude/FunctionsReturningString.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Accumulator; 4 | import nl.wernerdegroot.applicatives.runtime.Contravariant; 5 | import nl.wernerdegroot.applicatives.runtime.Finalizer; 6 | import nl.wernerdegroot.applicatives.runtime.Initializer; 7 | 8 | import java.util.function.Function; 9 | 10 | // Added to the test package to make sure `@Covariant.Builder` compiles neatly. 11 | @Contravariant.Builder(combineMethodName = "combine") 12 | public class FunctionsReturningString implements FunctionsReturningStringOverloads { 13 | 14 | @Initializer 15 | public Function initialize(Function value) { 16 | return parameter -> new StringBuilder(value.apply(parameter)); 17 | } 18 | 19 | @Accumulator 20 | public Function combineImpl(Function left, Function right, Function toIntermediate, Function extractLeft, Function extractRight) { 21 | return parameter -> { 22 | Intermediate intermediate = toIntermediate.apply(parameter); 23 | StringBuilder fromLeft = left.apply(extractLeft.apply(intermediate)); 24 | String fromRight = right.apply(extractRight.apply(intermediate)); 25 | return fromLeft.append(fromRight); 26 | }; 27 | } 28 | 29 | @Finalizer 30 | public Function finalize(Function value) { 31 | return parameter -> value.apply(parameter).toString(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /prelude/src/test/java/nl/wernerdegroot/applicatives/prelude/MapsTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.prelude; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | 11 | public class MapsTest { 12 | 13 | @Test 14 | public void combine() { 15 | Map left = new HashMap<>(); 16 | left.put(1, "One"); 17 | left.put(2, "Two"); 18 | left.put(3, "Three"); 19 | 20 | Map right = new HashMap<>(); 21 | right.put(2, "Twee"); 22 | right.put(3, "Drie"); 23 | right.put(4, "Vier"); 24 | 25 | Map expected = new HashMap<>(); 26 | expected.put(2, "TwoTwee"); 27 | expected.put(3, "ThreeDrie"); 28 | Map toVerify = Maps.instance().compose(left, right, String::concat); 29 | 30 | assertEquals(expected, toVerify); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/Options.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor; 2 | 3 | public class Options { 4 | public static final String VERBOSE_ARGUMENT = "applicatives.verbose"; 5 | } 6 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/Ordinals.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor; 2 | 3 | import java.util.List; 4 | 5 | import static java.util.Arrays.asList; 6 | 7 | public class Ordinals { 8 | 9 | public static final List ORDINALS = asList( 10 | "first", 11 | "second", 12 | "third", 13 | "fourth", 14 | "fifth", 15 | "sixth", 16 | "seventh", 17 | "eighth", 18 | "ninth", 19 | "tenth", 20 | "eleventh", 21 | "twelfth", 22 | "thirteenth", 23 | "fourteenth", 24 | "fifteenth", 25 | "sixteenth", 26 | "seventeenth", 27 | "eighteenth", 28 | "nineteenth", 29 | "twentieth", 30 | "twentyFirst", 31 | "twentySecond", 32 | "twentyThird", 33 | "twentyFourth", 34 | "twentyFifth", 35 | "twentySixth" 36 | ); 37 | 38 | public static String witherForIndex(int index) { 39 | String ordinal = ORDINALS.get(index); 40 | return "with" + ordinal.substring(0, 1).toUpperCase() + ordinal.substring(1); 41 | } 42 | 43 | public static String getterForIndex(int index) { 44 | String ordinal = ORDINALS.get(index); 45 | return "get" + ordinal.substring(0, 1).toUpperCase() + ordinal.substring(1); 46 | } 47 | 48 | public static String withouterForIndex(int index) { 49 | String ordinal = ORDINALS.get(index); 50 | return "without" + ordinal.substring(0, 1).toUpperCase() + ordinal.substring(1); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/converters/ContainingConverter.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.converters; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.PackageName; 4 | import nl.wernerdegroot.applicatives.processor.domain.containing.Containing; 5 | import nl.wernerdegroot.applicatives.processor.domain.containing.ContainingPackage; 6 | 7 | import javax.lang.model.element.Element; 8 | import javax.lang.model.element.PackageElement; 9 | import javax.lang.model.element.TypeElement; 10 | import java.util.Objects; 11 | 12 | public class ContainingConverter { 13 | 14 | /** 15 | * Converts a class from the world of {@link javax.lang.model} to the 16 | * world of {@link nl.wernerdegroot.applicatives.processor.domain}. 17 | * 18 | * @param element A package, class, interface or record 19 | * @return {@link Containing Containing} 20 | */ 21 | public static Containing toDomain(Element element) { 22 | Objects.requireNonNull(element); 23 | 24 | if (element instanceof PackageElement) { 25 | PackageElement packageElement = (PackageElement) element; 26 | PackageName packageName = PackageName.of(packageElement.getQualifiedName().toString()); 27 | return ContainingPackage.of(packageName); 28 | } else if (element instanceof TypeElement) { 29 | return ContainingClassConverter.toDomain(element); 30 | } else { 31 | throw new IllegalArgumentException("Not a package, class, interface or record"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/converters/EnclosedMethodsConverter.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.converters; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.FullyQualifiedName; 4 | import nl.wernerdegroot.applicatives.processor.domain.Method; 5 | 6 | import javax.lang.model.element.TypeElement; 7 | import java.util.List; 8 | 9 | import static java.util.stream.Collectors.toList; 10 | import static javax.lang.model.element.ElementKind.METHOD; 11 | 12 | public class EnclosedMethodsConverter { 13 | 14 | public static List toDomain(TypeElement typeElement, FullyQualifiedName... supportedAnnotations) { 15 | return typeElement 16 | .getEnclosedElements() 17 | .stream() 18 | .filter(enclosedElement -> enclosedElement.getKind() == METHOD) 19 | .map(MethodConverter::toDomain) 20 | .filter(method -> method.hasAnnotationOf(supportedAnnotations)) 21 | .collect(toList()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/converters/ModifierConverter.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.converters; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.Modifier; 4 | 5 | import java.util.Objects; 6 | 7 | public class ModifierConverter { 8 | 9 | /** 10 | * Converts a class from the world of {@link javax.lang.model} to the 11 | * world of {@link nl.wernerdegroot.applicatives.processor.domain}. 12 | * 13 | * @param modifier A modifier 14 | * 15 | * @return {@link Modifier Modifier} 16 | */ 17 | public static Modifier toDomain(javax.lang.model.element.Modifier modifier) { 18 | Objects.requireNonNull(modifier); 19 | 20 | return Modifier.fromString(modifier.toString()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/domain/ClassName.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import java.util.Objects; 4 | 5 | public final class ClassName { 6 | 7 | private final String className; 8 | 9 | public ClassName(String className) { 10 | this.className = className; 11 | } 12 | 13 | public static ClassName of(String className) { 14 | return new ClassName(className); 15 | } 16 | 17 | public String raw() { 18 | return className; 19 | } 20 | 21 | @Override 22 | public boolean equals(Object o) { 23 | if (this == o) return true; 24 | if (o == null || getClass() != o.getClass()) return false; 25 | ClassName className1 = (ClassName) o; 26 | return Objects.equals(className, className1.className); 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | return Objects.hash(className); 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "ClassName{" + 37 | "className='" + className + '\'' + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/domain/HasReplaceableTypeParameterNames.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import java.util.Map; 4 | 5 | public interface HasReplaceableTypeParameterNames { 6 | 7 | T replaceTypeParameterNames(Map replacements); 8 | } 9 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/domain/MayContainReferenceToTypeParameter.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | public interface MayContainReferenceToTypeParameter { 4 | 5 | boolean referencesTypeParameter(TypeParameterName typeParameterName); 6 | } 7 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/domain/Modifier.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import java.util.EnumSet; 4 | import java.util.Objects; 5 | import java.util.Set; 6 | 7 | public enum Modifier { 8 | PUBLIC("public"), 9 | PROTECTED("protected"), 10 | PRIVATE("private"), 11 | ABSTRACT("abstract"), 12 | DEFAULT("default"), 13 | STATIC("static"), 14 | SEALED("sealed"), 15 | NON_SEALED("non-sealed"), 16 | FINAL("final"), 17 | TRANSIENT("transient"), 18 | VOLATILE("volatile"), 19 | SYNCHRONIZED("synchronized"), 20 | NATIVE("native"), 21 | STRICTFP("strictfp"); 22 | 23 | public static final Set ACCESS_MODIFIERS = EnumSet.of(PUBLIC, PRIVATE, PROTECTED); 24 | 25 | private final String stringValue; 26 | 27 | Modifier(String stringValue) { 28 | this.stringValue = stringValue; 29 | } 30 | 31 | public static Modifier fromString(String stringValue) { 32 | for (Modifier modifier : values()) { 33 | if (Objects.equals(modifier.stringValue, stringValue)) { 34 | return modifier; 35 | } 36 | } 37 | throw new IllegalArgumentException(String.format("No modifier found with value \"%s\"", stringValue)); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return stringValue; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/domain/PackageName.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.containing.ContainingPackage; 4 | 5 | import java.util.Objects; 6 | 7 | public final class PackageName { 8 | private final String packageName; 9 | 10 | public PackageName(String packageName) { 11 | this.packageName = packageName; 12 | } 13 | 14 | public static PackageName of(String packageName) { 15 | return new PackageName(packageName); 16 | } 17 | 18 | public FullyQualifiedName withClassName(ClassName className) { 19 | return FullyQualifiedName.of(packageName + "." + className.raw()); 20 | } 21 | 22 | public ContainingPackage asPackage() { 23 | return ContainingPackage.of(this); 24 | } 25 | 26 | public String raw() { 27 | return packageName; 28 | } 29 | 30 | @Override 31 | public boolean equals(Object o) { 32 | if (this == o) return true; 33 | if (o == null || getClass() != o.getClass()) return false; 34 | PackageName that = (PackageName) o; 35 | return Objects.equals(packageName, that.packageName); 36 | } 37 | 38 | @Override 39 | public int hashCode() { 40 | return Objects.hash(raw()); 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "PackageName{" + 46 | "packageName='" + packageName + '\'' + 47 | '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/domain/Parameter.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.type.Type; 4 | 5 | import java.util.Objects; 6 | 7 | public final class Parameter { 8 | 9 | private final Type type; 10 | private final String name; 11 | 12 | public Parameter(Type type, String name) { 13 | this.type = type; 14 | this.name = name; 15 | } 16 | 17 | public static Parameter of(Type type, String name) { 18 | return new Parameter(type, name); 19 | } 20 | 21 | public Type getType() { 22 | return type; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | @Override 30 | public boolean equals(Object o) { 31 | if (this == o) return true; 32 | if (o == null || getClass() != o.getClass()) return false; 33 | Parameter parameter = (Parameter) o; 34 | return Objects.equals(getType(), parameter.getType()) && Objects.equals(getName(), parameter.getName()); 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return Objects.hash(getType(), getName()); 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "Parameter{" + 45 | "type=" + type + 46 | ", name='" + name + '\'' + 47 | '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/domain/Variance.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | public enum Variance { 4 | INVARIANT, 5 | COVARIANT, 6 | CONTRAVARIANT 7 | } 8 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/domain/containing/Containing.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain.containing; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.ClassName; 4 | import nl.wernerdegroot.applicatives.processor.domain.Modifier; 5 | import nl.wernerdegroot.applicatives.processor.domain.PackageName; 6 | import nl.wernerdegroot.applicatives.processor.domain.TypeParameter; 7 | 8 | import java.util.Set; 9 | import java.util.function.Function; 10 | 11 | import static java.util.Arrays.asList; 12 | 13 | public interface Containing { 14 | 15 | R match(Function matchPackage, Function matchClass); 16 | 17 | PackageName getPackageName(); 18 | 19 | boolean isPackage(); 20 | 21 | boolean isClass(); 22 | 23 | boolean isOuterClass(); 24 | 25 | boolean isStaticInnerClass(); 26 | 27 | default ContainingClass containingClass(Set modifiers, ClassName className, TypeParameter... typeParameters) { 28 | return ContainingClass.of(this, modifiers, className, asList(typeParameters)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/domain/typeconstructor/PlaceholderTypeConstructor.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain.typeconstructor; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.TypeParameterName; 4 | import nl.wernerdegroot.applicatives.processor.domain.type.Type; 5 | 6 | import java.util.Map; 7 | 8 | public final class PlaceholderTypeConstructor implements TypeConstructor { 9 | 10 | @Override 11 | public PlaceholderTypeConstructor replaceTypeParameterNames(Map replacement) { 12 | return this; 13 | } 14 | 15 | @Override 16 | public boolean referencesTypeParameter(TypeParameterName typeParameterName) { 17 | return false; 18 | } 19 | 20 | @Override 21 | public boolean canAccept(TypeConstructor that) { 22 | return this.equals(that); 23 | } 24 | 25 | @Override 26 | public Type apply(Type toApplyTo) { 27 | return toApplyTo; 28 | } 29 | 30 | @Override 31 | public boolean equals(Object that) { 32 | return that instanceof PlaceholderTypeConstructor; 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | return 7; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "PlaceholderTypeConstructor{}"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/BodyGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import static java.util.Arrays.asList; 7 | import static java.util.stream.Collectors.toList; 8 | import static nl.wernerdegroot.applicatives.processor.generator.Constants.EMPTY_LINE; 9 | import static nl.wernerdegroot.applicatives.processor.generator.Constants.INDENT; 10 | 11 | public class BodyGenerator { 12 | 13 | private List lines = new ArrayList<>(); 14 | 15 | public BodyGenerator indent() { 16 | lines = lines 17 | .stream() 18 | .map(line -> EMPTY_LINE.equals(line) ? line : INDENT + line) 19 | .collect(toList()); 20 | return this; 21 | } 22 | 23 | public List lines() { 24 | return lines; 25 | } 26 | 27 | public interface HasBodyGenerator extends HasThis { 28 | 29 | BodyGenerator getBodyGenerator(); 30 | 31 | default This withBody(List lines) { 32 | lines.forEach(getBodyGenerator().lines::add); 33 | return getThis(); 34 | } 35 | 36 | default This withBody(String... lines) { 37 | return withBody(asList(lines)); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/ClassType.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | public enum ClassType { 4 | CLASS(Constants.CLASS), 5 | INTERFACE(Constants.INTERFACE); 6 | 7 | private final String stringValue; 8 | 9 | ClassType(String stringValue) { 10 | this.stringValue = stringValue; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return stringValue; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/Constants.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | public class Constants { 4 | public static String PACKAGE = "package"; 5 | public static String SEMICOLON = ";"; 6 | public static String LINE_FEED = System.lineSeparator(); 7 | public static String EMPTY_LINE = ""; 8 | public static String SPACE = " "; 9 | public static String INDENT = " "; 10 | public static String CLASS = "class"; 11 | public static String INTERFACE = "interface"; 12 | public static String OPEN_BRACE = "{"; 13 | public static String CLOSE_BRACE = "}"; 14 | public static String OPEN_PARENTHESIS = "("; 15 | public static String CLOSE_PARENTHESIS = ")"; 16 | public static String OPEN_ANGULAR_BRACKET = "<"; 17 | public static String CLOSE_ANGULAR_BRACKET = ">"; 18 | public static String OPEN_SQUARE_BRACKET = "["; 19 | public static String CLOSE_SQUARE_BRACKET = "]"; 20 | public static String SEPARATOR = ", "; 21 | public static String PERIOD = "."; 22 | public static String THIS = "this"; 23 | public static String ARROW = "->"; 24 | public static String RETURN = "return"; 25 | public static String DOUBLE_COLON = "::"; 26 | public static String EXTENDS = "extends"; 27 | public static String SUPER = "super"; 28 | public static String QUESTION_MARK = "?"; 29 | 30 | public static String VOID = "void"; 31 | } 32 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/ContainingClassGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.containing.Containing; 4 | import nl.wernerdegroot.applicatives.processor.domain.containing.ContainingClass; 5 | 6 | import java.util.Optional; 7 | 8 | public class ContainingClassGenerator { 9 | 10 | private final ContainingClass containingClass; 11 | 12 | public ContainingClassGenerator(ContainingClass containingClass) { 13 | this.containingClass = containingClass; 14 | } 15 | 16 | public static String generateFrom(ContainingClass containingClass) { 17 | return new ContainingClassGenerator(containingClass).generate(); 18 | } 19 | 20 | public String generate() { 21 | return containingToString(containingClass); 22 | } 23 | 24 | private String containingToString(Containing containing) { 25 | return containing.match( 26 | p -> p.getPackageName().raw(), 27 | c -> { 28 | String parentAsString = containingToString(c.getParent()); 29 | String classNameAsString = c.getClassName().raw(); 30 | String typeParametersAsString = Optional.of(c.getTypeParameters()) 31 | .filter(typeParameters -> !typeParameters.isEmpty()) 32 | .map(TypeParametersGenerator::generatoreFrom) 33 | .orElse(""); 34 | return parentAsString + "." + classNameAsString + typeParametersAsString; 35 | } 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/HasThis.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | public interface HasThis { 4 | 5 | This getThis(); 6 | } 7 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/LambdaGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import java.util.List; 4 | 5 | import static java.util.Arrays.asList; 6 | import static java.util.stream.Collectors.joining; 7 | import static nl.wernerdegroot.applicatives.processor.generator.Constants.*; 8 | 9 | public class LambdaGenerator { 10 | 11 | private List parameterNames; 12 | private String expression; 13 | 14 | public static LambdaGenerator lambda() { 15 | return new LambdaGenerator(); 16 | } 17 | 18 | public LambdaGenerator withParameterNames(List parameterNames) { 19 | this.parameterNames = parameterNames; 20 | return this; 21 | } 22 | 23 | public LambdaGenerator withParameterNames(String... parameterNames) { 24 | return withParameterNames(asList(parameterNames)); 25 | } 26 | 27 | public LambdaGenerator withExpression(String expression) { 28 | this.expression = expression; 29 | return this; 30 | } 31 | 32 | public List multiline() { 33 | return asList( 34 | generateParameterList() + SPACE + ARROW, 35 | INDENT + INDENT + expression 36 | ); 37 | } 38 | 39 | public String generate() { 40 | return generateParameterList() + SPACE + ARROW + SPACE + expression; 41 | } 42 | 43 | private String generateParameterList() { 44 | return parameterNames.stream().collect(joining(SEPARATOR, OPEN_PARENTHESIS, CLOSE_PARENTHESIS)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/MethodReferenceGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.generator.ObjectPathOrTypeGenerator.HasObjectPathOrTypeGenerator; 4 | 5 | import static nl.wernerdegroot.applicatives.processor.generator.Constants.DOUBLE_COLON; 6 | 7 | public class MethodReferenceGenerator implements HasObjectPathOrTypeGenerator { 8 | 9 | private ObjectPathOrTypeGenerator objectPathOrTypeGenerator = new ObjectPathOrTypeGenerator(); 10 | private String methodName; 11 | 12 | public static MethodReferenceGenerator methodReference() { 13 | return new MethodReferenceGenerator(); 14 | } 15 | 16 | @Override 17 | public ObjectPathOrTypeGenerator getObjectPathOrTypeGenerator() { 18 | return objectPathOrTypeGenerator; 19 | } 20 | 21 | @Override 22 | public MethodReferenceGenerator getThis() { 23 | return this; 24 | } 25 | 26 | public MethodReferenceGenerator withMethodName(String methodName) { 27 | this.methodName = methodName; 28 | return this; 29 | } 30 | 31 | public String generate() { 32 | return objectPathOrTypeGenerator.generate() + DOUBLE_COLON + methodName; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/ModifiersGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.Modifier; 4 | 5 | import java.util.Collection; 6 | import java.util.HashSet; 7 | import java.util.Set; 8 | 9 | import static java.util.Arrays.asList; 10 | import static java.util.Comparator.comparing; 11 | import static java.util.stream.Collectors.joining; 12 | import static nl.wernerdegroot.applicatives.processor.generator.Constants.SPACE; 13 | 14 | public class ModifiersGenerator { 15 | 16 | private Set modifiers = new HashSet<>(); 17 | 18 | public boolean isEmpty() { 19 | return modifiers.isEmpty(); 20 | } 21 | 22 | public String generate() { 23 | return modifiers 24 | .stream() 25 | .sorted(comparing(Modifier::ordinal)) 26 | .map(Modifier::toString) 27 | .collect(joining(SPACE)); 28 | } 29 | 30 | public interface HasModifiersGenerator extends HasThis { 31 | 32 | ModifiersGenerator getModifiersGenerator(); 33 | 34 | default This withModifiers(Collection modifiers) { 35 | getModifiersGenerator().modifiers.addAll(modifiers); 36 | return getThis(); 37 | } 38 | 39 | default This withModifiers(Modifier... modifiers) { 40 | return this.withModifiers(asList(modifiers)); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/ObjectPathGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.FullyQualifiedName; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.stream.Stream; 8 | 9 | import static java.util.Arrays.asList; 10 | import static java.util.stream.Collectors.toList; 11 | import static nl.wernerdegroot.applicatives.processor.generator.Constants.PERIOD; 12 | 13 | public class ObjectPathGenerator { 14 | 15 | private List components = new ArrayList<>(); 16 | 17 | public String generate() { 18 | return String.join(PERIOD, components); 19 | } 20 | 21 | public interface HasObjectPathGenerator extends HasThis { 22 | 23 | ObjectPathGenerator getObjectPathGenerator(); 24 | 25 | default This withObjectPath(List components) { 26 | getObjectPathGenerator().components.addAll(components); 27 | return getThis(); 28 | } 29 | 30 | default This withObjectPath(String... components) { 31 | return withObjectPath(asList(components)); 32 | } 33 | 34 | default This withObjectPath(FullyQualifiedName... components) { 35 | return withObjectPath(Stream.of(components).map(FullyQualifiedName::raw).collect(toList())); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/ParameterGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.Parameter; 4 | 5 | import static nl.wernerdegroot.applicatives.processor.generator.Constants.SPACE; 6 | 7 | public class ParameterGenerator { 8 | 9 | private final Parameter parameter; 10 | 11 | public ParameterGenerator(Parameter parameter) { 12 | this.parameter = parameter; 13 | } 14 | 15 | public static ParameterGenerator parameter(Parameter parameter) { 16 | return new ParameterGenerator(parameter); 17 | } 18 | 19 | public static String generateFrom(Parameter parameter) { 20 | return parameter(parameter).generate(); 21 | } 22 | 23 | public String generate() { 24 | String type = TypeGenerator.generateFrom(parameter.getType()); 25 | String name = parameter.getName(); 26 | return String.join(SPACE, type, name); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/TypeArgumentGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.type.TypeArgument; 4 | 5 | import static nl.wernerdegroot.applicatives.processor.generator.Constants.*; 6 | 7 | public class TypeArgumentGenerator { 8 | 9 | private final TypeArgument typeArgument; 10 | 11 | public TypeArgumentGenerator(TypeArgument typeArgument) { 12 | this.typeArgument = typeArgument; 13 | } 14 | 15 | public static String generateFrom(TypeArgument typeArgument) { 16 | return new TypeArgumentGenerator(typeArgument).generate(); 17 | } 18 | 19 | public String generate() { 20 | String generatedType = TypeGenerator.generateFrom(typeArgument.getType()); 21 | switch (typeArgument.getVariance()) { 22 | case INVARIANT: 23 | return generatedType; 24 | case COVARIANT: 25 | return String.join(SPACE, QUESTION_MARK, EXTENDS, generatedType); 26 | case CONTRAVARIANT: 27 | return String.join(SPACE, QUESTION_MARK, SUPER, generatedType); 28 | default: 29 | throw new RuntimeException("Not implemented"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/TypeGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.type.Type; 4 | import nl.wernerdegroot.applicatives.processor.domain.type.TypeArgument; 5 | 6 | import java.util.List; 7 | 8 | import static java.util.stream.Collectors.joining; 9 | import static nl.wernerdegroot.applicatives.processor.generator.Constants.*; 10 | 11 | public class TypeGenerator { 12 | 13 | private final Type type; 14 | 15 | public TypeGenerator(Type type) { 16 | this.type = type; 17 | } 18 | 19 | public static TypeGenerator type(Type type) { 20 | return new TypeGenerator(type); 21 | } 22 | 23 | public static String generateFrom(Type type) { 24 | return new TypeGenerator(type).generate(); 25 | } 26 | 27 | public String generate() { 28 | return type.match( 29 | generic -> generic.getName().raw(), 30 | 31 | concrete -> { 32 | List typeArguments = concrete.getTypeArguments(); 33 | if (typeArguments.isEmpty()) { 34 | return concrete.getFullyQualifiedName().raw(); 35 | } else { 36 | return concrete.getFullyQualifiedName().raw() + OPEN_ANGULAR_BRACKET + typeArguments.stream().map(TypeArgumentGenerator::generateFrom).collect(joining(SEPARATOR)) + CLOSE_ANGULAR_BRACKET; 37 | } 38 | }, 39 | 40 | array -> type(array.getType()).generate() + OPEN_SQUARE_BRACKET + CLOSE_SQUARE_BRACKET 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/TypeParameterGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.TypeParameter; 4 | import nl.wernerdegroot.applicatives.processor.domain.type.Type; 5 | 6 | import java.util.List; 7 | 8 | import static java.util.stream.Collectors.joining; 9 | import static nl.wernerdegroot.applicatives.processor.generator.Constants.EXTENDS; 10 | 11 | public class TypeParameterGenerator { 12 | 13 | private final TypeParameter typeParameter; 14 | 15 | public TypeParameterGenerator(TypeParameter typeParameter) { 16 | this.typeParameter = typeParameter; 17 | } 18 | 19 | public static TypeParameterGenerator typeParameter(TypeParameter typeParameter) { 20 | return new TypeParameterGenerator(typeParameter); 21 | } 22 | 23 | public static String generateFrom(TypeParameter typeParameter) { 24 | return typeParameter(typeParameter).generate(); 25 | } 26 | 27 | public String generate() { 28 | List upperBounds = typeParameter.getUpperBounds(); 29 | if (upperBounds.isEmpty()) { 30 | return typeParameter.getName().raw(); 31 | } else { 32 | return String.join(" ", typeParameter.getName().raw(), EXTENDS, upperBounds.stream().map(TypeGenerator::type).map(TypeGenerator::generate).collect(joining(" & "))); 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/generator/VarianceProcessorTemplate.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.containing.ContainingClass; 4 | import nl.wernerdegroot.applicatives.processor.validation.Validator; 5 | 6 | public interface VarianceProcessorTemplate { 7 | 8 | String generate(ContainingClass containingClass, String classNameToGenerate, String combineMethodName, String liftMethodName, int maxArity, Validator.Result conflictFree); 9 | } 10 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/logging/LoggingBackend.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.logging; 2 | 3 | public interface LoggingBackend { 4 | 5 | void log(String message); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/logging/MessengerLoggingBackend.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.logging; 2 | 3 | import javax.annotation.processing.ProcessingEnvironment; 4 | import javax.tools.Diagnostic; 5 | 6 | public class MessengerLoggingBackend implements LoggingBackend { 7 | 8 | private final ProcessingEnvironment processingEnvironment; 9 | private final Diagnostic.Kind diagnosticKind; 10 | 11 | public MessengerLoggingBackend(ProcessingEnvironment processingEnvironment, Diagnostic.Kind diagnosticKind) { 12 | this.processingEnvironment = processingEnvironment; 13 | this.diagnosticKind = diagnosticKind; 14 | } 15 | 16 | public static MessengerLoggingBackend of(ProcessingEnvironment processingEnvironment, Diagnostic.Kind diagnosticKind) { 17 | return new MessengerLoggingBackend(processingEnvironment, diagnosticKind); 18 | } 19 | 20 | @Override 21 | public void log(String message) { 22 | processingEnvironment.getMessager().printMessage(diagnosticKind, message); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /processor/src/main/java/nl/wernerdegroot/applicatives/processor/logging/NoLoggingBackend.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.logging; 2 | 3 | public class NoLoggingBackend implements LoggingBackend { 4 | 5 | public static final NoLoggingBackend INSTANCE = new NoLoggingBackend(); 6 | 7 | @Override 8 | public void log(String message) { 9 | // Do nothing 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/Utils.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.Modifier; 4 | 5 | import java.util.Set; 6 | import java.util.stream.Stream; 7 | 8 | import static java.util.stream.Collectors.toSet; 9 | 10 | public class Utils { 11 | 12 | public static Set modifiers(Modifier... modifiers) { 13 | return Stream.of(modifiers).collect(toSet()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/VarianceProcessorTemplateTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor; 2 | 3 | import com.google.testing.compile.Compilation; 4 | import com.google.testing.compile.Compiler; 5 | import com.google.testing.compile.JavaFileObjects; 6 | 7 | import javax.tools.JavaFileObject; 8 | import java.io.BufferedReader; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.io.InputStreamReader; 12 | 13 | import static java.util.stream.Collectors.joining; 14 | import static org.junit.jupiter.api.Assertions.assertTrue; 15 | 16 | public interface VarianceProcessorTemplateTest { 17 | 18 | default String getResourceFileAsString(String fileName) throws IOException { 19 | try (InputStream is = VarianceProcessorTemplateTest.class.getResourceAsStream(fileName)) { 20 | if (is == null) { 21 | throw new NullPointerException(); 22 | } 23 | 24 | try (InputStreamReader isr = new InputStreamReader(is); BufferedReader reader = new BufferedReader(isr)) { 25 | return reader.lines().collect(joining("\n")); 26 | } 27 | } 28 | } 29 | 30 | default String getResourceClassFileAsString(String className) throws IOException { 31 | String fileName = "/" + className + ".java"; 32 | return getResourceFileAsString(fileName); 33 | } 34 | 35 | default void ensureResourceFileCompiles(String className) throws IOException { 36 | JavaFileObject javaFileObject = JavaFileObjects.forSourceString(className, getResourceClassFileAsString(className)); 37 | Compilation result = Compiler.javac().compile(javaFileObject); 38 | boolean compiles = result.status() == Compilation.Status.SUCCESS; 39 | assertTrue(compiles); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/converters/TestAnnotation.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.converters; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.METHOD, ElementType.TYPE}) 9 | @Retention(RetentionPolicy.SOURCE) 10 | public @interface TestAnnotation { 11 | } 12 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/converters/subjects/BunchOfNestedClasses.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.converters.subjects; 2 | 3 | import nl.wernerdegroot.applicatives.processor.converters.TestAnnotation; 4 | 5 | import java.io.Serializable; 6 | 7 | public class BunchOfNestedClasses { 8 | 9 | private static class StaticInnerClass { 10 | 11 | @TestAnnotation 12 | class InnerClass { 13 | 14 | } 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/converters/subjects/ClassWithManyMethods.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.converters.subjects; 2 | 3 | import nl.wernerdegroot.applicatives.processor.converters.TestAnnotation; 4 | 5 | @TestAnnotation 6 | public class ClassWithManyMethods implements InterfaceWithManyMethods { 7 | 8 | @Deprecated 9 | static void deprecated() { 10 | 11 | } 12 | 13 | @Override 14 | public String override(int multiplier) { 15 | return "Override times " + multiplier + "!"; 16 | } 17 | 18 | public int noAnnotations() { 19 | return 42; 20 | } 21 | 22 | @SuppressWarnings({"some", "warnings"}) 23 | public String[] suppressWarnings(String more) { 24 | return new String[]{more, "warnings"}; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/converters/subjects/ComplexMethod.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.converters.subjects; 2 | 3 | import nl.wernerdegroot.applicatives.processor.converters.TestAnnotation; 4 | import nl.wernerdegroot.applicatives.runtime.Covariant; 5 | 6 | import java.io.Serializable; 7 | import java.util.Collection; 8 | import java.util.List; 9 | import java.util.Set; 10 | 11 | public class ComplexMethod { 12 | 13 | public static class StaticInnerClass { 14 | } 15 | 16 | @TestAnnotation 17 | @Deprecated 18 | @SuppressWarnings("As many as you can!") 19 | public strictfp synchronized > void someMethod( 20 | int primitive, 21 | Boolean object, 22 | char[][] twoDimensionalPrimitiveArray, 23 | List listOfWildcardsWithoutUpperOrLowerBound, 24 | Set setOfWildcardsWithUpperBound, 25 | Collection collectionOfWildcardsWithLowerBound, 26 | StaticInnerClass nestedClasses, 27 | String... varArgs) { 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/converters/subjects/InterfaceWithManyMethods.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.converters.subjects; 2 | 3 | interface InterfaceWithManyMethods { 4 | String override(int multiplier); 5 | } 6 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/AccumulatorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import com.jparams.verifier.tostring.ToStringVerifier; 4 | import nl.jqno.equalsverifier.EqualsVerifier; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class AccumulatorTest { 8 | 9 | @Test 10 | public void equalsHashCodeToString() { 11 | EqualsVerifier.forClass(Accumulator.class).verify(); 12 | ToStringVerifier.forClass(Accumulator.class).verify(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/ClassNameTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import com.jparams.verifier.tostring.ToStringVerifier; 4 | import nl.jqno.equalsverifier.EqualsVerifier; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | public class ClassNameTest { 10 | 11 | @Test 12 | public void of() { 13 | ClassName expected = new ClassName("String"); 14 | ClassName toVerify = ClassName.of("String"); 15 | 16 | assertEquals(expected, toVerify); 17 | } 18 | 19 | @Test 20 | public void raw() { 21 | String expected = "String"; 22 | String toVerify = new ClassName("String").raw(); 23 | 24 | assertEquals(expected, toVerify); 25 | } 26 | 27 | @Test 28 | public void equalsHashCodeToString() { 29 | EqualsVerifier.forClass(ClassName.class).verify(); 30 | ToStringVerifier.forClass(ClassName.class).verify(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/FinalizerTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import com.jparams.verifier.tostring.ToStringVerifier; 4 | import nl.jqno.equalsverifier.EqualsVerifier; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class FinalizerTest { 8 | 9 | @Test 10 | public void equalsHashCodeToString() { 11 | EqualsVerifier.forClass(Finalizer.class).verify(); 12 | ToStringVerifier.forClass(Finalizer.class).verify(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/FullyQualifiedNameTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import nl.jqno.equalsverifier.EqualsVerifier; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class FullyQualifiedNameTest { 7 | 8 | @Test 9 | public void equals() { 10 | EqualsVerifier.forClass(FullyQualifiedName.class).verify(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/InitializerTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import com.jparams.verifier.tostring.ToStringVerifier; 4 | import nl.jqno.equalsverifier.EqualsVerifier; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class InitializerTest { 8 | 9 | @Test 10 | public void equalsHashCodeToString() { 11 | EqualsVerifier.forClass(Initializer.class).verify(); 12 | ToStringVerifier.forClass(Initializer.class).verify(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/MethodTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import com.jparams.verifier.tostring.ToStringVerifier; 4 | import nl.jqno.equalsverifier.EqualsVerifier; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class MethodTest { 8 | @Test 9 | public void equalsHashCodeToString() { 10 | EqualsVerifier.forClass(Method.class).verify(); 11 | ToStringVerifier.forClass(Method.class).verify(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/ModifierTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertThrows; 6 | 7 | public class ModifierTest { 8 | 9 | @Test 10 | public void givenInvalidValue() { 11 | assertThrows(IllegalArgumentException.class, () -> { 12 | Modifier.fromString("sanitized"); 13 | }); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/PackageNameTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import com.jparams.verifier.tostring.ToStringVerifier; 4 | import nl.jqno.equalsverifier.EqualsVerifier; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public final class PackageNameTest { 8 | 9 | @Test 10 | public void equalsHashCodeToString() { 11 | EqualsVerifier.forClass(PackageName.class).verify(); 12 | ToStringVerifier.forClass(PackageName.class).verify(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/ParameterTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import nl.jqno.equalsverifier.EqualsVerifier; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class ParameterTest { 7 | 8 | @Test 9 | public void equals() { 10 | EqualsVerifier.forClass(Parameter.class).verify(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/TypeParameterNameTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import nl.jqno.equalsverifier.EqualsVerifier; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class TypeParameterNameTest { 7 | 8 | @Test 9 | public void equals() { 10 | EqualsVerifier.forClass(TypeParameterName.class).verify(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/TypeParameterTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain; 2 | 3 | import nl.jqno.equalsverifier.EqualsVerifier; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class TypeParameterTest { 7 | 8 | @Test 9 | public void equals() { 10 | EqualsVerifier.forClass(TypeParameter.class).verify(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/containing/ContainingTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain.containing; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.*; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.Set; 7 | import java.util.stream.Stream; 8 | 9 | import static java.util.Arrays.asList; 10 | import static java.util.Collections.emptyList; 11 | import static java.util.stream.Collectors.toSet; 12 | import static nl.wernerdegroot.applicatives.processor.domain.Modifier.ABSTRACT; 13 | import static nl.wernerdegroot.applicatives.processor.domain.Modifier.PUBLIC; 14 | import static org.junit.jupiter.api.Assertions.assertEquals; 15 | 16 | public class ContainingTest { 17 | 18 | @Test 19 | public void containingClass() { 20 | ContainingPackage containingPackage = new ContainingPackage(new PackageName("nl.wernerdegroot.applicatives")); 21 | ClassName className = new ClassName("Erudite"); 22 | TypeParameter T = new TypeParameter(new TypeParameterName("T"), emptyList()); 23 | TypeParameter U = new TypeParameter(new TypeParameterName("U"), emptyList()); 24 | 25 | ContainingClass expected = new ContainingClass( 26 | containingPackage, 27 | modifiers(PUBLIC, ABSTRACT), 28 | className, 29 | asList(T, U) 30 | ); 31 | 32 | ContainingClass toVerify = containingPackage 33 | .containingClass( 34 | modifiers(PUBLIC, ABSTRACT), 35 | className, 36 | T, 37 | U 38 | ); 39 | 40 | assertEquals(expected, toVerify); 41 | } 42 | 43 | private Set modifiers(Modifier... modifiers) { 44 | return Stream.of(modifiers).collect(toSet()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/type/TypeArgumentTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain.type; 2 | 3 | import com.jparams.verifier.tostring.ToStringVerifier; 4 | import nl.jqno.equalsverifier.EqualsVerifier; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class TypeArgumentTest { 8 | 9 | @Test 10 | public void equalsHashCodeToString() { 11 | EqualsVerifier.forClass(TypeArgument.class).verify(); 12 | ToStringVerifier.forClass(TypeArgument.class).verify(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/domain/typeconstructor/TypeConstructorArgumentTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.domain.typeconstructor; 2 | 3 | import com.jparams.verifier.tostring.ToStringVerifier; 4 | import nl.jqno.equalsverifier.EqualsVerifier; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class TypeConstructorArgumentTest { 8 | 9 | @Test 10 | public void equalsHashCodeToString() { 11 | EqualsVerifier.forClass(TypeConstructorArgument.class).verify(); 12 | ToStringVerifier.forClass(TypeConstructorArgument.class).verify(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/generator/LambdaGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.List; 6 | 7 | import static java.util.Arrays.asList; 8 | import static nl.wernerdegroot.applicatives.processor.generator.LambdaGenerator.lambda; 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | 11 | public class LambdaGeneratorTest { 12 | 13 | @Test 14 | public void lambdaWithSingleExpressionAsMultipleLines() { 15 | List toVerify = lambda() 16 | .withParameterNames("capacity", "hasPower") 17 | .withExpression("new Device(capacity, hasPower)") 18 | .multiline(); 19 | 20 | List expected = asList( 21 | "(capacity, hasPower) ->", 22 | " new Device(capacity, hasPower)" 23 | ); 24 | 25 | assertEquals(expected, toVerify); 26 | } 27 | 28 | @Test 29 | public void lambdaWithSingleExpressionAsSingleLine() { 30 | String toVerify = lambda() 31 | .withParameterNames("capacity", "hasPower") 32 | .withExpression("new Device(capacity, hasPower)") 33 | .generate(); 34 | 35 | String expected = "(capacity, hasPower) -> new Device(capacity, hasPower)"; 36 | 37 | assertEquals(expected, toVerify); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/generator/MethodCallGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static nl.wernerdegroot.applicatives.processor.domain.type.Type.BIG_DECIMAL; 6 | import static nl.wernerdegroot.applicatives.processor.domain.type.Type.CHAR_SEQUENCE; 7 | import static nl.wernerdegroot.applicatives.processor.generator.MethodCallGenerator.methodCall; 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | public class MethodCallGeneratorTest { 11 | 12 | @Test 13 | public void givenInstanceMethodAndExplicitTypeArguments() { 14 | String toVerify = methodCall() 15 | .withObjectPath("objects") 16 | .withTypeArguments(CHAR_SEQUENCE) 17 | .withMethodName("map") 18 | .withArguments("java.lang.Object::toString") 19 | .generate(); 20 | 21 | String expected = "objects.map(java.lang.Object::toString)"; 22 | 23 | assertEquals(expected, toVerify); 24 | } 25 | 26 | @Test 27 | public void givenStaticMethodAndNoTypeArguments() { 28 | String toVerify = methodCall() 29 | .withType(BIG_DECIMAL) 30 | .withMethodName("valueOf") 31 | .withArguments("10") 32 | .generate(); 33 | 34 | String expected = "java.math.BigDecimal.valueOf(10)"; 35 | 36 | assertEquals(expected, toVerify); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/generator/MethodReferenceGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static nl.wernerdegroot.applicatives.processor.domain.type.Type.STRING; 6 | import static nl.wernerdegroot.applicatives.processor.generator.MethodReferenceGenerator.methodReference; 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | public class MethodReferenceGeneratorTest { 10 | 11 | @Test 12 | public void givenInstanceMethod() { 13 | String toVerify = methodReference() 14 | .withObjectPath("this") 15 | .withMethodName("toString") 16 | .generate(); 17 | 18 | String expected = "this::toString"; 19 | 20 | assertEquals(expected, toVerify); 21 | } 22 | 23 | @Test 24 | public void givenStaticMethod() { 25 | String toVerify = methodReference() 26 | .withType(STRING) 27 | .withMethodName("toString") 28 | .generate(); 29 | 30 | String expected = "java.lang.String::toString"; 31 | 32 | assertEquals(expected, toVerify); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/generator/ModifiersGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static nl.wernerdegroot.applicatives.processor.domain.Modifier.*; 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | 8 | public class ModifiersGeneratorTest { 9 | 10 | @Test 11 | public void givenManyModifiers() { 12 | String toVerify = toTest() 13 | .withModifiers(PUBLIC, STATIC, ABSTRACT) 14 | .withModifiers(PRIVATE, DEFAULT) 15 | .getModifiersGenerator() 16 | .generate(); 17 | 18 | String expected = "public private abstract default static"; 19 | 20 | assertEquals(expected, toVerify); 21 | } 22 | 23 | private static ToTest toTest() { 24 | return new ToTest(); 25 | } 26 | 27 | private static class ToTest implements ModifiersGenerator.HasModifiersGenerator { 28 | 29 | private ModifiersGenerator modifiersGenerator = new ModifiersGenerator(); 30 | 31 | @Override 32 | public ModifiersGenerator getModifiersGenerator() { 33 | return modifiersGenerator; 34 | } 35 | 36 | @Override 37 | public ToTest getThis() { 38 | return this; 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/generator/ObjectPathGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class ObjectPathGeneratorTest { 8 | 9 | @Test 10 | public void givenObjectPath() { 11 | String toVerify = toTest() 12 | .withObjectPath("this", "value") 13 | .withObjectPath("selection") 14 | .withObjectPath("current") 15 | .getObjectPathGenerator() 16 | .generate(); 17 | 18 | String expected = "this.value.selection.current"; 19 | 20 | assertEquals(expected, toVerify); 21 | } 22 | 23 | private static ToTest toTest() { 24 | return new ToTest(); 25 | } 26 | 27 | private static class ToTest implements ObjectPathGenerator.HasObjectPathGenerator { 28 | 29 | private ObjectPathGenerator objectPathGenerator = new ObjectPathGenerator(); 30 | 31 | @Override 32 | public ObjectPathGenerator getObjectPathGenerator() { 33 | return objectPathGenerator; 34 | } 35 | 36 | @Override 37 | public ToTest getThis() { 38 | return this; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/generator/ParameterGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.Parameter; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static nl.wernerdegroot.applicatives.processor.domain.type.Type.STRING; 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | public class ParameterGeneratorTest { 10 | 11 | @Test 12 | public void givenParameter() { 13 | String expected = "java.lang.String s"; 14 | String toVerify = ParameterGenerator.generateFrom(Parameter.of(STRING, "s")); 15 | 16 | assertEquals(expected, toVerify); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/generator/ParametersGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.Parameter; 4 | import nl.wernerdegroot.applicatives.processor.domain.TypeParameterName; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static nl.wernerdegroot.applicatives.processor.domain.type.Type.*; 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | public class ParametersGeneratorTest { 11 | 12 | private final TypeParameterName T = TypeParameterName.of("T"); 13 | private final TypeParameterName U = TypeParameterName.of("U"); 14 | 15 | @Test 16 | public void givenParameters() { 17 | String toVerify = toTest() 18 | .withParameter(STRING, "s") 19 | .withParameters(Parameter.of(BIG_DECIMAL, "bd"), Parameter.of(INTEGER, "i")) 20 | .withParameterTypes(OPTIONAL.with(T), OPTIONAL.with(U)) 21 | .andParameterNames("t", "u") 22 | .getParametersGenerator() 23 | .generate(); 24 | 25 | String expected = "(java.lang.String s, java.math.BigDecimal bd, java.lang.Integer i, java.util.Optional t, java.util.Optional u)"; 26 | 27 | assertEquals(expected, toVerify); 28 | } 29 | 30 | public static ToTest toTest() { 31 | return new ToTest(); 32 | } 33 | 34 | public static class ToTest implements ParametersGenerator.HasParametersGenerator { 35 | 36 | private ParametersGenerator parametersGenerator = new ParametersGenerator(); 37 | 38 | @Override 39 | public ParametersGenerator getParametersGenerator() { 40 | return parametersGenerator; 41 | } 42 | 43 | @Override 44 | public ToTest getThis() { 45 | return this; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/generator/TypeArgumentGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static nl.wernerdegroot.applicatives.processor.domain.type.Type.*; 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | 8 | public class TypeArgumentGeneratorTest { 9 | 10 | @Test 11 | public void generateGivenInvariant() { 12 | String expected = "java.lang.String"; 13 | String toVerify = new TypeArgumentGenerator(STRING.invariant()).generate(); 14 | 15 | assertEquals(expected, toVerify); 16 | } 17 | 18 | @Test 19 | public void generateGivenCovariant() { 20 | String expected = "? extends java.lang.Integer"; 21 | String toVerify = new TypeArgumentGenerator(INTEGER.covariant()).generate(); 22 | 23 | assertEquals(expected, toVerify); 24 | } 25 | 26 | @Test 27 | public void generateGivenContravariant() { 28 | String expected = "? super java.lang.Boolean"; 29 | String toVerify = new TypeArgumentGenerator(BOOLEAN.contravariant()).generate(); 30 | 31 | assertEquals(expected, toVerify); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/generator/TypeGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.TypeParameterName; 4 | import nl.wernerdegroot.applicatives.processor.domain.type.Type; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static nl.wernerdegroot.applicatives.processor.domain.type.Type.*; 8 | import static nl.wernerdegroot.applicatives.processor.generator.TypeGenerator.type; 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | 11 | public class TypeGeneratorTest { 12 | 13 | private final TypeParameterName T = TypeParameterName.of("T"); 14 | 15 | @Test 16 | public void givenGenericType() { 17 | Type type = T.asType(); 18 | String toVerify = type(type).generate(); 19 | String expected = "T"; 20 | assertEquals(expected, toVerify); 21 | } 22 | 23 | @Test 24 | public void givenConcreteTypeWithoutTypeParameters() { 25 | Type type = STRING; 26 | String toVerify = type(type).generate(); 27 | String expected = "java.lang.String"; 28 | assertEquals(expected, toVerify); 29 | } 30 | 31 | @Test 32 | public void givenConcreteTypeWithTypeParameters() { 33 | Type type = FUNCTION.with( 34 | STRING.contravariant(), 35 | OBJECT.covariant() 36 | ); 37 | String toVerify = type(type).generate(); 38 | String expected = "java.util.function.Function"; 39 | assertEquals(expected, toVerify); 40 | } 41 | 42 | @Test 43 | public void givenArrayType() { 44 | Type type = OBJECT.array(); 45 | String toVerify = type(type).generate(); 46 | String expected = "java.lang.Object[]"; 47 | assertEquals(expected, toVerify); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/generator/TypeParameterGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.generator; 2 | 3 | import nl.wernerdegroot.applicatives.processor.domain.TypeParameter; 4 | import nl.wernerdegroot.applicatives.processor.domain.TypeParameterName; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static nl.wernerdegroot.applicatives.processor.domain.type.Type.COMPARABLE; 8 | import static nl.wernerdegroot.applicatives.processor.domain.type.Type.SERIALIZABLE; 9 | import static nl.wernerdegroot.applicatives.processor.generator.TypeParameterGenerator.generateFrom; 10 | import static nl.wernerdegroot.applicatives.processor.generator.TypeParameterGenerator.typeParameter; 11 | import static org.junit.jupiter.api.Assertions.assertEquals; 12 | 13 | public class TypeParameterGeneratorTest { 14 | 15 | private final TypeParameterName T = TypeParameterName.of("T"); 16 | 17 | @Test 18 | public void withoutUpperBounds() { 19 | TypeParameter typeParameter = T.asTypeParameter(); 20 | String toVerify = generateFrom(typeParameter); 21 | String expected = "T"; 22 | assertEquals(expected, toVerify); 23 | } 24 | 25 | @Test 26 | public void withUpperBound() { 27 | TypeParameter typeParameter = T.extending(COMPARABLE.with(T)); 28 | String toVerify = generateFrom(typeParameter); 29 | String expected = "T extends java.lang.Comparable"; 30 | assertEquals(expected, toVerify); 31 | } 32 | 33 | @Test 34 | public void withMultipleUpperBounds() { 35 | TypeParameter typeParameter = T.extending(COMPARABLE.with(T), SERIALIZABLE); 36 | String toVerify = generateFrom(typeParameter); 37 | String expected = "T extends java.lang.Comparable & java.io.Serializable"; 38 | assertEquals(expected, toVerify); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/logging/NoLoggingBackendTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.logging; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | public class NoLoggingBackendTest { 6 | 7 | @Test 8 | public void doesNothing() { 9 | NoLoggingBackend.INSTANCE.log("Poof!"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/logging/StringBuilderLoggingBackend.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.logging; 2 | 3 | public class StringBuilderLoggingBackend implements LoggingBackend { 4 | 5 | private final StringBuilder builder = new StringBuilder(); 6 | 7 | @Override 8 | public void log(String message) { 9 | builder.append(message).append("\n"); 10 | } 11 | 12 | public String build() { 13 | return builder.toString(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/validation/ParameterAndTypeParametersValidatorTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.validation; 2 | 3 | import com.jparams.verifier.tostring.ToStringVerifier; 4 | import nl.jqno.equalsverifier.EqualsVerifier; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class ParameterAndTypeParametersValidatorTest { 8 | 9 | @Test 10 | public void resultEqualsHashCodeToString() { 11 | EqualsVerifier.forClass(ParametersAndTypeParametersValidator.Result.class).verify(); 12 | ToStringVerifier.forClass(ParametersAndTypeParametersValidator.Result.class).verify(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /processor/src/test/java/nl/wernerdegroot/applicatives/processor/validation/ValidatedTest.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.processor.validation; 2 | 3 | import com.jparams.verifier.tostring.ToStringVerifier; 4 | import nl.jqno.equalsverifier.EqualsVerifier; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.util.NoSuchElementException; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertThrows; 10 | 11 | public class ValidatedTest { 12 | 13 | @Test 14 | public void equalsHashCodeToString() { 15 | EqualsVerifier.forClass(Validated.class).verify(); 16 | ToStringVerifier.forClass(Validated.class).verify(); 17 | } 18 | 19 | @Test 20 | public void getValueGivenInvalid() { 21 | Validated invalid = Validated.invalid("pretty", "bad"); 22 | assertThrows(NoSuchElementException.class, () -> { 23 | invalid.getValue(); 24 | }); 25 | } 26 | 27 | @Test 28 | public void getErrorMessagesGivenValid() { 29 | Validated valid = Validated.valid("OK"); 30 | assertThrows(NoSuchElementException.class, () -> { 31 | valid.getErrorMessages(); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /processor/src/test/resources/CompletableFuturesOverloads.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives; 2 | 3 | public interface CompletableFuturesOverloads { 4 | 5 | java.util.concurrent.CompletableFuture combineImpl(java.util.concurrent.CompletableFuture first, java.util.concurrent.CompletableFuture second, java.util.function.BiFunction fn); 6 | 7 | default java.util.concurrent.CompletableFuture combine(java.util.concurrent.CompletableFuture first, java.util.concurrent.CompletableFuture second, java.util.function.BiFunction fn) { 8 | return this.combineImpl(first, second, fn); 9 | } 10 | 11 | default java.util.function.BiFunction, java.util.concurrent.CompletableFuture, java.util.concurrent.CompletableFuture> lift(java.util.function.BiFunction fn) { 12 | return (first, second) -> 13 | this.combine(first, second, fn); 14 | } 15 | 16 | class Tuples { 17 | 18 | 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /processor/src/test/resources/OptionalsOverloads.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives; 2 | 3 | public interface OptionalsOverloads { 4 | 5 | java.util.Optional combine(java.util.Optional first, java.util.Optional second, java.util.function.BiFunction fn); 6 | 7 | default java.util.function.BiFunction, java.util.Optional, java.util.Optional> lift(java.util.function.BiFunction fn) { 8 | return (first, second) -> 9 | this.combine(first, second, fn); 10 | } 11 | 12 | class Tuples { 13 | 14 | 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /records/src/main/java/nl/wernerdegroot/applicatives/records/Record10.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function10; 4 | import nl.wernerdegroot.applicatives.runtime.decompositions.Decomposable10; 5 | 6 | public interface Record10, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth> extends Decomposable10 { 7 | 8 | @Override 9 | default T decomposeTo(Function10 fn) { 10 | var components = this.getClass().getRecordComponents(); 11 | try { 12 | return fn.apply( 13 | (First) components[0].getAccessor().invoke(this), 14 | (Second) components[1].getAccessor().invoke(this), 15 | (Third) components[2].getAccessor().invoke(this), 16 | (Fourth) components[3].getAccessor().invoke(this), 17 | (Fifth) components[4].getAccessor().invoke(this), 18 | (Sixth) components[5].getAccessor().invoke(this), 19 | (Seventh) components[6].getAccessor().invoke(this), 20 | (Eighth) components[7].getAccessor().invoke(this), 21 | (Ninth) components[8].getAccessor().invoke(this), 22 | (Tenth) components[9].getAccessor().invoke(this) 23 | ); 24 | } catch (ReflectiveOperationException e) { 25 | throw new RuntimeException(e); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /records/src/main/java/nl/wernerdegroot/applicatives/records/Record11.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function11; 4 | import nl.wernerdegroot.applicatives.runtime.decompositions.Decomposable11; 5 | 6 | public interface Record11, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh> extends Decomposable11 { 7 | 8 | @Override 9 | default T decomposeTo(Function11 fn) { 10 | var components = this.getClass().getRecordComponents(); 11 | try { 12 | return fn.apply( 13 | (First) components[0].getAccessor().invoke(this), 14 | (Second) components[1].getAccessor().invoke(this), 15 | (Third) components[2].getAccessor().invoke(this), 16 | (Fourth) components[3].getAccessor().invoke(this), 17 | (Fifth) components[4].getAccessor().invoke(this), 18 | (Sixth) components[5].getAccessor().invoke(this), 19 | (Seventh) components[6].getAccessor().invoke(this), 20 | (Eighth) components[7].getAccessor().invoke(this), 21 | (Ninth) components[8].getAccessor().invoke(this), 22 | (Tenth) components[9].getAccessor().invoke(this), 23 | (Eleventh) components[10].getAccessor().invoke(this) 24 | ); 25 | } catch (ReflectiveOperationException e) { 26 | throw new RuntimeException(e); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /records/src/main/java/nl/wernerdegroot/applicatives/records/Record2.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.decompositions.Decomposable2; 4 | 5 | import java.util.function.BiFunction; 6 | 7 | public interface Record2, First, Second> extends Decomposable2 { 8 | 9 | @Override 10 | default T decomposeTo(BiFunction fn) { 11 | var components = this.getClass().getRecordComponents(); 12 | try { 13 | return fn.apply( 14 | (First) components[0].getAccessor().invoke(this), 15 | (Second) components[1].getAccessor().invoke(this) 16 | ); 17 | } catch (ReflectiveOperationException e) { 18 | throw new RuntimeException(e); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /records/src/main/java/nl/wernerdegroot/applicatives/records/Record3.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function3; 4 | import nl.wernerdegroot.applicatives.runtime.decompositions.Decomposable3; 5 | 6 | import java.util.function.BiFunction; 7 | 8 | public interface Record3, First, Second, Third> extends Decomposable3 { 9 | 10 | @Override 11 | default T decomposeTo(Function3 fn) { 12 | var components = this.getClass().getRecordComponents(); 13 | try { 14 | return fn.apply( 15 | (First) components[0].getAccessor().invoke(this), 16 | (Second) components[1].getAccessor().invoke(this), 17 | (Third) components[2].getAccessor().invoke(this) 18 | ); 19 | } catch (ReflectiveOperationException e) { 20 | throw new RuntimeException(e); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /records/src/main/java/nl/wernerdegroot/applicatives/records/Record4.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function4; 4 | import nl.wernerdegroot.applicatives.runtime.decompositions.Decomposable4; 5 | 6 | public interface Record4, First, Second, Third, Fourth> extends Decomposable4 { 7 | 8 | @Override 9 | default T decomposeTo(Function4 fn) { 10 | var components = this.getClass().getRecordComponents(); 11 | try { 12 | return fn.apply( 13 | (First) components[0].getAccessor().invoke(this), 14 | (Second) components[1].getAccessor().invoke(this), 15 | (Third) components[2].getAccessor().invoke(this), 16 | (Fourth) components[3].getAccessor().invoke(this) 17 | ); 18 | } catch (ReflectiveOperationException e) { 19 | throw new RuntimeException(e); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /records/src/main/java/nl/wernerdegroot/applicatives/records/Record5.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function5; 4 | import nl.wernerdegroot.applicatives.runtime.decompositions.Decomposable5; 5 | 6 | public interface Record5, First, Second, Third, Fourth, Fifth> extends Decomposable5 { 7 | 8 | @Override 9 | default T decomposeTo(Function5 fn) { 10 | var components = this.getClass().getRecordComponents(); 11 | try { 12 | return fn.apply( 13 | (First) components[0].getAccessor().invoke(this), 14 | (Second) components[1].getAccessor().invoke(this), 15 | (Third) components[2].getAccessor().invoke(this), 16 | (Fourth) components[3].getAccessor().invoke(this), 17 | (Fifth) components[4].getAccessor().invoke(this) 18 | ); 19 | } catch (ReflectiveOperationException e) { 20 | throw new RuntimeException(e); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /records/src/main/java/nl/wernerdegroot/applicatives/records/Record6.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function6; 4 | import nl.wernerdegroot.applicatives.runtime.decompositions.Decomposable6; 5 | 6 | public interface Record6, First, Second, Third, Fourth, Fifth, Sixth> extends Decomposable6 { 7 | 8 | @Override 9 | default T decomposeTo(Function6 fn) { 10 | var components = this.getClass().getRecordComponents(); 11 | try { 12 | return fn.apply( 13 | (First) components[0].getAccessor().invoke(this), 14 | (Second) components[1].getAccessor().invoke(this), 15 | (Third) components[2].getAccessor().invoke(this), 16 | (Fourth) components[3].getAccessor().invoke(this), 17 | (Fifth) components[4].getAccessor().invoke(this), 18 | (Sixth) components[5].getAccessor().invoke(this) 19 | ); 20 | } catch (ReflectiveOperationException e) { 21 | throw new RuntimeException(e); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /records/src/main/java/nl/wernerdegroot/applicatives/records/Record7.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function7; 4 | import nl.wernerdegroot.applicatives.runtime.decompositions.Decomposable7; 5 | 6 | public interface Record7, First, Second, Third, Fourth, Fifth, Sixth, Seventh> extends Decomposable7 { 7 | 8 | @Override 9 | default T decomposeTo(Function7 fn) { 10 | var components = this.getClass().getRecordComponents(); 11 | try { 12 | return fn.apply( 13 | (First) components[0].getAccessor().invoke(this), 14 | (Second) components[1].getAccessor().invoke(this), 15 | (Third) components[2].getAccessor().invoke(this), 16 | (Fourth) components[3].getAccessor().invoke(this), 17 | (Fifth) components[4].getAccessor().invoke(this), 18 | (Sixth) components[5].getAccessor().invoke(this), 19 | (Seventh) components[6].getAccessor().invoke(this) 20 | ); 21 | } catch (ReflectiveOperationException e) { 22 | throw new RuntimeException(e); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /records/src/main/java/nl/wernerdegroot/applicatives/records/Record8.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function8; 4 | import nl.wernerdegroot.applicatives.runtime.decompositions.Decomposable8; 5 | 6 | public interface Record8, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth> extends Decomposable8 { 7 | 8 | @Override 9 | default T decomposeTo(Function8 fn) { 10 | var components = this.getClass().getRecordComponents(); 11 | try { 12 | return fn.apply( 13 | (First) components[0].getAccessor().invoke(this), 14 | (Second) components[1].getAccessor().invoke(this), 15 | (Third) components[2].getAccessor().invoke(this), 16 | (Fourth) components[3].getAccessor().invoke(this), 17 | (Fifth) components[4].getAccessor().invoke(this), 18 | (Sixth) components[5].getAccessor().invoke(this), 19 | (Seventh) components[6].getAccessor().invoke(this), 20 | (Eighth) components[7].getAccessor().invoke(this) 21 | ); 22 | } catch (ReflectiveOperationException e) { 23 | throw new RuntimeException(e); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /records/src/main/java/nl/wernerdegroot/applicatives/records/Record9.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function9; 4 | import nl.wernerdegroot.applicatives.runtime.decompositions.Decomposable9; 5 | 6 | public interface Record9, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth> extends Decomposable9 { 7 | 8 | @Override 9 | default T decomposeTo(Function9 fn) { 10 | var components = this.getClass().getRecordComponents(); 11 | try { 12 | return fn.apply( 13 | (First) components[0].getAccessor().invoke(this), 14 | (Second) components[1].getAccessor().invoke(this), 15 | (Third) components[2].getAccessor().invoke(this), 16 | (Fourth) components[3].getAccessor().invoke(this), 17 | (Fifth) components[4].getAccessor().invoke(this), 18 | (Sixth) components[5].getAccessor().invoke(this), 19 | (Seventh) components[6].getAccessor().invoke(this), 20 | (Eighth) components[7].getAccessor().invoke(this), 21 | (Ninth) components[8].getAccessor().invoke(this) 22 | ); 23 | } catch (ReflectiveOperationException e) { 24 | throw new RuntimeException(e); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /records/src/test/java/nl/wernerdegroot/applicatives/records/Record3Test.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.records; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class Record3Test { 8 | 9 | static { 10 | Records.verify(Color::new); 11 | } 12 | 13 | public record Color(int red, int green, int blue) implements Record3 { 14 | } 15 | 16 | public record Town(int population, int altitude, int yearEstablished) { 17 | } 18 | 19 | @Test 20 | public void givenColor() { 21 | // See https://benjiweber.co.uk/blog/2020/09/19/fun-with-java-records/ 22 | Color color = new Color(1, 2, 3); 23 | Town expected = new Town(1, 2, 3); 24 | Town toVerify = color.decomposeTo(Town::new); 25 | assertEquals(expected, toVerify); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /runtime/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | parent 7 | nl.wernerdegroot.applicatives 8 | 1.2.1 9 | 10 | 11 | 4.0.0 12 | 13 | runtime 14 | 15 | Applicatives | runtime 16 | 17 | 18 | 8 19 | 8 20 | 21 | 22 | 23 | 24 | 25 | org.junit 26 | junit-bom 27 | 5.8.1 28 | pom 29 | import 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.junit.jupiter 37 | junit-jupiter 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-surefire-plugin 47 | 2.22.2 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Accumulator.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.SOURCE) 10 | public @interface Accumulator { 11 | } 12 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Applicatives.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public @interface Applicatives { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Contravariant.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.SOURCE) 10 | public @interface Contravariant { 11 | String className() default "*Overloads"; 12 | String combineMethodName() default "*"; 13 | String liftMethodName() default "lift"; 14 | int maxArity() default 26; 15 | 16 | @Target(ElementType.TYPE) 17 | @Retention(RetentionPolicy.SOURCE) 18 | @interface Builder { 19 | String className() default "*Overloads"; 20 | String combineMethodName() default "*"; 21 | String liftMethodName() default "lift"; 22 | int maxArity() default 26; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Covariant.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.SOURCE) 10 | public @interface Covariant { 11 | String className() default "*Overloads"; 12 | String combineMethodName() default "*"; 13 | String liftMethodName() default "lift"; 14 | int maxArity() default 26; 15 | 16 | @Target(ElementType.TYPE) 17 | @Retention(RetentionPolicy.SOURCE) 18 | @interface Builder { 19 | String className() default "*Overloads"; 20 | String combineMethodName() default "*"; 21 | String liftMethodName() default "lift"; 22 | int maxArity() default 26; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Finalizer.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.SOURCE) 10 | public @interface Finalizer { 11 | } 12 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function10.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function10 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function11.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function11 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function12.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function12 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function13.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function13 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function14.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function14 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function15.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function15 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function16.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function16 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function17.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function17 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth, Q seventeenth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function18.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function18 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth, Q seventeenth, R eighteenth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function19.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function19 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth, Q seventeenth, R eighteenth, S nineteenth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function20.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function20 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth, Q seventeenth, R eighteenth, S nineteenth, T twentieth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function21.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function21 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth, Q seventeenth, R eighteenth, S nineteenth, T twentieth, U twentyFirst); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function22.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function22 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth, Q seventeenth, R eighteenth, S nineteenth, T twentieth, U twentyFirst, V twentySecond); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function23.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function23 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth, Q seventeenth, R eighteenth, S nineteenth, T twentieth, U twentyFirst, V twentySecond, W twentyThird); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function24.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function24 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth, Q seventeenth, R eighteenth, S nineteenth, T twentieth, U twentyFirst, V twentySecond, W twentyThird, X twentyFourth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function25.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function25 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth, Q seventeenth, R eighteenth, S nineteenth, T twentieth, U twentyFirst, V twentySecond, W twentyThird, X twentyFourth, Y twentyFifth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function26.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function26 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth, J tenth, K eleventh, L twelfth, M thirteenth, N fourteenth, O fifteenth, P sixteenth, Q seventeenth, R eighteenth, S nineteenth, T twentieth, U twentyFirst, V twentySecond, W twentyThird, X twentyFourth, Y twentyFifth, Z twentySixth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function3.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function3 { 5 | 6 | Result apply(A first, B second, C third); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function4.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function4 { 5 | 6 | Result apply(A first, B second, C third, D fourth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function5.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function5 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function6.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function6 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function7.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function7 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function8.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function8 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Function9.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | @FunctionalInterface 4 | public interface Function9 { 5 | 6 | Result apply(A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eight, I ninth); 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Initializer.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.SOURCE) 10 | public @interface Initializer { 11 | } 12 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Invariant.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.SOURCE) 10 | public @interface Invariant { 11 | String className() default "*Overloads"; 12 | String combineMethodName() default "*"; 13 | String liftMethodName() default "lift"; 14 | int maxArity() default 26; 15 | 16 | @Target(ElementType.TYPE) 17 | @Retention(RetentionPolicy.SOURCE) 18 | @interface Builder { 19 | String className() default "*Overloads"; 20 | String combineMethodName() default "*"; 21 | String liftMethodName() default "lift"; 22 | int maxArity() default 26; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple10.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple10 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Seventh getSeventh(); 18 | 19 | Eighth getEighth(); 20 | 21 | Ninth getNinth(); 22 | 23 | Tenth getTenth(); 24 | 25 | Tuple9 withoutTenth(); 26 | 27 | Tuple11 withEleventh(Eleventh eleventh); 28 | 29 | default R apply(Function10 fn) { 30 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth(), getSeventh(), getEighth(), getNinth(), getTenth()); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple11.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple11 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Seventh getSeventh(); 18 | 19 | Eighth getEighth(); 20 | 21 | Ninth getNinth(); 22 | 23 | Tenth getTenth(); 24 | 25 | Eleventh getEleventh(); 26 | 27 | Tuple10 withoutEleventh(); 28 | 29 | Tuple12 withTwelfth(Twelfth twelfth); 30 | 31 | default R apply(Function11 fn) { 32 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth(), getSeventh(), getEighth(), getNinth(), getTenth(), getEleventh()); 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple12.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple12 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Seventh getSeventh(); 18 | 19 | Eighth getEighth(); 20 | 21 | Ninth getNinth(); 22 | 23 | Tenth getTenth(); 24 | 25 | Eleventh getEleventh(); 26 | 27 | Twelfth getTwelfth(); 28 | 29 | Tuple11 withoutTwelfth(); 30 | 31 | Tuple13 withThirteenth(Thirteenth thirteenth); 32 | 33 | default R apply(Function12 fn) { 34 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth(), getSeventh(), getEighth(), getNinth(), getTenth(), getEleventh(), getTwelfth()); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple13.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple13 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Seventh getSeventh(); 18 | 19 | Eighth getEighth(); 20 | 21 | Ninth getNinth(); 22 | 23 | Tenth getTenth(); 24 | 25 | Eleventh getEleventh(); 26 | 27 | Twelfth getTwelfth(); 28 | 29 | Thirteenth getThirteenth(); 30 | 31 | Tuple12 withoutThirteenth(); 32 | 33 | Tuple14 withFourteenth(Fourteenth fourteenth); 34 | 35 | default R apply(Function13 fn) { 36 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth(), getSeventh(), getEighth(), getNinth(), getTenth(), getEleventh(), getTwelfth(), getThirteenth()); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple14.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple14 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Seventh getSeventh(); 18 | 19 | Eighth getEighth(); 20 | 21 | Ninth getNinth(); 22 | 23 | Tenth getTenth(); 24 | 25 | Eleventh getEleventh(); 26 | 27 | Twelfth getTwelfth(); 28 | 29 | Thirteenth getThirteenth(); 30 | 31 | Fourteenth getFourteenth(); 32 | 33 | Tuple13 withoutFourteenth(); 34 | 35 | Tuple15 withFifteenth(Fifteenth fifteenth); 36 | 37 | default R apply(Function14 fn) { 38 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth(), getSeventh(), getEighth(), getNinth(), getTenth(), getEleventh(), getTwelfth(), getThirteenth(), getFourteenth()); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple15.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple15 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Seventh getSeventh(); 18 | 19 | Eighth getEighth(); 20 | 21 | Ninth getNinth(); 22 | 23 | Tenth getTenth(); 24 | 25 | Eleventh getEleventh(); 26 | 27 | Twelfth getTwelfth(); 28 | 29 | Thirteenth getThirteenth(); 30 | 31 | Fourteenth getFourteenth(); 32 | 33 | Fifteenth getFifteenth(); 34 | 35 | Tuple14 withoutFifteenth(); 36 | 37 | Tuple16 withSixteenth(Sixteenth sixteenth); 38 | 39 | default R apply(Function15 fn) { 40 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth(), getSeventh(), getEighth(), getNinth(), getTenth(), getEleventh(), getTwelfth(), getThirteenth(), getFourteenth(), getFifteenth()); 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple16.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple16 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Seventh getSeventh(); 18 | 19 | Eighth getEighth(); 20 | 21 | Ninth getNinth(); 22 | 23 | Tenth getTenth(); 24 | 25 | Eleventh getEleventh(); 26 | 27 | Twelfth getTwelfth(); 28 | 29 | Thirteenth getThirteenth(); 30 | 31 | Fourteenth getFourteenth(); 32 | 33 | Fifteenth getFifteenth(); 34 | 35 | Sixteenth getSixteenth(); 36 | 37 | Tuple15 withoutSixteenth(); 38 | 39 | Tuple17 withSeventeenth(Seventeenth seventeenth); 40 | 41 | default R apply(Function16 fn) { 42 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth(), getSeventh(), getEighth(), getNinth(), getTenth(), getEleventh(), getTwelfth(), getThirteenth(), getFourteenth(), getFifteenth(), getSixteenth()); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple2.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | import java.util.function.BiFunction; 4 | 5 | public interface Tuple2 { 6 | 7 | First getFirst(); 8 | 9 | Second getSecond(); 10 | 11 | Tuple3 withThird(Third third); 12 | 13 | default R apply(BiFunction fn) { 14 | return fn.apply(getFirst(), getSecond()); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple3.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple3 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Tuple2 withoutThird(); 12 | 13 | Tuple4 withFourth(Fourth fourth); 14 | 15 | default R apply(Function3 fn) { 16 | return fn.apply(getFirst(), getSecond(), getThird()); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple4.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple4 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Tuple3 withoutFourth(); 14 | 15 | Tuple5 withFifth(Fifth fifth); 16 | 17 | default R apply(Function4 fn) { 18 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth()); 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple5.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple5 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Tuple4 withoutFifth(); 16 | 17 | Tuple6 withSixth(Sixth sixth); 18 | 19 | default R apply(Function5 fn) { 20 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth()); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple6.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple6 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Tuple5 withoutSixth(); 18 | 19 | Tuple7 withSeventh(Seventh seventh); 20 | 21 | default R apply(Function6 fn) { 22 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth()); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple7.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple7 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Seventh getSeventh(); 18 | 19 | Tuple6 withoutSeventh(); 20 | 21 | Tuple8 withEighth(Eighth eighth); 22 | 23 | default R apply(Function7 fn) { 24 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth(), getSeventh()); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple8.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple8 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Seventh getSeventh(); 18 | 19 | Eighth getEighth(); 20 | 21 | Tuple7 withoutEighth(); 22 | 23 | Tuple9 withNinth(Ninth ninth); 24 | 25 | default R apply(Function8 fn) { 26 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth(), getSeventh(), getEighth()); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/Tuple9.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime; 2 | 3 | public interface Tuple9 { 4 | 5 | First getFirst(); 6 | 7 | Second getSecond(); 8 | 9 | Third getThird(); 10 | 11 | Fourth getFourth(); 12 | 13 | Fifth getFifth(); 14 | 15 | Sixth getSixth(); 16 | 17 | Seventh getSeventh(); 18 | 19 | Eighth getEighth(); 20 | 21 | Ninth getNinth(); 22 | 23 | Tuple8 withoutNinth(); 24 | 25 | Tuple10 withTenth(Tenth tenth); 26 | 27 | default R apply(Function9 fn) { 28 | return fn.apply(getFirst(), getSecond(), getThird(), getFourth(), getFifth(), getSixth(), getSeventh(), getEighth(), getNinth()); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable10.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function10; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple10; 6 | 7 | public interface Decomposable10 { 8 | T decomposeTo(Function10 fn); 9 | 10 | default Tuple10 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable11.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function11; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple11; 6 | 7 | public interface Decomposable11 { 8 | T decomposeTo(Function11 fn); 9 | 10 | default Tuple11 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable12.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function12; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple12; 6 | 7 | public interface Decomposable12 { 8 | T decomposeTo(Function12 fn); 9 | 10 | default Tuple12 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable13.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function13; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple13; 6 | 7 | public interface Decomposable13 { 8 | T decomposeTo(Function13 fn); 9 | 10 | default Tuple13 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable14.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function14; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple14; 6 | 7 | public interface Decomposable14 { 8 | T decomposeTo(Function14 fn); 9 | 10 | default Tuple14 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable15.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function15; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple15; 6 | 7 | public interface Decomposable15 { 8 | T decomposeTo(Function15 fn); 9 | 10 | default Tuple15 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable16.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function16; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple16; 6 | 7 | public interface Decomposable16 { 8 | T decomposeTo(Function16 fn); 9 | 10 | default Tuple16 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable17.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function17; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple17; 6 | 7 | public interface Decomposable17 { 8 | T decomposeTo(Function17 fn); 9 | 10 | default Tuple17 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable18.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function18; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple18; 6 | 7 | public interface Decomposable18 { 8 | T decomposeTo(Function18 fn); 9 | 10 | default Tuple18 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable19.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function19; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple19; 6 | 7 | public interface Decomposable19 { 8 | T decomposeTo(Function19 fn); 9 | 10 | default Tuple19 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable2.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple2; 5 | 6 | import java.util.function.BiFunction; 7 | 8 | public interface Decomposable2 { 9 | T decomposeTo(BiFunction fn); 10 | 11 | default Tuple2 decompose() { 12 | return decomposeTo(Tuple::of); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable20.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function20; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple20; 6 | 7 | public interface Decomposable20 { 8 | T decomposeTo(Function20 fn); 9 | 10 | default Tuple20 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable21.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function21; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple21; 6 | 7 | public interface Decomposable21 { 8 | T decomposeTo(Function21 fn); 9 | 10 | default Tuple21 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable22.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function22; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple22; 6 | 7 | public interface Decomposable22 { 8 | T decomposeTo(Function22 fn); 9 | 10 | default Tuple22 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable23.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function23; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple23; 6 | 7 | public interface Decomposable23 { 8 | T decomposeTo(Function23 fn); 9 | 10 | default Tuple23 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable24.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function24; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple24; 6 | 7 | public interface Decomposable24 { 8 | T decomposeTo(Function24 fn); 9 | 10 | default Tuple24 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable25.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function25; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple25; 6 | 7 | public interface Decomposable25 { 8 | T decomposeTo(Function25 fn); 9 | 10 | default Tuple25 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable26.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function26; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple26; 6 | 7 | public interface Decomposable26 { 8 | T decomposeTo(Function26 fn); 9 | 10 | default Tuple26 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable3.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function3; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple3; 6 | 7 | public interface Decomposable3 { 8 | T decomposeTo(Function3 fn); 9 | 10 | default Tuple3 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable4.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function4; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple4; 6 | 7 | public interface Decomposable4 { 8 | T decomposeTo(Function4 fn); 9 | 10 | default Tuple4 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable5.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function5; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple5; 6 | 7 | public interface Decomposable5 { 8 | T decomposeTo(Function5 fn); 9 | 10 | default Tuple5 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable6.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function6; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple6; 6 | 7 | public interface Decomposable6 { 8 | T decomposeTo(Function6 fn); 9 | 10 | default Tuple6 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable7.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function7; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple7; 6 | 7 | public interface Decomposable7 { 8 | T decomposeTo(Function7 fn); 9 | 10 | default Tuple7 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable8.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function8; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple8; 6 | 7 | public interface Decomposable8 { 8 | T decomposeTo(Function8 fn); 9 | 10 | default Tuple8 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposable9.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Function9; 4 | import nl.wernerdegroot.applicatives.runtime.Tuple; 5 | import nl.wernerdegroot.applicatives.runtime.Tuple9; 6 | 7 | public interface Decomposable9 { 8 | T decomposeTo(Function9 fn); 9 | 10 | default Tuple9 decompose() { 11 | return decomposeTo(Tuple::of); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition10.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple10; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition10 { 7 | 8 | Tuple10 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition11.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple11; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition11 { 7 | 8 | Tuple11 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition12.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple12; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition12 { 7 | 8 | Tuple12 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition13.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple13; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition13 { 7 | 8 | Tuple13 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition14.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple14; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition14 { 7 | 8 | Tuple14 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition15.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple15; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition15 { 7 | 8 | Tuple15 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition16.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple16; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition16 { 7 | 8 | Tuple16 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition17.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple17; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition17 { 7 | 8 | Tuple17 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition18.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple18; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition18 { 7 | 8 | Tuple18 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition19.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple19; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition19 { 7 | 8 | Tuple19 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition2.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple2; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition2 { 7 | 8 | Tuple2 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition20.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple20; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition20 { 7 | 8 | Tuple20 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition21.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple21; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition21 { 7 | 8 | Tuple21 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition22.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple22; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition22 { 7 | 8 | Tuple22 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition23.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple23; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition23 { 7 | 8 | Tuple23 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition24.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple24; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition24 { 7 | 8 | Tuple24 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition25.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple25; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition25 { 7 | 8 | Tuple25 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition26.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple26; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition26 { 7 | 8 | Tuple26 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition3.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple3; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition3 { 7 | 8 | Tuple3 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition4.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple4; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition4 { 7 | 8 | Tuple4 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition5.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple5; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition5 { 7 | 8 | Tuple5 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition6.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple6; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition6 { 7 | 8 | Tuple6 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition7.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple7; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition7 { 7 | 8 | Tuple7 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition8.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple8; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition8 { 7 | 8 | Tuple8 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /runtime/src/main/java/nl/wernerdegroot/applicatives/runtime/decompositions/Decomposition9.java: -------------------------------------------------------------------------------- 1 | package nl.wernerdegroot.applicatives.runtime.decompositions; 2 | 3 | import nl.wernerdegroot.applicatives.runtime.Tuple9; 4 | 5 | @FunctionalInterface 6 | public interface Decomposition9 { 7 | 8 | Tuple9 decompose(Source source); 9 | } 10 | -------------------------------------------------------------------------------- /untitled/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /untitled/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /untitled/.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /untitled/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /untitled/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /untitled/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | untitled 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 8 13 | 8 14 | 15 | 16 | -------------------------------------------------------------------------------- /untitled/src/main/java/lambdas/Test.java: -------------------------------------------------------------------------------- 1 | package lambdas; 2 | 3 | import java.util.Comparator; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import java.util.function.Consumer; 7 | import java.util.function.Predicate; 8 | import java.util.function.Supplier; 9 | import java.util.stream.Stream; 10 | 11 | import static java.util.Arrays.asList; 12 | 13 | class CoolThing { 14 | public static void doCoolThings() { 15 | System.out.println("Very cool"); 16 | } 17 | } 18 | 19 | public class Test { 20 | 21 | static int i = 0; 22 | 23 | 24 | public static void main(String[] args) { 25 | Integer x = 43; 26 | giveMeBooles(true, true); 27 | } 28 | 29 | public static void giveMeBooles(Boolean... i) { 30 | 31 | } 32 | 33 | public static void giveMeBooles(boolean... i) { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /untitled/target/classes/lambdas/CoolThing.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wernerdegroot/applicatives/db183ebdaa059efecf2575f1834320a1dc2b04b9/untitled/target/classes/lambdas/CoolThing.class -------------------------------------------------------------------------------- /untitled/target/classes/lambdas/Test.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wernerdegroot/applicatives/db183ebdaa059efecf2575f1834320a1dc2b04b9/untitled/target/classes/lambdas/Test.class --------------------------------------------------------------------------------