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