-
-
Save 7h3kk1d/66272357ac7d9d18da268b552d632b1b to your computer and use it in GitHub Desktop.
bool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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