Skip to content

Instantly share code, notes, and snippets.

@wende
Last active May 31, 2017 16:50
Show Gist options
  • Save wende/9cef083b2d3964f46c6520441ffb56bb to your computer and use it in GitHub Desktop.
Save wende/9cef083b2d3964f46c6520441ffb56bb to your computer and use it in GitHub Desktop.
Elmchemy article #2
module FizzBuzz exposing (fizzbuzz)
import List exposing (map, range)
{-| Fizzes the buzzes and buzzfizzes the fizz out of buzz
fizzbuzz 1 7 == "1 2 Fizz 4 Buzz Fizz 7"
-}
fizzbuzz : Int -> Int -> String
fizzbuzz from to =
let fizzBuzz n = case (n % 3, n % 5) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(_, 0) -> "Buzz"
_ -> toString n
in List.range from to |> map (fizzBuzz >> toString) |> joinWords
joinWords : List String -> String
joinWords list = String.join " " list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment