git ssb

2+

Dominic / pull-stream



Commit c94bab17e0c6d926909827c46b30a3411a9ada32

Merge branch 'patch-1' of https://github.com/isiahmeadows/pull-stream

Dominic Tarr committed on 8/31/2016, 4:15:29 AM
Parent: 2d4523dffda72662b6872ac393ee20e811eee7b1
Parent: 8c0347d8e7f88171cd4c45eec22b42c5c7332fac

Files changed

pull.jschanged
test/pull.jschanged
pull.jsView
@@ -6,10 +6,27 @@
66 var args = new Array(length)
77 for(var i = 0; i < length; i++)
88 args[i] = arguments[i]
99 return function (read) {
10- args.unshift(read)
11- return pull.apply(null, args)
10+ if (args == null) {
11+ throw new TypeError("partial sink should only be called once!")
12+ }
13+
14+ // Grab the reference after the check, because it's always an array now
15+ // (engines like that kind of consistency).
16+ var ref = args
17+ args = null
18+
19+ // Prioritize common case of small number of pulls.
20+ switch (length) {
21+ case 1: return pull(read, ref[0])
22+ case 2: return pull(read, ref[0], ref[1])
23+ case 3: return pull(read, ref[0], ref[1], ref[2])
24+ case 4: return pull(read, ref[0], ref[1], ref[2], ref[3])
25+ default:
26+ ref.unshift(read)
27+ return pull.apply(null, ref)
28+ }
1229 }
1330 }
1431
1532 var read = a
@@ -29,9 +46,4 @@
2946 }
3047
3148 return read
3249 }
33-
34-
35-
36-
37-
test/pull.jsView
@@ -3,10 +3,9 @@
33 function curry (fun) {
44 return function () {
55 var args = [].slice.call(arguments)
66 return function (read) {
7- args.unshift(read)
8- return fun.apply(null, args)
7+ return fun.apply(null, [read].concat(args))
98 }
109 }
1110 }
1211
@@ -94,4 +93,21 @@
9493 // })
9594 // )
9695 //
9796
97+tape("writable pull() should throw when called twice", function (t) {
98+ t.plan(2)
99+
100+ var stream = pull(
101+ map(function (e) { return e*e }),
102+ sum(function (err, value) {
103+ console.log(value)
104+ t.equal(value, 385)
105+ })
106+ )
107+
108+ stream(values([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
109+
110+ t.throws(function () {
111+ stream(values([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
112+ }, TypeError)
113+})

Built with git-ssb-web