forked from paldepind/flyd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flyd.js
801 lines (753 loc) · 22.4 KB
/
flyd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.flyd = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var curryN = require('ramda/src/curryN');
// Utility
function isFunction(obj) {
return !!(obj && obj.constructor && obj.call && obj.apply);
}
function trueFn() { return true; }
// Globals
var toUpdate = [];
var inStream;
var order = [];
var orderNextIdx = -1;
var flushing = false;
/** @namespace */
var flyd = {}
// /////////////////////////// API ///////////////////////////////// //
/**
* Creates a new stream
*
* __Signature__: `a -> Stream a`
*
* @name flyd.stream
* @param {*} initialValue - (Optional) the initial value of the stream
* @return {stream} the stream
*
* @example
* var n = flyd.stream(1); // Stream with initial value `1`
* var s = flyd.stream(); // Stream with no initial value
*/
flyd.stream = function(initialValue) {
var endStream = createDependentStream([], trueFn);
var s = createStream();
s.end = endStream;
s.fnArgs = [];
endStream.listeners.push(s);
if (arguments.length > 0) s(initialValue);
return s;
}
/**
* Create a new dependent stream
*
* __Signature__: `(...Stream * -> Stream b -> b) -> [Stream *] -> Stream b`
*
* @name flyd.combine
* @param {Function} fn - the function used to combine the streams
* @param {Array<stream>} dependencies - the streams that this one depends on
* @return {stream} the dependent stream
*
* @example
* var n1 = flyd.stream(0);
* var n2 = flyd.stream(0);
* var max = flyd.combine(function(n1, n2, self, changed) {
* return n1() > n2() ? n1() : n2();
* }, [n1, n2]);
*/
flyd.combine = curryN(2, combine);
function combine(fn, streams) {
var i, s, deps, depEndStreams;
var endStream = createDependentStream([], trueFn);
deps = []; depEndStreams = [];
for (i = 0; i < streams.length; ++i) {
if (streams[i] !== undefined) {
deps.push(streams[i]);
if (streams[i].end !== undefined) depEndStreams.push(streams[i].end);
}
}
s = createDependentStream(deps, fn);
s.depsChanged = [];
s.fnArgs = s.deps.concat([s, s.depsChanged]);
s.end = endStream;
endStream.listeners.push(s);
addListeners(depEndStreams, endStream);
endStream.deps = depEndStreams;
updateStream(s);
return s;
}
/**
* Returns `true` if the supplied argument is a Flyd stream and `false` otherwise.
*
* __Signature__: `* -> Boolean`
*
* @name flyd.isStream
* @param {*} value - the value to test
* @return {Boolean} `true` if is a Flyd streamn, `false` otherwise
*
* @example
* var s = flyd.stream(1);
* var n = 1;
* flyd.isStream(s); //=> true
* flyd.isStream(n); //=> false
*/
flyd.isStream = function(stream) {
return isFunction(stream) && 'hasVal' in stream;
}
/**
* Invokes the body (the function to calculate the value) of a dependent stream
*
* By default the body of a dependent stream is only called when all the streams
* upon which it depends has a value. `immediate` can circumvent this behaviour.
* It immediately invokes the body of a dependent stream.
*
* __Signature__: `Stream a -> Stream a`
*
* @name flyd.immediate
* @param {stream} stream - the dependent stream
* @return {stream} the same stream
*
* @example
* var s = flyd.stream();
* var hasItems = flyd.immediate(flyd.combine(function(s) {
* return s() !== undefined && s().length > 0;
* }, [s]);
* console.log(hasItems()); // logs `false`. Had `immediate` not been
* // used `hasItems()` would've returned `undefined`
* s([1]);
* console.log(hasItems()); // logs `true`.
* s([]);
* console.log(hasItems()); // logs `false`.
*/
flyd.immediate = function(s) {
if (s.depsMet === false) {
s.depsMet = true;
updateStream(s);
}
return s;
}
/**
* Changes which `endsStream` should trigger the ending of `s`.
*
* __Signature__: `Stream a -> Stream b -> Stream b`
*
* @name flyd.endsOn
* @param {stream} endStream - the stream to trigger the ending
* @param {stream} stream - the stream to be ended by the endStream
* @param {stream} the stream modified to be ended by endStream
*
* @example
* var n = flyd.stream(1);
* var killer = flyd.stream();
* // `double` ends when `n` ends or when `killer` emits any value
* var double = flyd.endsOn(flyd.merge(n.end, killer), flyd.combine(function(n) {
* return 2 * n();
* }, [n]);
*/
flyd.endsOn = function(endS, s) {
detachDeps(s.end);
endS.listeners.push(s.end);
s.end.deps.push(endS);
return s;
}
/**
* Map a stream
*
* Returns a new stream consisting of every value from `s` passed through
* `fn`. I.e. `map` creates a new stream that listens to `s` and
* applies `fn` to every new value.
* __Signature__: `(a -> result) -> Stream a -> Stream result`
*
* @name flyd.map
* @param {Function} fn - the function that produces the elements of the new stream
* @param {stream} stream - the stream to map
* @return {stream} a new stream with the mapped values
*
* @example
* var numbers = flyd.stream(0);
* var squaredNumbers = flyd.map(function(n) { return n*n; }, numbers);
*/
// Library functions use self callback to accept (null, undefined) update triggers.
flyd.map = curryN(2, function(f, s) {
return combine(function(s, self) { self(f(s.val)); }, [s]);
})
/**
* Listen to stream events
*
* Similair to `map` except that the returned stream is empty. Use `on` for doing
* side effects in reaction to stream changes. Use the returned stream only if you
* need to manually end it.
*
* __Signature__: `(a -> result) -> Stream a -> Stream undefined`
*
* @name flyd.on
* @param {Function} cb - the callback
* @param {stream} stream - the stream
* @return {stream} an empty stream (can be ended)
*/
flyd.on = curryN(2, function(f, s) {
return combine(function(s) { f(s.val); }, [s]);
})
/**
* Creates a new stream with the results of calling the function on every incoming
* stream with and accumulator and the incoming value.
*
* __Signature__: `(a -> b -> a) -> a -> Stream b -> Stream a`
*
* @name flyd.scan
* @param {Function} fn - the function to call
* @param {*} val - the initial value of the accumulator
* @param {stream} stream - the stream source
* @return {stream} the new stream
*
* @example
* var numbers = flyd.stream();
* var sum = flyd.scan(function(sum, n) { return sum+n; }, 0, numbers);
* numbers(2)(3)(5);
* sum(); // 10
*/
flyd.scan = curryN(3, function(f, acc, s) {
var ns = combine(function(s, self) {
self(acc = f(acc, s.val));
}, [s]);
if (!ns.hasVal) ns(acc);
return ns;
});
/**
* Creates a new stream down which all values from both `stream1` and `stream2`
* will be sent.
*
* __Signature__: `Stream a -> Stream a -> Stream a`
*
* @name flyd.merge
* @param {stream} source1 - one stream to be merged
* @param {stream} source2 - the other stream to be merged
* @return {stream} a stream with the values from both sources
*
* @example
* var btn1Clicks = flyd.stream();
* button1Elm.addEventListener(btn1Clicks);
* var btn2Clicks = flyd.stream();
* button2Elm.addEventListener(btn2Clicks);
* var allClicks = flyd.merge(btn1Clicks, btn2Clicks);
*/
flyd.merge = curryN(2, function(s1, s2) {
var s = flyd.immediate(combine(function(s1, s2, self, changed) {
if (changed[0]) {
self(changed[0]());
} else if (s1.hasVal) {
self(s1.val);
} else if (s2.hasVal) {
self(s2.val);
}
}, [s1, s2]));
flyd.endsOn(combine(function() {
return true;
}, [s1.end, s2.end]), s);
return s;
});
/**
* Creates a new stream resulting from applying `transducer` to `stream`.
*
* __Signature__: `Transducer -> Stream a -> Stream b`
*
* @name flyd.transduce
* @param {Transducer} xform - the transducer transformation
* @param {stream} source - the stream source
* @return {stream} the new stream
*
* @example
* var t = require('transducers.js');
*
* var results = [];
* var s1 = flyd.stream();
* var tx = t.compose(t.map(function(x) { return x * 2; }), t.dedupe());
* var s2 = flyd.transduce(tx, s1);
* flyd.combine(function(s2) { results.push(s2()); }, [s2]);
* s1(1)(1)(2)(3)(3)(3)(4);
* results; // => [2, 4, 6, 8]
*/
flyd.transduce = curryN(2, function(xform, source) {
xform = xform(new StreamTransformer());
return combine(function(source, self) {
var res = xform['@@transducer/step'](undefined, source.val);
if (res && res['@@transducer/reduced'] === true) {
self.end(true);
return res['@@transducer/value'];
} else {
return res;
}
}, [source]);
});
/**
* Returns `fn` curried to `n`. Use this function to curry functions exposed by
* modules for Flyd.
*
* @name flyd.curryN
* @function
* @param {Integer} arity - the function arity
* @param {Function} fn - the function to curry
* @return {Function} the curried function
*
* @example
* function add(x, y) { return x + y; };
* var a = flyd.curryN(2, add);
* a(2)(4) // => 6
*/
flyd.curryN = curryN
/**
* Returns a new stream identical to the original except every
* value will be passed through `f`.
*
* _Note:_ This function is included in order to support the fantasy land
* specification.
*
* __Signature__: Called bound to `Stream a`: `(a -> b) -> Stream b`
*
* @name stream.map
* @param {Function} function - the function to apply
* @return {stream} a new stream with the values mapped
*
* @example
* var numbers = flyd.stream(0);
* var squaredNumbers = numbers.map(function(n) { return n*n; });
*/
function boundMap(f) { return flyd.map(f, this); }
/**
* Returns a new stream which is the result of applying the
* functions from `this` stream to the values in `stream` parameter.
*
* `this` stream must be a stream of functions.
*
* _Note:_ This function is included in order to support the fantasy land
* specification.
*
* __Signature__: Called bound to `Stream (a -> b)`: `a -> Stream b`
*
* @name stream.ap
* @param {stream} stream - the values stream
* @return {stream} a new stram with the functions applied to values
*
* @example
* var add = flyd.curryN(2, function(x, y) { return x + y; });
* var numbers1 = flyd.stream();
* var numbers2 = flyd.stream();
* var addToNumbers1 = flyd.map(add, numbers1);
* var added = addToNumbers1.ap(numbers2);
*/
function ap(s2) {
var s1 = this;
return combine(function(s1, s2, self) { self(s1.val(s2.val)); }, [s1, s2]);
}
/**
* Get a human readable view of a stream
* @name stream.toString
* @return {String} the stream string representation
*/
function streamToString() {
return 'stream(' + this.val + ')';
}
/**
* @name stream.end
* @memberof stream
* A stream that emits `true` when the stream ends. If `true` is pushed down the
* stream the parent stream ends.
*/
/**
* @name stream.of
* @function
* @memberof stream
* Returns a new stream with `value` as its initial value. It is identical to
* calling `flyd.stream` with one argument.
*
* __Signature__: Called bound to `Stream (a)`: `b -> Stream b`
*
* @param {*} value - the initial value
* @return {stream} the new stream
*
* @example
* var n = flyd.stream(1);
* var m = n.of(1);
*/
// /////////////////////////// PRIVATE ///////////////////////////////// //
/**
* @private
* Create a stream with no dependencies and no value
* @return {Function} a flyd stream
*/
function createStream() {
function s(n) {
if (arguments.length === 0) return s.val
updateStreamValue(s, n)
return s
}
s.hasVal = false;
s.val = undefined;
s.vals = [];
s.listeners = [];
s.queued = false;
s.end = undefined;
s.map = boundMap;
s.ap = ap;
s.of = flyd.stream;
s.toString = streamToString;
return s;
}
/**
* @private
* Create a dependent stream
* @param {Array<stream>} dependencies - an array of the streams
* @param {Function} fn - the function used to calculate the new stream value
* from the dependencies
* @return {stream} the created stream
*/
function createDependentStream(deps, fn) {
var s = createStream();
s.fn = fn;
s.deps = deps;
s.depsMet = false;
s.depsChanged = deps.length > 0 ? [] : undefined;
s.shouldUpdate = false;
addListeners(deps, s);
return s;
}
/**
* @private
* Check if all the dependencies have values
* @param {stream} stream - the stream to check depencencies from
* @return {Boolean} `true` if all dependencies have vales, `false` otherwise
*/
function initialDepsNotMet(stream) {
stream.depsMet = stream.deps.every(function(s) {
return s.hasVal;
});
return !stream.depsMet;
}
/**
* @private
* Update a dependent stream using its dependencies in an atomic way
* @param {stream} stream - the stream to update
*/
function updateStream(s) {
if ((s.depsMet !== true && initialDepsNotMet(s)) ||
(s.end !== undefined && s.end.val === true)) return;
if (inStream !== undefined) {
toUpdate.push(s);
return;
}
inStream = s;
if (s.depsChanged) s.fnArgs[s.fnArgs.length - 1] = s.depsChanged;
var returnVal = s.fn.apply(s.fn, s.fnArgs);
if (returnVal !== undefined) {
s(returnVal);
}
inStream = undefined;
if (s.depsChanged !== undefined) s.depsChanged = [];
s.shouldUpdate = false;
if (flushing === false) flushUpdate();
}
/**
* @private
* Update the dependencies of a stream
* @param {stream} stream
*/
function updateDeps(s) {
var i, o, list
var listeners = s.listeners;
for (i = 0; i < listeners.length; ++i) {
list = listeners[i];
if (list.end === s) {
endStream(list);
} else {
if (list.depsChanged !== undefined) list.depsChanged.push(s);
list.shouldUpdate = true;
findDeps(list);
}
}
for (; orderNextIdx >= 0; --orderNextIdx) {
o = order[orderNextIdx];
if (o.shouldUpdate === true) updateStream(o);
o.queued = false;
}
}
/**
* @private
* Add stream dependencies to the global `order` queue.
* @param {stream} stream
* @see updateDeps
*/
function findDeps(s) {
var i
var listeners = s.listeners;
if (s.queued === false) {
s.queued = true;
for (i = 0; i < listeners.length; ++i) {
findDeps(listeners[i]);
}
order[++orderNextIdx] = s;
}
}
/**
* @private
*/
function flushUpdate() {
flushing = true;
while (toUpdate.length > 0) {
var s = toUpdate.shift();
if (s.vals.length > 0) s.val = s.vals.shift();
updateDeps(s);
}
flushing = false;
}
/**
* @private
* Push down a value into a stream
* @param {stream} stream
* @param {*} value
*/
function updateStreamValue(s, n) {
if (n !== undefined && n !== null && isFunction(n.then)) {
n.then(s);
return;
}
s.val = n;
s.hasVal = true;
if (inStream === undefined) {
flushing = true;
updateDeps(s);
if (toUpdate.length > 0) flushUpdate(); else flushing = false;
} else if (inStream === s) {
markListeners(s, s.listeners);
} else {
s.vals.push(n);
toUpdate.push(s);
}
}
/**
* @private
*/
function markListeners(s, lists) {
var i, list;
for (i = 0; i < lists.length; ++i) {
list = lists[i];
if (list.end !== s) {
if (list.depsChanged !== undefined) {
list.depsChanged.push(s);
}
list.shouldUpdate = true;
} else {
endStream(list);
}
}
}
/**
* @private
* Add dependencies to a stream
* @param {Array<stream>} dependencies
* @param {stream} stream
*/
function addListeners(deps, s) {
for (var i = 0; i < deps.length; ++i) {
deps[i].listeners.push(s);
}
}
/**
* @private
* Removes an stream from a dependency array
* @param {stream} stream
* @param {Array<stream>} dependencies
*/
function removeListener(s, listeners) {
var idx = listeners.indexOf(s);
listeners[idx] = listeners[listeners.length - 1];
listeners.length--;
}
/**
* @private
* Detach a stream from its dependencies
* @param {stream} stream
*/
function detachDeps(s) {
for (var i = 0; i < s.deps.length; ++i) {
removeListener(s, s.deps[i].listeners);
}
s.deps.length = 0;
}
/**
* @private
* Ends a stream
*/
function endStream(s) {
if (s.deps !== undefined) detachDeps(s);
if (s.end !== undefined) detachDeps(s.end);
}
/**
* @private
* transducer stream transformer
*/
function StreamTransformer() { }
StreamTransformer.prototype['@@transducer/init'] = function() { };
StreamTransformer.prototype['@@transducer/result'] = function() { };
StreamTransformer.prototype['@@transducer/step'] = function(s, v) { return v; };
module.exports = flyd;
},{"ramda/src/curryN":2}],2:[function(require,module,exports){
var _arity = require('./internal/_arity');
var _curry1 = require('./internal/_curry1');
var _curry2 = require('./internal/_curry2');
var _curryN = require('./internal/_curryN');
/**
* Returns a curried equivalent of the provided function, with the
* specified arity. The curried function has two unusual capabilities.
* First, its arguments needn't be provided one at a time. If `g` is
* `R.curryN(3, f)`, the following are equivalent:
*
* - `g(1)(2)(3)`
* - `g(1)(2, 3)`
* - `g(1, 2)(3)`
* - `g(1, 2, 3)`
*
* Secondly, the special placeholder value `R.__` may be used to specify
* "gaps", allowing partial application of any combination of arguments,
* regardless of their positions. If `g` is as above and `_` is `R.__`,
* the following are equivalent:
*
* - `g(1, 2, 3)`
* - `g(_, 2, 3)(1)`
* - `g(_, _, 3)(1)(2)`
* - `g(_, _, 3)(1, 2)`
* - `g(_, 2)(1)(3)`
* - `g(_, 2)(1, 3)`
* - `g(_, 2)(_, 3)(1)`
*
* @func
* @memberOf R
* @category Function
* @sig Number -> (* -> a) -> (* -> a)
* @param {Number} length The arity for the returned function.
* @param {Function} fn The function to curry.
* @return {Function} A new, curried function.
* @see R.curry
* @example
*
* var addFourNumbers = function() {
* return R.sum([].slice.call(arguments, 0, 4));
* };
*
* var curriedAddFourNumbers = R.curryN(4, addFourNumbers);
* var f = curriedAddFourNumbers(1, 2);
* var g = f(3);
* g(4); //=> 10
*/
module.exports = _curry2(function curryN(length, fn) {
if (length === 1) {
return _curry1(fn);
}
return _arity(length, _curryN(length, [], fn));
});
},{"./internal/_arity":3,"./internal/_curry1":4,"./internal/_curry2":5,"./internal/_curryN":6}],3:[function(require,module,exports){
module.exports = function _arity(n, fn) {
// jshint unused:vars
switch (n) {
case 0: return function() { return fn.apply(this, arguments); };
case 1: return function(a0) { return fn.apply(this, arguments); };
case 2: return function(a0, a1) { return fn.apply(this, arguments); };
case 3: return function(a0, a1, a2) { return fn.apply(this, arguments); };
case 4: return function(a0, a1, a2, a3) { return fn.apply(this, arguments); };
case 5: return function(a0, a1, a2, a3, a4) { return fn.apply(this, arguments); };
case 6: return function(a0, a1, a2, a3, a4, a5) { return fn.apply(this, arguments); };
case 7: return function(a0, a1, a2, a3, a4, a5, a6) { return fn.apply(this, arguments); };
case 8: return function(a0, a1, a2, a3, a4, a5, a6, a7) { return fn.apply(this, arguments); };
case 9: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8) { return fn.apply(this, arguments); };
case 10: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { return fn.apply(this, arguments); };
default: throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
}
};
},{}],4:[function(require,module,exports){
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0) {
return f1;
} else if (a != null && a['@@functional/placeholder'] === true) {
return f1;
} else {
return fn.apply(this, arguments);
}
};
};
},{}],5:[function(require,module,exports){
var _curry1 = require('./_curry1');
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry2(fn) {
return function f2(a, b) {
var n = arguments.length;
if (n === 0) {
return f2;
} else if (n === 1 && a != null && a['@@functional/placeholder'] === true) {
return f2;
} else if (n === 1) {
return _curry1(function(b) { return fn(a, b); });
} else if (n === 2 && a != null && a['@@functional/placeholder'] === true &&
b != null && b['@@functional/placeholder'] === true) {
return f2;
} else if (n === 2 && a != null && a['@@functional/placeholder'] === true) {
return _curry1(function(a) { return fn(a, b); });
} else if (n === 2 && b != null && b['@@functional/placeholder'] === true) {
return _curry1(function(b) { return fn(a, b); });
} else {
return fn(a, b);
}
};
};
},{"./_curry1":4}],6:[function(require,module,exports){
var _arity = require('./_arity');
/**
* Internal curryN function.
*
* @private
* @category Function
* @param {Number} length The arity of the curried function.
* @return {array} An array of arguments received thus far.
* @param {Function} fn The function to curry.
*/
module.exports = function _curryN(length, received, fn) {
return function() {
var combined = [];
var argsIdx = 0;
var left = length;
var combinedIdx = 0;
while (combinedIdx < received.length || argsIdx < arguments.length) {
var result;
if (combinedIdx < received.length &&
(received[combinedIdx] == null ||
received[combinedIdx]['@@functional/placeholder'] !== true ||
argsIdx >= arguments.length)) {
result = received[combinedIdx];
} else {
result = arguments[argsIdx];
argsIdx += 1;
}
combined[combinedIdx] = result;
if (result == null || result['@@functional/placeholder'] !== true) {
left -= 1;
}
combinedIdx += 1;
}
return left <= 0 ? fn.apply(this, combined) : _arity(left, _curryN(length, combined, fn));
};
};
},{"./_arity":3}]},{},[1])(1)
});