From 384c841b86e6f0568ecb86e6099865c43fbc83cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Mu=C3=B1oz?= Date: Fri, 3 May 2024 23:11:24 +0200 Subject: [PATCH] code cleanup --- .../tonivade/purefun/free/FreeTest.java | 3 +-- .../purefun/typeclasses/MonadDeferTest.java | 26 +++++++++---------- .../purefun/typeclasses/Traverse.java | 2 +- .../purefun/typeclasses/ConcurrentTest.java | 4 +-- .../tonivade/purefun/typeclasses/ForTest.java | 10 +++---- .../purefun/typeclasses/MonadStateTest.java | 2 +- .../purefun/typeclasses/SelectiveTest.java | 2 +- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/free/src/test/java/com/github/tonivade/purefun/free/FreeTest.java b/free/src/test/java/com/github/tonivade/purefun/free/FreeTest.java index f79ce54d4..167975409 100644 --- a/free/src/test/java/com/github/tonivade/purefun/free/FreeTest.java +++ b/free/src/test/java/com/github/tonivade/purefun/free/FreeTest.java @@ -13,7 +13,6 @@ import com.github.tonivade.purefun.core.Unit; import com.github.tonivade.purefun.data.ImmutableList; import com.github.tonivade.purefun.instances.StateInstances; -import com.github.tonivade.purefun.monad.IO; import com.github.tonivade.purefun.monad.State; import com.github.tonivade.purefun.monad.StateOf; import com.github.tonivade.purefun.runtimes.ConsoleExecutor; @@ -40,7 +39,7 @@ public void interpretState() { @Test public void interpretIO() { - var foldMap = echo.foldMap(Instances.>monad(), new IOProgramToIO()); + var foldMap = echo.foldMap(Instances.monad(), new IOProgramToIO()); var executor = new ConsoleExecutor().read("Toni"); diff --git a/instances/src/test/java/com/github/tonivade/purefun/typeclasses/MonadDeferTest.java b/instances/src/test/java/com/github/tonivade/purefun/typeclasses/MonadDeferTest.java index e94f033c8..bfdf9e4c4 100644 --- a/instances/src/test/java/com/github/tonivade/purefun/typeclasses/MonadDeferTest.java +++ b/instances/src/test/java/com/github/tonivade/purefun/typeclasses/MonadDeferTest.java @@ -36,7 +36,7 @@ @ExtendWith(MockitoExtension.class) public class MonadDeferTest { - private MonadDefer> ioMonadDefer = Instances.>monadDefer(); + private MonadDefer> ioMonadDefer = Instances.monadDefer(); private MonadDefer, Void>, Throwable>> PureIOMonadDefer = new Instance, Void>, Throwable>>(){}.monadDefer(); private MonadDefer, IO>, Throwable>> eitherTMonadDefer = @@ -92,8 +92,8 @@ public void ioBracketUseError() throws Exception { @Test public void eitherTBracket() throws Exception { Kind, IO>, Throwable>, String> bracket = - eitherTMonadDefer.bracket(EitherT., Throwable, AutoCloseable>right(Instances.>monad(), resource), - r -> EitherT., Throwable, String>right(Instances.>monad(), "done")); + eitherTMonadDefer.bracket(EitherT., Throwable, AutoCloseable>right(Instances.monad(), resource), + r -> EitherT., Throwable, String>right(Instances.monad(), "done")); String result = bracket.fix(EitherTOf::narrowK).get().fix(toIO()).unsafeRunSync(); @@ -104,8 +104,8 @@ public void eitherTBracket() throws Exception { @Test public void eitherTBracketAcquireError() throws Exception { Kind, IO>, Throwable>, String> bracket = - eitherTMonadDefer.bracket(EitherT., Throwable, AutoCloseable>left(Instances.>monad(), new IllegalStateException()), - r -> EitherT., Throwable, String>right(Instances.>monad(), "done")); + eitherTMonadDefer.bracket(EitherT., Throwable, AutoCloseable>left(Instances.monad(), new IllegalStateException()), + r -> EitherT., Throwable, String>right(Instances.monad(), "done")); assertThrows(IllegalStateException.class, () -> bracket.fix(EitherTOf::narrowK).value().fix(toIO()).unsafeRunSync()); @@ -116,8 +116,8 @@ public void eitherTBracketAcquireError() throws Exception { @Test public void eitherTBracketUseError() throws Exception { Kind, IO>, Throwable>, String> bracket = - eitherTMonadDefer.bracket(EitherT., Throwable, AutoCloseable>right(Instances.>monad(), resource), - r -> EitherT., Throwable, String>left(Instances.>monad(), new UnsupportedOperationException())); + eitherTMonadDefer.bracket(EitherT., Throwable, AutoCloseable>right(Instances.monad(), resource), + r -> EitherT., Throwable, String>left(Instances.monad(), new UnsupportedOperationException())); Either unsafeRunSync = bracket.fix(toEitherT()).value().fix(toIO()).unsafeRunSync(); @@ -128,8 +128,8 @@ public void eitherTBracketUseError() throws Exception { @Test public void optionTBracket() throws Exception { Kind, IO>, String> bracket = - optionTMonadDefer.bracket(OptionT.some(Instances.>monad(), resource), - r -> OptionT.some(Instances.>monad(), "done")); + optionTMonadDefer.bracket(OptionT.some(Instances.monad(), resource), + r -> OptionT.some(Instances.monad(), "done")); String result = bracket.fix(OptionTOf::narrowK).getOrElseThrow().fix(toIO()).unsafeRunSync(); @@ -141,8 +141,8 @@ public void optionTBracket() throws Exception { @Disabled public void optionTBracketAcquireError() throws Exception { Kind, IO>, String> bracket = - optionTMonadDefer.bracket(OptionT., AutoCloseable>none(Instances.>monad()), - r -> OptionT.some(Instances.>monad(), "done")); + optionTMonadDefer.bracket(OptionT., AutoCloseable>none(Instances.monad()), + r -> OptionT.some(Instances.monad(), "done")); NoSuchElementException error = assertThrows(NoSuchElementException.class, () -> bracket.fix(OptionTOf::narrowK).getOrElseThrow().fix(toIO()).unsafeRunSync()); @@ -155,8 +155,8 @@ public void optionTBracketAcquireError() throws Exception { @Disabled public void optionTBracketUseError() throws Exception { Kind, IO>, String> bracket = - optionTMonadDefer.bracket(OptionT.some(Instances.>monad(), resource), - r -> OptionT., String>none(Instances.>monad())); + optionTMonadDefer.bracket(OptionT.some(Instances.monad(), resource), + r -> OptionT., String>none(Instances.monad())); NoSuchElementException error = assertThrows(NoSuchElementException.class, () -> bracket.fix(OptionTOf::narrowK).getOrElseThrow().fix(toIO()).unsafeRunSync()); diff --git a/typeclasses/src/main/java/com/github/tonivade/purefun/typeclasses/Traverse.java b/typeclasses/src/main/java/com/github/tonivade/purefun/typeclasses/Traverse.java index 2e755f2ef..ff026f824 100644 --- a/typeclasses/src/main/java/com/github/tonivade/purefun/typeclasses/Traverse.java +++ b/typeclasses/src/main/java/com/github/tonivade/purefun/typeclasses/Traverse.java @@ -24,7 +24,7 @@ default Kind> sequence(Applicative applicative, @Override default Kind map(Kind value, Function1 map) { - Kind, Kind> traverse = traverse(Instances.>applicative(), value, t -> Id.of(map.apply(t))); + Kind, Kind> traverse = traverse(Instances.applicative(), value, t -> Id.of(map.apply(t))); return traverse.fix(toId()).value(); } diff --git a/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/ConcurrentTest.java b/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/ConcurrentTest.java index e1a64ba6d..43d29c449 100644 --- a/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/ConcurrentTest.java +++ b/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/ConcurrentTest.java @@ -23,7 +23,7 @@ public class ConcurrentTest { @Test public void ioRaceA() { - Concurrent> concurrent = Instances.>concurrent(); + Concurrent> concurrent = Instances.concurrent(); Kind, Either> race = concurrent.race( IO.delay(Duration.ofMillis(10), () -> 10), @@ -36,7 +36,7 @@ public void ioRaceA() { @Test public void ioRaceB() { - Concurrent> concurrent = Instances.>concurrent(); + Concurrent> concurrent = Instances.concurrent(); Kind, Either> race = concurrent.race( IO.delay(Duration.ofMillis(100), () -> 10), diff --git a/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/ForTest.java b/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/ForTest.java index cba094ffe..ad2e0a9b9 100644 --- a/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/ForTest.java +++ b/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/ForTest.java @@ -27,7 +27,7 @@ @ExtendWith(MockitoExtension.class) public class ForTest { - final Monad> monad = Instances.>monad(); + final Monad> monad = Instances.monad(); @Test public void map() { @@ -55,9 +55,9 @@ public void returns(@Mock Function1 mapper) { @Test public void flatMap() { - Id result = For.with(Instances.>monad()) - .andThen(() -> Instances.>monad().pure("value")) - .flatMap(string -> Instances.>monad().pure(string.toUpperCase())) + Id result = For.with(monad) + .andThen(() -> monad.pure("value")) + .flatMap(string -> monad.pure(string.toUpperCase())) .fix(toId()); assertEquals(Id.of("VALUE"), result); @@ -68,7 +68,7 @@ public void applyBug(@Mock Producer task1, @Mock Producer task2) when(task1.get()).thenReturn("hola toni"); when(task2.get()).thenReturn("adios toni"); - Applicative> monad = Instances.>applicative(); + Applicative> monad = Instances.applicative(); var result = For.with(monad) .then(IO.task(task1)) .then(IO.task(task2)) diff --git a/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/MonadStateTest.java b/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/MonadStateTest.java index d917e2944..e1f47ecfc 100644 --- a/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/MonadStateTest.java +++ b/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/MonadStateTest.java @@ -16,7 +16,7 @@ public class MonadStateTest { private MonadState, ImmutableArray> monadState = - MonadState.from(Instances.>monadDefer(), ImmutableArray.empty()); + MonadState.from(Instances.monadDefer(), ImmutableArray.empty()); @Test public void program() { diff --git a/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/SelectiveTest.java b/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/SelectiveTest.java index 3af36d902..f3c510cd8 100644 --- a/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/SelectiveTest.java +++ b/typeclasses/src/test/java/com/github/tonivade/purefun/typeclasses/SelectiveTest.java @@ -33,7 +33,7 @@ @ExtendWith(MockitoExtension.class) class SelectiveTest { - private final Selective> monad = Instances.>monad(); + private final Selective> monad = Instances.monad(); @Test void apply() {