Created
March 22, 2016 21:09
-
-
Save r-wheeler/dec06af5d64c1ab04615 to your computer and use it in GitHub Desktop.
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
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