Last active
December 11, 2015 22:49
-
-
Save masak/4672575 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes, using roles and decoration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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