Skip to content

Instantly share code, notes, and snippets.

@Murphydbuffalo
Created June 19, 2016 00:07
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 Murphydbuffalo/aa6118ed0fdaaa53e97a35c345823618 to your computer and use it in GitHub Desktop.
Save Murphydbuffalo/aa6118ed0fdaaa53e97a35c345823618 to your computer and use it in GitHub Desktop.
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