Created
June 19, 2016 00:07
-
-
Save Murphydbuffalo/aa6118ed0fdaaa53e97a35c345823618 to your computer and use it in GitHub Desktop.
The final countdown
This file contains hidden or 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
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