Skip to content

Instantly share code, notes, and snippets.

@r-wheeler
Created March 22, 2016 21:09
Show Gist options
  • Save r-wheeler/dec06af5d64c1ab04615 to your computer and use it in GitHub Desktop.
Save r-wheeler/dec06af5d64c1ab04615 to your computer and use it in GitHub Desktop.
import Control.Applicative
import Data.Traversable
import Lens.Family (to)
import Control.Foldl (Fold)
import Data.Text (Text)
import Prelude hiding (lines, words)
import qualified Control.Foldl as Fold
import qualified Control.Foldl.Text as Fold.Text
import qualified Data.Text as Text
import qualified Turtle
lines, words, chars :: Fold Text Int
lines = Fold.length
words = Fold.handles (to Text.words . traverse) Fold.length
chars = Fold.Text.length + lines
data WcValue = WcValue
{ lineCount :: Int
, wordCount :: Int
, byteCount :: Int
} deriving (Show)
total :: Fold Text WcValue
total = WcValue <$> lines <*> words <*> chars
main :: IO ()
main = do
x <- Turtle.fold Turtle.stdin total
print x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment