ir: moving to labeled chunks, no more IRLabel nodes

This commit is contained in:
Irmen de Jong
2022-10-07 00:34:56 +02:00
parent 2340760f53
commit 6fc89607d3
17 changed files with 997 additions and 846 deletions
+24
View File
@@ -0,0 +1,24 @@
package prog8.code
/**
* By convention, the right side of an `Either` is used to hold successful values.
*/
sealed class Either<out L, out R> {
data class Left<out L>(val value: L) : Either<L, Nothing>()
data class Right<out R>(val value: R) : Either<Nothing, R>()
fun isRight() = this is Right<R>
fun isLeft() = this is Left<L>
inline fun <C> fold(ifLeft: (L) -> C, ifRight: (R) -> C): C = when (this) {
is Right -> ifRight(value)
is Left -> ifLeft(value)
}
}
fun <L> left(a: L) = Either.Left(a)
fun <R> right(b: R) = Either.Right(b)