Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A functional FizzBuzz (without any integer modulus or division) in Elixir. See https://pragprog.com/magazines/2012-08/thinking-functionally-with-haskell
# A functional FizzBuzz (without any integer modulus or division) in Elixir
# https://pragprog.com/magazines/2012-08/thinking-functionally-with-haskell
nums = Stream.iterate(1, &(&1 + 1))
fizz = Stream.cycle ["", "", "Fizz"]
buzz = Stream.cycle ["", "", "", "", "Buzz"]
fizzbuzz = Stream.zip(fizz, buzz) |> Stream.zip(nums) |> Stream.map(fn
{{"", "" }, number} -> number
{{fizzword, buzzword}, _number} -> fizzword <> buzzword
end)
fizzbuzz |> Stream.take(100) |> Enum.each(&IO.puts/1)
@janxious

This comment has been minimized.

Copy link

@janxious janxious commented May 20, 2015

😸

@llambeau

This comment has been minimized.

Copy link

@llambeau llambeau commented May 20, 2015

👍 😄

@elbow-jason

This comment has been minimized.

Copy link

@elbow-jason elbow-jason commented May 20, 2015

this is pretty cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment