update OreAddon to use do notation

This commit is contained in:
dfsek
2022-08-15 11:12:10 -07:00
parent 8538ee6804
commit 45c3729392
5 changed files with 67 additions and 15 deletions
@@ -1,8 +1,9 @@
package com.dfsek.terra.addons.manifest.api;
import com.dfsek.terra.addons.manifest.api.monad.Init;
import com.dfsek.terra.api.util.function.monad.Monad;
public interface MonadAddonInitializer {
Init<?> initialize();
Monad<?, Init<?>> initialize();
}
@@ -32,6 +32,12 @@ public final class Do {
.bind(bind2.apply(t)));
}
public static <T, U, V, M extends Monad<?, M>> Monad<V, M> with(Monad<T, M> monad,
Monad<U, M> monad2,
Function2<T, U, Monad<V, M>> bind2) {
return with(monad, Function1.constant(monad2), bind2);
}
public static <T, U, V, W, M extends Monad<?, M>> Monad<W, M> with(Monad<T, M> monad,
Function1<T, Monad<U, M>> bind,
Function2<T, U, Monad<V, M>> bind2,
@@ -45,6 +51,20 @@ public final class Do {
.apply(u)));
}
public static <T, U, V, W, M extends Monad<?, M>> Monad<W, M> with(Monad<T, M> monad,
Monad<U, M> monad2,
Function2<T, U, Monad<V, M>> bind2,
Function3<T, U, V, Monad<W, M>> bind3) {
return with(monad, Function1.constant(monad2), bind2, bind3);
}
public static <T, U, V, W, M extends Monad<?, M>> Monad<W, M> with(Monad<T, M> monad,
Monad<U, M> monad2,
Monad<V, M> monad3,
Function3<T, U, V, Monad<W, M>> bind3) {
return with(monad, monad2, Function2.constant(monad3), bind3);
}
public static <T, U, V, W, X, M extends Monad<?, M>> Monad<X, M> with(Monad<T, M> monad,
Function1<T, Monad<U, M>> bind,
Function2<T, U, Monad<V, M>> bind2,
@@ -61,4 +81,28 @@ public final class Do {
.apply(v)))
.apply(u)));
}
public static <T, U, V, W, X, M extends Monad<?, M>> Monad<X, M> with(Monad<T, M> monad,
Monad<U, M> monad2,
Function2<T, U, Monad<V, M>> bind2,
Function3<T, U, V, Monad<W, M>> bind3,
Function4<T, U, V, W, Monad<X, M>> bind4) {
return with(monad, Function1.constant(monad2), bind2, bind3, bind4);
}
public static <T, U, V, W, X, M extends Monad<?, M>> Monad<X, M> with(Monad<T, M> monad,
Monad<U, M> monad2,
Monad<V, M> monad3,
Function3<T, U, V, Monad<W, M>> bind3,
Function4<T, U, V, W, Monad<X, M>> bind4) {
return with(monad, monad2, Function2.constant(monad3), bind3, bind4);
}
public static <T, U, V, W, X, M extends Monad<?, M>> Monad<X, M> with(Monad<T, M> monad,
Monad<U, M> monad2,
Monad<V, M> monad3,
Monad<W, M> monad4,
Function4<T, U, V, W, Monad<X, M>> bind4) {
return with(monad, monad2, monad3, Function3.constant(monad4), bind4);
}
}
@@ -34,6 +34,10 @@ public class Init<T> implements Monad<T, Init<?>> {
@Override
public <U> Monad<U, Init<?>> pure(U u) {
return of(Functions.constant(u));
return ofPure(u);
}
public static <T> Init<T> ofPure(T t) {
return of(Functions.constant(t));
}
}
@@ -2,6 +2,7 @@ package com.dfsek.terra.addons.manifest.impl;
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
import com.dfsek.terra.addons.manifest.api.MonadAddonInitializer;
import com.dfsek.terra.addons.manifest.api.monad.Init;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.inject.Injector;
@@ -34,7 +35,7 @@ public abstract class Initializer {
@Override
public void initialize(InitInfo info) {
addon.initialize().apply(info);
((Init<?>) addon.initialize()).apply(info);
}
}