Replying to Avatar YoshikuniJujo

HaskellでZipListを使ったFizzBuzz

{-# LANGUAGE TypeApplications #-}

{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}

module Main (main) where

import Control.Applicative

import Data.Foldable

z :: [a] -> ZipList a; unz :: ZipList a -> [a]; cycleZ :: [a] -> ZipList a

(z, unz, cycleZ) = (ZipList, getZipList, z . cycle)

main :: IO ()

main = traverse_ (either @Int print putStrLn) . take 100 . unz $ z [1 ..]

<**> cycleZ [Left, Left, const $ Right "Fizz"]

<**> cycleZ [id, id, id, id,

either (const Right) ((Right .) . (<>)) `flip` "Buzz"]

https://github.com/YoshikuniJujo/test_haskell/blob/master/tribial/tribial-mains/app/fizzbuzz-ziplist.hs

Avatar
frphank 1y ago

` ` `

let (m ~> str) x = str <$ guard (x ` mod` m == 0)

in map (fromMaybe . show <*> 3 ~> "fizz" <> 5 ~> "buzz")

` ` `

Reply to this note

Please Login to reply.

Discussion

No replies yet.