simple-pipe: simple pipeline library like conduit

[ bsd3, data, library ] [ Propose Tags ]

examples/upperFile.hs

  • read file (sample.txt)

  • take 3 lines

  • to upper all lines

  • write to stdout

extensions

  • PackageImports

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

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 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.6 && <5), bytestring (>=0.10 && <0.11), lifted-base (>=0.2 && <0.3), monad-control (>=1.0 && <1.1), monads-tf (>=0.1 && <0.2), stm (>=2.4 && <2.5), transformers-base (>=0.4 && <0.5) [details]
License BSD-3-Clause
Author Yoshikuni Jujo <PAF01143@nifty.ne.jp>
Maintainer Yoshikuni Jujo <PAF01143@nifty.ne.jp>
Revised Revision 1 made by HerbertValerioRiedel at 2018-10-04T08:58:51Z
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 2015-09-29T03:12:41Z
Distributions NixOS:0.0.0.29
Downloads 19931 total (136 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-09-30 [all 1 reports]