mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-17 13:49:57 +00:00
implement MonadAddonInitializer
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.dfsek.terra.api.util.function;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public final class Functions {
|
||||
private Functions() {
|
||||
|
||||
}
|
||||
|
||||
public static <T, U> Function<T, U> constant(U value) {
|
||||
return ignore -> value;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,6 @@ package com.dfsek.terra.api.util.function.functor;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public interface Functor<T> {
|
||||
<U> Functor<U> map(Function<T, U> map);
|
||||
public interface Functor<T, F extends Functor<?, F>> {
|
||||
<U> Functor<U, F> map(Function<T, U> map);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
package com.dfsek.terra.api.util.function.monad;
|
||||
|
||||
import com.dfsek.terra.api.util.function.functor.Functor;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public interface Monad<T> {
|
||||
<U> Monad<U> bind(Function<T, Monad<U>> map);
|
||||
public interface Monad<T, M extends Monad<?, M>> extends Functor<T, M> {
|
||||
<U> Monad<U, M> bind(Function<T, Monad<U, M>> map);
|
||||
|
||||
default <U> Monad<U, M> map(Function<T, U> fn) {
|
||||
return bind(a -> pure(fn.apply(a)));
|
||||
}
|
||||
|
||||
<U> Monad<U, M> pure(U u);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user