Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The final countdown
defmodule Countdown do
def from(number, phrase \\ 'Aww shucky ducky!') do
Stream.iterate(number, &(&1 - 1)) |> Enum.take(number + 1) |> Enum.map(
fn
0 -> say(phrase)
number ->
say(number)
sleep(1)
end
)
end
defp sleep(seconds) do
receive do
after seconds * 1000 -> :done
end
end
defp say(phrase) do
spawn fn -> :os.cmd('say #{phrase}') end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment