simple-pipe: simple pipeline library like conduit

[ bsd3, data, library ] [ Propose Tags ]

examples/upperFile.hs

extensions

 import Data.Pipe
 import Data.Char
 import System.IO
 import "monads-tf" Control.Monad.Trans

 main :: IO ()
 main = do
 	_ <- runPipe $ readFileP "sample.txt"
		=$= takeP 3
		=$= convert (map toUpper)
		=$= writeString
 	return ()

 readFileP :: FilePath -> Pipe () String IO ()
 readFileP fp = bracket (openFile fp ReadMode) hClose hRead

 hRead :: Handle -> Pipe () String IO ()
 hRead h = do
 	eof <- lift $ hIsEOF h
 	if eof then return () else do
 		l <- lift $ hGetLine h
 		yield l
 		hRead h

 writeString :: Pipe String () IO ()
 writeString = do
 	ms <- await
 	case ms of
 		Just s -> lift (putStrLn s) >> writeString
 		_ -> return ()

 takeP :: Monad m => Int -> Pipe a a m ()
 takeP 0 = return ()
 takeP n = do
	mx <- await
	case mx of
		Just x -> yield x >> takeP (n - 1)
		_ -> return ()
Versions 0.0.0.0, 0.0.0.1, 0.0.0.2, 0.0.0.3, 0.0.0.4, 0.0.0.5, 0.0.0.6, 0.0.0.7, 0.0.0.8, 0.0.0.9, 0.0.0.10, 0.0.0.11, 0.0.0.12, 0.0.0.13, 0.0.0.14, 0.0.0.15, 0.0.0.16, 0.0.0.17, 0.0.0.18, 0.0.0.19, 0.0.0.20, 0.0.0.21, 0.0.0.22, 0.0.0.23, 0.0.0.24, 0.0.0.25, 0.0.0.26, 0.0.0.27, 0.0.0.28, 0.0.0.29
Dependencies base (==4.*), bytestring (==0.10.*), lifted-base (==0.2.*), monad-control (==1.0.*), monads-tf (==0.1.*), stm (==2.4.*), transformers-base (==0.4.*) [details]
License BSD-3-Clause
Author Yoshikuni Jujo <PAF01143@nifty.ne.jp>
Maintainer Yoshikuni Jujo <PAF01143@nifty.ne.jp>
Category Data
Home page https://github.com/YoshikuniJujo/simple-pipe/wiki
Source repo head: git clone git://github.com/YoshikuniJujo/simple-pipe.git
this: git clone git://github.com/YoshikuniJujo/simple-pipe.git(tag simple-pipe-0.0.0.29)
Uploaded by YoshikuniJujo at Tue Sep 29 03:12:41 UTC 2015
Distributions NixOS:0.0.0.29
Downloads 8919 total (381 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-09-30 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees