Skip to content

Instantly share code, notes, and snippets.

@anacrolix
Created June 26, 2020 02:11
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 anacrolix/7b5fef88038b3b8de5b441e7d6e89115 to your computer and use it in GitHub Desktop.
Save anacrolix/7b5fef88038b3b8de5b441e7d6e89115 to your computer and use it in GitHub Desktop.
actor Main
new create(env: Env) =>
let chain = DivisibleFilter(2, Printer(env), env)
let g = Generator(1_000_000, chain)
actor Generator
var _i: I = 2
let _max: I
let _next: Next
new create(max: I, next: Next) =>
_next = next
_max = max
emit()
be emit() =>
if _i <= _max then
_next(_i)
_i = _i + 1
emit()
end
actor Printer
let _env: Env
new create(env: Env) =>
_env = env
be apply(i: I) =>
_env.out.print(i.string())
type I is U64
interface tag Next
be apply(i: I)
actor DivisibleFilter
let _div: I
var _next: Next tag
var _is_last: Bool
let _env: Env
new create(div: I, next: Next tag, env: Env) =>
_div = div
_next = next
_is_last = true
_env = env
be apply(i: I) =>
// _env.out.print(_div.string()+" got "+i.string())
if (i % _div) == 0 then
return
end
_next.apply(i)
if _is_last then
_next = DivisibleFilter(i, _next, _env)
_is_last = false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment