Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
</properties>

<dependencies>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -47,6 +52,38 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<configuration>
<fork>true</fork>
<meminitial>128m</meminitial>
<maxmem>2048m</maxmem>
<compilerArgs>
Comment thread
Garciat marked this conversation as resolved.
<arg>-XDcompilePolicy=simple</arg>
<arg>--should-stop=ifError=FLOW</arg>
<arg>-Xplugin:ErrorProne -Xep:NullAway:ERROR -XepOpt:NullAway:AnnotatedPackages=com.garciat.typeclasses</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.45.0</version>
</path>
<path>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>0.12.14</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -86,6 +123,9 @@
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
7 changes: 5 additions & 2 deletions src/main/java/com/garciat/typeclasses/classes/PrintAll.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.garciat.typeclasses.classes;

import static com.garciat.typeclasses.types.Unit.unit;

import com.garciat.typeclasses.api.TypeClass;
import com.garciat.typeclasses.api.TypeClass.Witness;
import com.garciat.typeclasses.impl.utils.Lists;
import com.garciat.typeclasses.types.F1;
import com.garciat.typeclasses.types.F2;
import com.garciat.typeclasses.types.F3;
import com.garciat.typeclasses.types.Unit;
import java.util.List;
import java.util.function.Function;

Expand All @@ -21,12 +24,12 @@ static <T> T of(PrintAll<T> printAll) {
}

@Witness
static PrintAll<Void> base() {
static PrintAll<Unit> base() {
return strings -> {
for (String s : strings) {
System.out.println(s);
}
return null;
return unit();
};
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/garciat/typeclasses/types/FwdList.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.garciat.typeclasses.types;

import static com.garciat.typeclasses.api.TypeClass.Witness.Overlap.OVERLAPPING;
import static com.garciat.typeclasses.types.Unit.unit;

import com.garciat.typeclasses.api.hkt.Kind;
import com.garciat.typeclasses.api.hkt.Kind.KArr;
Expand Down Expand Up @@ -47,12 +48,12 @@ default <B> B foldl(B identity, BiFunction<B, A, B> f) {
}

default void forEach(Consumer<A> action) {
this.<Void>match(
() -> null,
this.<Unit>match(
() -> unit(),
(head, tail) -> {
action.accept(head);
tail.forEach(action);
return null;
return unit();
});
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/garciat/typeclasses/types/Unit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.garciat.typeclasses.types;

public record Unit() {
public static Unit unit() {
return new Unit();
}
}
3 changes: 2 additions & 1 deletion src/test/java/com/garciat/typeclasses/ExamplesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.garciat.typeclasses.types.JavaList;
import com.garciat.typeclasses.types.Maybe;
import com.garciat.typeclasses.types.Sum;
import com.garciat.typeclasses.types.Unit;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -70,7 +71,7 @@ void example() {
F3<Integer, Integer, Integer, Integer> sum = SumAllInt.of(witness(new Ty<>() {}));
System.out.println(sum.apply(1, 2, 3));

F3<String, JavaList<String>, Integer, Void> printer = PrintAll.of(witness(new Ty<>() {}));
F3<String, JavaList<String>, Integer, Unit> printer = PrintAll.of(witness(new Ty<>() {}));
printer.apply("Items:", JavaList.of("apple", "banana", "cherry"), 0);

Foldable<FwdList.Tag> foldableFwdList = witness(new Ty<>() {});
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/garciat/typeclasses/TypeClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,12 @@ void witnessMapWithDependencies() {
// Test helper classes
// ============================================

@SuppressWarnings("NullAway")
static class NoWitnessType {
String value;
}

@SuppressWarnings("NullAway")
static class CustomType {
String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class TestClass<T> {}

@Test
void parseTypeVariableInParameterizedType() throws Exception {
@SuppressWarnings("NullAway")
class TestClass<T> {
List<T> field;
}
Expand All @@ -88,6 +89,7 @@ class TestClass<T> {

@Test
void parseWildcardTypeThrows() throws Exception {
@SuppressWarnings("NullAway")
class TestClass {
List<?> field;
}
Expand Down