Files: 12f48f87e5e7e5e2d9d27836952b476f235fff89 / pull.js
1249 bytesRaw
1 | |
2 | |
3 | module.exports = function pull (a) { |
4 | var length = arguments.length |
5 | if (typeof a === 'function' && a.length === 1) { |
6 | var args = new Array(length) |
7 | for(var i = 0; i < length; i++) |
8 | args[i] = arguments[i] |
9 | return function (read) { |
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 | } |
29 | } |
30 | } |
31 | |
32 | var read = a |
33 | |
34 | if (read && typeof read.source === 'function') { |
35 | read = read.source |
36 | } |
37 | |
38 | for (var i = 1; i < length; i++) { |
39 | var s = arguments[i] |
40 | if (typeof s === 'function') { |
41 | read = s(read) |
42 | } else if (s && typeof s === 'object') { |
43 | s.sink(read) |
44 | read = s.source |
45 | } |
46 | } |
47 | |
48 | return read |
49 | } |
50 |
Built with git-ssb-web