Skip to content

Commit 35fa90a

Browse files
committed
Merge #9 - Add examples
Fix #4
2 parents 4761a15 + fd92440 commit 35fa90a

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ install:
1313
- npm install
1414
script:
1515
- npm run build
16+
- npm run example

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@
77

88
* @scott-christopher for porting `ListT` and writing the `MonadError`,
99
`MonadWriter`, `MonadPlus` and `Alternative` instances for `Proxy`!
10+
11+
## How-To
12+
13+
For an in-depth overview of pipes follow the tutorial that comes with the
14+
Haskell pipes library. The concepts apply one to one to purescript-pipes.
15+
16+
Also have a look at the examples that come with purescript-pipes. You can run
17+
them using `npm run example`.

bower.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@
2323
"purescript-tailrec": "^3.0.0",
2424
"purescript-mmorph": "^3.0.0",
2525
"purescript-prelude": "^3.0.0"
26+
},
27+
"devDependencies": {
28+
"purescript-console": "^3.0.0",
29+
"purescript-random": "^3.0.0"
2630
}
2731
}

examples/Example.purs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Example where
2+
3+
import Prelude
4+
import Control.Monad.Eff (Eff)
5+
import Control.Monad.Eff.Class (liftEff)
6+
import Control.Monad.Eff.Console (CONSOLE, log)
7+
import Control.Monad.Eff.Random (randomInt, RANDOM)
8+
9+
import Pipes (yield, for)
10+
import Pipes.Core (runEffect, Producer_)
11+
12+
pipedRandomInt
13+
:: eff
14+
. Int
15+
-> Int
16+
-> Producer_ String (Eff (random :: RANDOM | eff)) Int
17+
pipedRandomInt x y = do
18+
yield $ "Generating an Int between " <> show x <> " and " <> show y <> "..."
19+
r <- liftEff $ randomInt x y
20+
yield $ "Generated " <> show r
21+
pure r
22+
23+
main :: Eff (console :: CONSOLE, random :: RANDOM) Unit
24+
main =
25+
let go = pipedRandomInt 1 10
26+
in do
27+
r <- runEffect $ for go (liftEff <<< log <<< ("Log: " <> _))
28+
log $ "Result: " <> show r

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"private": true,
33
"scripts": {
44
"postinstall": "bower install",
5-
"build": "pulp build && rimraf docs && pulp docs"
5+
"build": "pulp build && rimraf docs && pulp docs",
6+
"example": "pulp run -I examples -I src -I bower_components -m example"
67
},
78
"devDependencies": {
89
"bower": "^1.7.9",

0 commit comments

Comments
 (0)