Skip to content

Instantly share code, notes, and snippets.

@masak
Last active December 11, 2015 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save masak/4672575 to your computer and use it in GitHub Desktop.
Save masak/4672575 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes, using roles and decoration
role Filter[Int $factor] {
method next { repeat until $.value % $factor { callsame } }
}
class Stream {
has Int $.value is rw = 1;
method next { ++$.value }
method filter { self but Filter[$.value] }
}
.next, say .value for Stream.new, *.filter ... *;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment