File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed
Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change 11module Main where
22
3- import Control.Arrow (Arrow (first , (&&&) ))
4- import Data.Functor ((<&>) )
3+ import Control.Arrow (Arrow ((&&&) ))
54import Data.List (genericLength , group , sort )
65import System.Directory (listDirectory )
76import System.FilePath (takeExtension )
87import Text.Printf (printf )
98
109main :: IO ()
11- main = printExts . getPctExts =<< listDirectory " ."
10+ main = printExts . pctElems . filter ( /= " " ) . fmap takeExtension =<< listDirectory " ."
1211 where
1312 printExts :: [(Double , String )] -> IO ()
14- printExts = mapM_ . uncurry . printf $ " %.2f %% %s\n "
13+ printExts = mapM_ . uncurry . printf $ " %6.02f %% %s\n "
1514
16- -- | Get percentage of file extensions
17- getPctExts :: [FilePath ] -> [(Double , String )]
18- getPctExts = fmap takeExtension
19- <&> filter (/= " " )
20- <&> group . sort
21- <&> fmap (genericLength &&& head )
22- <&> id &&& genericLength
23- <&> \ (ys, len) -> first ((* 100 ) . (/ len)) <$> ys
15+ -- | Get percentage of each element in a list
16+ pctElems :: (Ord a , Fractional b ) => [a ] -> [(b , a )]
17+ pctElems xs = (calcPct . genericLength &&& head ) <$> group (sort xs)
18+ where
19+ len = genericLength xs
20+ calcPct = (* 100 ) . (/ len)
You can’t perform that action at this time.
0 commit comments