Skip to content

Instantly share code, notes, and snippets.

@polux
Created December 18, 2013 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polux/8021388 to your computer and use it in GitHub Desktop.
Save polux/8021388 to your computer and use it in GitHub Desktop.
Staged "contains" method
class Cons {
final x;
final xs;
Cons(this.x, this.xs);
freeze() => new Cons(((v) => <v>)(this.x), this.xs.freeze());
contains(e) => < (~this.x).eq(~e) ? true : ~(this.xs.contains(e)) >;
}
class Nil {
Nil();
freeze() => new Nil();
contains(e) => <false>;
}
class Demo {
Demo();
range(n) => n.eq(0) ? new Nil() : new Cons(n, this.range(n.minus(1)));
inRange10() => run(<(e) => ~this.range(10).freeze().contains(<e>)>);
}
main() {
print(new Demo().inRange10());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment