mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 14:50:56 +00:00
update OreAddon to use do notation
This commit is contained in:
@@ -8,25 +8,27 @@
|
|||||||
package com.dfsek.terra.addons.ore;
|
package com.dfsek.terra.addons.ore;
|
||||||
|
|
||||||
import com.dfsek.terra.addons.manifest.api.MonadAddonInitializer;
|
import com.dfsek.terra.addons.manifest.api.MonadAddonInitializer;
|
||||||
|
import com.dfsek.terra.addons.manifest.api.monad.Do;
|
||||||
import com.dfsek.terra.addons.manifest.api.monad.Get;
|
import com.dfsek.terra.addons.manifest.api.monad.Get;
|
||||||
import com.dfsek.terra.addons.manifest.api.monad.Init;
|
import com.dfsek.terra.addons.manifest.api.monad.Init;
|
||||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||||
|
import com.dfsek.terra.api.util.function.monad.Monad;
|
||||||
|
|
||||||
|
|
||||||
public class OreAddon implements MonadAddonInitializer {
|
public class OreAddon implements MonadAddonInitializer {
|
||||||
@Override
|
@Override
|
||||||
public Init<?> initialize() {
|
public Monad<?, Init<?>> initialize() {
|
||||||
return Get.eventManager()
|
return Do.with(
|
||||||
.map(eventManager -> eventManager.getHandler(FunctionalEventHandler.class))
|
Get.eventManager().map(manager -> manager.getHandler(FunctionalEventHandler.class)),
|
||||||
.bind(functionalEventHandler ->
|
Get.addon(),
|
||||||
Get.addon()
|
((eventHandler, addon) -> Init
|
||||||
.map(addon -> functionalEventHandler
|
.ofPure(eventHandler
|
||||||
.register(addon, ConfigPackPreLoadEvent.class)
|
.register(addon, ConfigPackPreLoadEvent.class)
|
||||||
.then(event -> event
|
.then(event -> event
|
||||||
.getPack()
|
.getPack()
|
||||||
.registerConfigType(new OreConfigType(), addon.key("ORE"), 1))
|
.registerConfigType(new OreConfigType(), addon.key("ORE"), 1))
|
||||||
.failThrough()
|
.failThrough()))
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -1,8 +1,9 @@
|
|||||||
package com.dfsek.terra.addons.manifest.api;
|
package com.dfsek.terra.addons.manifest.api;
|
||||||
|
|
||||||
import com.dfsek.terra.addons.manifest.api.monad.Init;
|
import com.dfsek.terra.addons.manifest.api.monad.Init;
|
||||||
|
import com.dfsek.terra.api.util.function.monad.Monad;
|
||||||
|
|
||||||
|
|
||||||
public interface MonadAddonInitializer {
|
public interface MonadAddonInitializer {
|
||||||
Init<?> initialize();
|
Monad<?, Init<?>> initialize();
|
||||||
}
|
}
|
||||||
|
|||||||
+44
@@ -32,6 +32,12 @@ public final class Do {
|
|||||||
.bind(bind2.apply(t)));
|
.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,
|
public static <T, U, V, W, M extends Monad<?, M>> Monad<W, M> with(Monad<T, M> monad,
|
||||||
Function1<T, Monad<U, M>> bind,
|
Function1<T, Monad<U, M>> bind,
|
||||||
Function2<T, U, Monad<V, M>> bind2,
|
Function2<T, U, Monad<V, M>> bind2,
|
||||||
@@ -45,6 +51,20 @@ public final class Do {
|
|||||||
.apply(u)));
|
.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,
|
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,
|
Function1<T, Monad<U, M>> bind,
|
||||||
Function2<T, U, Monad<V, M>> bind2,
|
Function2<T, U, Monad<V, M>> bind2,
|
||||||
@@ -61,4 +81,28 @@ public final class Do {
|
|||||||
.apply(v)))
|
.apply(v)))
|
||||||
.apply(u)));
|
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -34,6 +34,10 @@ public class Init<T> implements Monad<T, Init<?>> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <U> Monad<U, Init<?>> pure(U u) {
|
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
-1
@@ -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.AddonInitializer;
|
||||||
import com.dfsek.terra.addons.manifest.api.MonadAddonInitializer;
|
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.Platform;
|
||||||
import com.dfsek.terra.api.addon.BaseAddon;
|
import com.dfsek.terra.api.addon.BaseAddon;
|
||||||
import com.dfsek.terra.api.inject.Injector;
|
import com.dfsek.terra.api.inject.Injector;
|
||||||
@@ -34,7 +35,7 @@ public abstract class Initializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(InitInfo info) {
|
public void initialize(InitInfo info) {
|
||||||
addon.initialize().apply(info);
|
((Init<?>) addon.initialize()).apply(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user