underscore-transducer
Advanced tools
| "use strict"; | ||
| var seq = require('transduce-sequence'), | ||
| ip = require('iterator-protocol'), | ||
| undef; | ||
| module.exports = function(_r){ | ||
| // Returns a new collection of the empty value of the from collection | ||
| _r.sequence = sequence; | ||
| function sequence(xf, from){ | ||
| if(_r.as(xf)){ | ||
| xf = _r.transducer(xf); | ||
| } | ||
| return seq(xf, from); | ||
| } | ||
| // calls sequence with chained transformation and optional wrapped object | ||
| _r.prototype.sequence = function(from){ | ||
| if(from == undef){ | ||
| from = this._wrapped; | ||
| } | ||
| return sequence(this, from); | ||
| }; | ||
| _r.prototype[ip.symbol] = function(){ | ||
| return _r.iterator(this.sequence()); | ||
| }; | ||
| }; |
+10
-7
@@ -24,3 +24,3 @@ "use strict"; | ||
| iterator = _r.iterator = dispatcher(), | ||
| sequence = _r.sequence = dispatcher(), | ||
| toArray = _r.toArray = dispatcher(), | ||
| iteratee = _r.iteratee = dispatcher(); | ||
@@ -176,12 +176,15 @@ _r.resolveSingleValue = resolveSingleValue; | ||
| // Returns a new collection of the empty value of the from collection | ||
| sequence.register(function(xf, from){ | ||
| return into(empty(from), xf, from); | ||
| toArray.register(function(xf, from){ | ||
| if(as(xf)){ | ||
| xf = transducer(xf); | ||
| } | ||
| return tr.toArray(xf, from); | ||
| }); | ||
| // calls sequence with chained transformation and optional wrapped object | ||
| _r.prototype.sequence = function(from){ | ||
| if(from == undef){ | ||
| // calls toArray with chained transformation and optional wrapped object | ||
| _r.prototype.toArray = function(from){ | ||
| if(from === undef){ | ||
| from = this._wrapped; | ||
| } | ||
| return sequence(this, from); | ||
| return toArray(this, from); | ||
| }; | ||
@@ -188,0 +191,0 @@ |
+8
-5
| { | ||
| "name": "underscore-transducer", | ||
| "version": "0.3.2", | ||
| "version": "0.4.0", | ||
| "description": "Transducers for Underscore", | ||
@@ -27,3 +27,3 @@ "main": "underscore-transducer.js", | ||
| "dependencies": { | ||
| "transduce": "~0.2.0", | ||
| "transduce": "~0.3.0", | ||
| "transduce-array": "~0.1.0", | ||
@@ -34,2 +34,4 @@ "transduce-math": "~0.1.0", | ||
| "transduce-unique": "~0.1.0", | ||
| "transduce-sequence": "~0.1.0", | ||
| "iterator-protocol": "~0.1.0", | ||
| "redispatch": "0.0.2" | ||
@@ -39,8 +41,9 @@ }, | ||
| "tape": "~3.0.0", | ||
| "uglify-js": "~2.3.6", | ||
| "browserify": "~6.1.0", | ||
| "uglify-js": "~2.4.16", | ||
| "tap-bail": "0.0.0", | ||
| "lodash-node": "~2.4.1", | ||
| "bundle-collapser": "~1.1.0" | ||
| "bundle-collapser": "~1.1.1", | ||
| "tap": "~0.4.13", | ||
| "browserify": "~8.0.3" | ||
| } | ||
| } |
+5
-12
@@ -63,3 +63,3 @@ # Underscore Transducer | ||
| result = _r.into([], trans, [1,2,3,4, 5]); | ||
| result = _r().filter(isEven).map(inc).sequence([1,2,3,4,5]); | ||
| result = _r().filter(isEven).map(inc).toArray([1,2,3,4,5]); | ||
| // [ 3, 5 ] | ||
@@ -75,3 +75,3 @@ ``` | ||
| .map(function(num) { return num * num }) | ||
| .sequence([1,2,3,200]); | ||
| .toArray([1,2,3,200]); | ||
| // 2 [] | ||
@@ -85,3 +85,3 @@ // 200 [4] | ||
| ```javascript | ||
| result = _r().invoke('sort').sequence([[5, 1, 7], [3, 2, 1]]); | ||
| result = _r().invoke('sort').toArray([[5, 1, 7], [3, 2, 1]]); | ||
| // [ [ 1, 5, 7 ], [ 1, 2, 3 ] ] | ||
@@ -314,9 +314,7 @@ | ||
| ##### sequence(xf?, from?) | ||
| Returns a new collection of the same type as `from` after running it through the optional transformation. | ||
| ##### toArray(xf?, from?) | ||
| Returns a new orray by iterating through`from` after running it through the optional transformation. | ||
| If called on a chained transformation, uses the composed transformation as `xf`. If `from` is not defined, uses the wrapped source when creating the chain, `_r(wrapped)`. | ||
| Equivalent to calling `into` with `to` created with `_r.empty(from)`. | ||
| ##### into(to?, xf?, from?) | ||
@@ -561,7 +559,2 @@ Returns a new collection appending all items into the empty collection `to` by passing all items from source collection `from` through the transformation `xf`. | ||
| ##### toArray(xf?, coll) | ||
| Transduce a collection into an array with an optional transformation. | ||
| From [transduce-toarray](https://github.com/transduce/transduce-toarray) | ||
| ##### compose() | ||
@@ -568,0 +561,0 @@ Simple function composition of arguments. Useful for composing (combining) transducers. |
@@ -5,2 +5,3 @@ module.exports = require('./lib/load')([ | ||
| require('./lib/transduce'), | ||
| require('./lib/sequence'), | ||
| require('./lib/array'), | ||
@@ -7,0 +8,0 @@ require('./lib/unique'), |
50478
1.13%20
5.26%841
3.44%9
28.57%7
16.67%618
-1.12%+ Added
+ Added
+ Added
- Removed
Updated