Created
          November 14, 2016 20:11 
        
      - 
      
 - 
        
Save Dierk/c37941c9383b695b30209e34638f8d65 to your computer and use it in GitHub Desktop.  
    Monoidal Fizzbuzz in Purescript
  
        
  
    
      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
    
  
  
    
  | module Main where | |
| import Control.Monad.Eff.Console (log) | |
| import Data.List.Lazy (take, zipWith, fromFoldable, cycle, iterate, foldr) | |
| import Data.Monoid (mempty, (<>)) | |
| import Data.Maybe (Maybe(..), fromMaybe) | |
| import Prelude ( show, map, ($), (+)) | |
| main = do | |
| log $ join $ take 100 $ fizzbuzz | |
| where | |
| join = foldr (\x y -> x <> " " <> y) "" | |
| nums = map show $ iterate (\x -> x+1) 1 | |
| fizzes = cycle $ fromFoldable [mempty, mempty, Just "fizz" ] | |
| buzzes = cycle $ fromFoldable [mempty, mempty, mempty, mempty, Just "buzz" ] | |
| pattern = zipWith (<>) fizzes buzzes | |
| fizzbuzz = zipWith fromMaybe nums pattern | 
Cool, this inspired me to do an extensible version: https://gist.github.com/mathiasverraes/763ebf4a7c6ed5e364840e021af5e431 (haskell)
Thank you both! @mathiasverraes: I added your solution to the references section of https://dierk.gitbooks.io/fregegoodness/content/src/docs/asciidoc/fizzbuzz_monoid.html
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Awesome!