mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-12 10:46:25 +00:00
implement Bifunctor Pair
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.api.util.generic.pair;
|
||||
package com.dfsek.terra.api.util.generic.data.types;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.data.BiFunctor;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -17,15 +19,15 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
|
||||
public record Pair<L, R>(L left, R right) implements Bifunctor{
|
||||
public record Pair<L, R>(L left, R right) implements BiFunctor<L, R, Pair<?, ?>> {
|
||||
private static final Pair<?, ?> NULL = new Pair<>(null, null);
|
||||
|
||||
public static <L, R, T> Function<Pair<L, R>, Pair<T, R>> mapLeft(Function<L, T> function) {
|
||||
return pair -> of(function.apply(pair.left), pair.right);
|
||||
public <T> Pair<T, R> mapLeft(Function<L, T> function) {
|
||||
return of(function.apply(left), right);
|
||||
}
|
||||
|
||||
public static <L, R, T> Function<Pair<L, R>, Pair<L, T>> mapRight(Function<R, T> function) {
|
||||
return pair -> of(pair.left, function.apply(pair.right));
|
||||
public <T> Pair<L, T> mapRight(Function<R, T> function) {
|
||||
return of(left, function.apply(right));
|
||||
}
|
||||
|
||||
public static <L> Predicate<Pair<L, ?>> testLeft(Predicate<L> predicate) {
|
||||
@@ -6,13 +6,11 @@ import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.github.benmanes.caffeine.cache.Scheduler;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.util.cache.SeededVector2Key;
|
||||
import com.dfsek.terra.api.util.cache.SeededVector3Key;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair.Mutable;
|
||||
import com.dfsek.terra.api.util.generic.data.types.Pair;
|
||||
import com.dfsek.terra.api.util.generic.data.types.Pair.Mutable;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
import static com.dfsek.terra.api.util.cache.CacheUtils.CACHE_EXECUTOR;
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import com.dfsek.terra.api.util.Column;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.generic.data.types.Pair;
|
||||
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
Reference in New Issue
Block a user