net.minestom.server.utils.Either Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of minestom-snapshots Show documentation
Show all versions of minestom-snapshots Show documentation
1.20.4 Lightweight Minecraft server
package net.minestom.server.utils;
import java.util.function.Function;
public record Either(boolean isLeft, L left, R right) {
public static Either left(T left) {
return new Either<>(true, left, null);
}
public static Either right(T right) {
return new Either<>(false, null, right);
}
public T map(Function leftMapper, Function rightMapper) {
if (isLeft) {
return leftMapper.apply(left);
} else {
return rightMapper.apply(right);
}
}
}