mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
fix functional utils
This commit is contained in:
@@ -2,7 +2,7 @@ package com.dfsek.terra.addons.commands.locate;
|
||||
|
||||
import com.dfsek.seismic.type.vector.Vector2Int;
|
||||
import com.dfsek.seismic.type.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.util.generic.either.Either;
|
||||
import com.dfsek.terra.api.util.generic.data.types.Either;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.util.generic.either.Either;
|
||||
import com.dfsek.terra.api.util.generic.data.types.Either;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.api.util.function;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.either.Either;
|
||||
import com.dfsek.terra.api.util.generic.data.types.Either;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.dfsek.terra.api.util.generic;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.kinds.K;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public interface Applicative<T, A extends K<A, T>> extends Functor<T> {
|
||||
<U, A1 extends K<A1, U>> Applicative<U, A1> pure(U t);
|
||||
|
||||
<U, A1 extends K<A1, U>> Applicative<U, A1> apply(K<A, Function<T, U>> amap);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.dfsek.terra.api.util.generic;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public interface Functor<T> {
|
||||
<U> Functor<U> map(Function<T, U> map);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.dfsek.terra.api.util.generic;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.kinds.K;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
/**
|
||||
* A monad is a monoid in the category of endofunctors.
|
||||
*/
|
||||
public interface Monad<T, M extends K<M, T>> extends Applicative<T, M>, Monoid<T, M>{
|
||||
<T2, M2 extends K<M2, T2>> Monad<T2, M2> bind(Function<T, Monad<T2, M2>> map);
|
||||
@Override
|
||||
<T2, M2 extends K<M2, T2>> Monad<T2, M2> identity();
|
||||
|
||||
@Override
|
||||
<U, M2 extends K<M2, U>> Monad<U, M2> pure(U t);
|
||||
|
||||
@Override
|
||||
Monad<T, M> multiply(M t);
|
||||
|
||||
@Override
|
||||
default <U, M2 extends K<M2, U>> Monad<U, M2> map(Function<T, U> map) {
|
||||
return bind(m -> pure(map.apply(m)));
|
||||
}
|
||||
|
||||
@Override
|
||||
default <U, A1 extends K<A1, U>> Monad<U, A1> apply(K<M, Function<T, U>> amap) {
|
||||
amap.self()
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.dfsek.terra.api.util.generic;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.kinds.K;
|
||||
|
||||
|
||||
public interface Monoid<T, M extends K<M, T>> extends Semigroup<T, M>{
|
||||
<T1, M1 extends K<M1, T1>> Monoid<T1, M1> identity();
|
||||
|
||||
@Override
|
||||
Monoid<T, M> multiply(M t);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.dfsek.terra.api.util.generic;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.kinds.K;
|
||||
|
||||
|
||||
public interface Semigroup<T, S extends K<S, T>> {
|
||||
Semigroup<T, S> multiply(S t);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.dfsek.terra.api.util.generic.control;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.data.Functor;
|
||||
import com.dfsek.terra.api.util.generic.kinds.K;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
/**
|
||||
* A monad is a monoid in the category of endofunctors.
|
||||
*/
|
||||
public interface Monad<T, M extends Monad<?, M>> extends Functor<T, M>, K<M, T> {
|
||||
<T2, M2 extends Monad<?, M2>> Monad<T2, M2> bind(Function<T, Monad<T2, M2>> map);
|
||||
|
||||
<T1, M1 extends Monad<?, M1>> Monad<T1, M1> pure(T1 t);
|
||||
|
||||
@Override
|
||||
default <U> Monad<U, M> map(Function<T, U> map) {
|
||||
return bind(map.andThen(this::pure));
|
||||
}
|
||||
|
||||
// almost all well-known applicative functors are also monads, so we can just put that here.
|
||||
default <U> Monad<U, M> apply(Monad<Function<T, U>, M> amap) {
|
||||
return amap.bind(this::map);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.dfsek.terra.api.util.generic.data;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.kinds.K;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public interface Functor<T, F extends Functor<?, F>> extends K<F, T> {
|
||||
<U> Functor<U, F> map(Function<T, U> map);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.dfsek.terra.api.util.generic.data;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.kinds.K;
|
||||
|
||||
|
||||
public interface Monoid<T, M extends Monoid<?, M>> extends Semigroup<T, M>, K<M, T>{
|
||||
<T1, M1 extends Monoid<?, M1>> Monoid<T1, M1> identity();
|
||||
|
||||
@Override
|
||||
Monoid<T, M> multiply(M t);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.api.util.generic.data;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.kinds.K;
|
||||
|
||||
|
||||
public interface Semigroup<T, S extends Semigroup<?, S>> extends K<S, T> {
|
||||
Semigroup<T, S> multiply(S t);
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.api.util.generic.either;
|
||||
package com.dfsek.terra.api.util.generic.data.types;
|
||||
|
||||
import com.dfsek.terra.api.util.function.FunctionUtils;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package com.dfsek.terra.api.util.generic;
|
||||
package com.dfsek.terra.api.util.generic.data.types;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.control.Monad;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.api.util.generic.kinds;
|
||||
|
||||
/**
|
||||
* Kind
|
||||
* Kind of the type T<U>
|
||||
*/
|
||||
public interface K<T, U> {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
Reference in New Issue
Block a user