UNPKG

1.19 kBJavaScriptView Raw
1var pull = require('../')
2var test = require('tape')
3//test through streams compose on pipe!
4
5test('join through streams with pipe', function (t) {
6
7 var map = pull.map
8
9 var pipeline =
10 pull(
11 map(function (d) {
12 //make exciting!
13 return d + '!'
14 }),
15 map(function (d) {
16 //make loud
17 return d.toUpperCase()
18 }),
19 map(function (d) {
20 //add sparkles
21 return '*** ' + d + ' ***'
22 })
23 )
24 //the pipe line does not have a source stream.
25 //so it should be a reader (function that accepts
26 //a read function)
27
28 t.equal('function', typeof pipeline)
29 t.equal(1, pipeline.length)
30
31 //if we pipe a read function to the pipeline,
32 //the pipeline will become readable!
33
34 var read =
35 pull(
36 pull.values(['billy', 'joe', 'zeke']),
37 pipeline
38 )
39
40 t.equal('function', typeof read)
41 //we will know it's a read function,
42 //because read takes two args.
43 t.equal(2, read.length)
44
45 pull(
46 read,
47 pull.collect(function (err, array) {
48 console.log(array)
49 t.deepEqual(
50 array,
51 [ '*** BILLY! ***', '*** JOE! ***', '*** ZEKE! ***' ]
52 )
53 t.end()
54 })
55 )
56
57})