Skip to content

Instantly share code, notes, and snippets.

@7h3kk1d
Created April 8, 2020 00:40
Show Gist options
  • Save 7h3kk1d/66272357ac7d9d18da268b552d632b1b to your computer and use it in GitHub Desktop.
Save 7h3kk1d/66272357ac7d9d18da268b552d632b1b to your computer and use it in GitHub Desktop.
bool.java
public abstract class Bool extends Number implements CoProduct2<Bool.False, Bool.True, Bool> {
@Override
public byte byteValue() {
return match(constantly((byte) 0),
constantly((byte) 1));
}
@Override
public short shortValue() {
return byteValue();
}
@Override
public int intValue() {
return byteValue();
}
@Override
public long longValue() {
return byteValue();
}
@Override
public float floatValue() {
return byteValue();
}
@Override
public double doubleValue() {
return byteValue();
}
public abstract Bool add(Bool bool);
public static class False extends Bool {
@Override
public <R> R match(Fn1<? super False, ? extends R> fn1, Fn1<? super True, ? extends R> fn11) {
return fn1.apply(this);
}
@Override
public Bool add(Bool bool) {
return bool.match(constantly(this),
constantly(new True()));
}
}
public static class True extends Bool {
@Override
public <R> R match(Fn1<? super False, ? extends R> fn1, Fn1<? super True, ? extends R> fn11) {
return fn11.apply(this);
}
@Override
public Bool add(Bool bool) {
return this;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment