Skip to content

Instantly share code, notes, and snippets.

@cblp
Created May 21, 2019 15:36
Show Gist options
  • Save cblp/19f89e8238903d29b4a0d3d377649924 to your computer and use it in GitHub Desktop.
Save cblp/19f89e8238903d29b4a0d3d377649924 to your computer and use it in GitHub Desktop.
module CountLines where
import Prelude hiding (length, lines,
readFile)
import Control.Monad.Trans.Resource (runResourceT)
import Data.ByteString.Streaming.Char8 (lines, readFile, toLazy)
import Streaming (mapped)
import Streaming.Prelude (fst', length)
countLines :: FilePath -> IO Int
countLines =
runResourceT . fmap fst' . length . mapped toLazy . lines . readFile
countLinesInFiles :: [FilePath] -> IO Int
countLinesInFiles = fmap sum . traverse countLines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment