First upload

This commit is contained in:
Marco Cetica 2024-09-17 10:34:11 +02:00
commit 72e5fc2e03
Signed by: marco
GPG Key ID: 45060A949E90D0FD
5 changed files with 103 additions and 0 deletions

41
.gitignore vendored Normal file
View File

@ -0,0 +1,41 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
### IntelliJ ###
.idea/

17
pom.xml Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ceticamarco</groupId>
<artifactId>LambdaTonic</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,17 @@
package com.ceticamarco;
import java.util.function.Function;
/**
* <p>
* This protocol defines a new sum type and provides the methods
* to operate on the associated data.
* The <i>Either</i> type can be implemented only by the <i>Left</i>
* and the <i>Right</i> classes.
* </p>
* @param <L> The left type, representing the error value
* @param <R> The right type, representing the actual value
*/
public sealed interface Either<L, R> permits Left, Right {
<T> T match(Function<L, T> onLeft, Function<R, T> onRight);
}

View File

@ -0,0 +1,18 @@
package com.ceticamarco;
import java.util.function.Function;
/**
* <p>
*
* </p>
* @param value
* @param <L>
* @param <R>
*/
public record Left<L, R>(L value) implements Either<L, R> {
@Override
public <T> T match(Function<L, T> onLeft, Function<R, T> onRight) {
return onLeft.apply(this.value);
}
}

View File

@ -0,0 +1,10 @@
package com.ceticamarco;
import java.util.function.Function;
public record Right<L, R>(R value) implements Either<L, R> {
@Override
public <T> T match(Function<L, T> onLeft, Function<R, T> onRight) {
return onRight.apply(this.value);
}
}