Skip to content

Instantly share code, notes, and snippets.

@kgashok
Last active May 7, 2016 16:54
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 kgashok/77640a826dd3581df7c6894e097192d3 to your computer and use it in GitHub Desktop.
Save kgashok/77640a826dd3581df7c6894e097192d3 to your computer and use it in GitHub Desktop.
A more dynamic version of fizzBuzz
import Graphics.Element exposing (..)
type alias Filter =
{ divisor : Int,
string : String
}
inputFilters =
[ Filter 3 "Fizz"
, Filter 5 "Buzz"
, Filter 7 "Mix"
]
applyFilter : Int -> Filter -> Maybe String
applyFilter number filter =
if number % filter.divisor == 0 then
Just filter.string
else
Nothing
applyFilters filters number =
let
res = List.filterMap (applyFilter number) filters
|> List.foldr (++) ""
in
if res == "" then
toString number
else
res
main: Element
main =
let
output =
List.map (applyFilters inputFilters) [1..110]
in
output |> List.map show |> flow down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment