organized, added futures

This commit is contained in:
ParkerTenBroeck 2025-04-25 13:25:03 -04:00
parent 13d9ba7363
commit 6424548e75
8 changed files with 29 additions and 6 deletions

View file

@ -0,0 +1,27 @@
package generator.gen;
public interface Gen<Y, R> {
Res<Y, R> next();
static <Y, R> Gen<Y, R> yield(Y y) {
throw new RuntimeException();
}
static <Y, R> Gen<Void, R> yield() {
throw new RuntimeException();
}
static <Y, R> Gen<Y, R> ret(R r) {throw new RuntimeException();}
static <Y, R> Gen<Y, Void> ret() {
throw new RuntimeException();
}
default R await(){
while(true){
var res = next();
if(res instanceof Ret r)return (R)r.v;
}
}
sealed interface Res<Y, R>{}
record Yield<Y, R>(Y v) implements Res<Y, R>{}
record Ret<Y, R>(R v) implements Res<Y, R>{}
}