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 ()

 convert :: Monad m => (a -> b) -> Pipe a b m ()
 convert f = do
 	mx <- await
 	case mx of
 		Just x -> yield (f x) >> convert f
 		_ -> 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 [faq] 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.*), lifted-base (==0.2.*), monad-control (==0.3.*), monads-tf (==0.1.*) [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/forest.git
this: git clone git://github.com/YoshikuniJujo/forest.git(tag simple-pipe-0.0.0.4)
Uploaded by YoshikuniJujo at Sat Jul 19 22:20:52 UTC 2014
Distributions NixOS:0.0.0.29
Downloads 12409 total (594 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Successful builds reported [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees