Skip to content

Instantly share code, notes, and snippets.

@ykon
Created November 23, 2017 12:52
Show Gist options
  • Save ykon/3fd8fb9743aefe018c8ec4242bb428df to your computer and use it in GitHub Desktop.
Save ykon/3fd8fb9743aefe018c8ec4242bb428df to your computer and use it in GitHub Desktop.
FizzBuzz in Elm
{--
Copyright (c) 2017 Yuki Ono
Licensed under the MIT License.
--}
import Html exposing (..)
import List
import String
type FizzBuzzType
= FizzBuzz Int
| Fizz Int
| Buzz Int
| Number Int
toFizzBuzz : Int -> FizzBuzzType
toFizzBuzz n =
case (n % 3, n % 5) of
(0, 0) -> FizzBuzz n
(0, _) -> Fizz n
(_, 0) -> Buzz n
(_, _) -> Number n
fizzBuzzToStr : FizzBuzzType -> String
fizzBuzzToStr fb =
case fb of
FizzBuzz _ -> "FizzBuzz"
Fizz _ -> "Fizz"
Buzz _ -> "Buzz"
Number n -> toString n
main : Html msg
main =
List.range 1 100
|> List.map (toFizzBuzz >> fizzBuzzToStr)
|> String.join ", "
|> text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment