Skip to content

Instantly share code, notes, and snippets.

@blackode
Last active February 19, 2017 20:40
Show Gist options
  • Save blackode/260e69a1659c19054d43e17dbc3d11a4 to your computer and use it in GitHub Desktop.
Save blackode/260e69a1659c19054d43e17dbc3d11a4 to your computer and use it in GitHub Desktop.
defmodule WhileLoop do
defmacro while(condition_expression, do: do_block) do
quote do
try do
for _ <- Stream.cycle([:fine]) do
if unquote(condition_expression) do
unquote(do_block)
else
throw :break
end
end
catch
:break -> :ok
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment