underscore-transducer
Advanced tools
+1
-1
| { | ||
| "name": "underscore-transducer", | ||
| "main": "build/underscore-transducer.min.js", | ||
| "version": "0.3.1", | ||
| "version": "0.3.2", | ||
| "homepage": "https://github.com/kevinbeaty/underscore-transducer", | ||
@@ -6,0 +6,0 @@ "authors": [ |
+1
-1
@@ -38,3 +38,3 @@ "use strict"; | ||
| _r.VERSION = '0.3.1'; | ||
| _r.VERSION = '0.3.2'; | ||
@@ -41,0 +41,0 @@ // Export for browser or Common-JS |
+19
-0
@@ -37,2 +37,21 @@ "use strict"; | ||
| _r.compose = tr.compose; | ||
| _r.isIterable = tr.isIterable; | ||
| _r.isIterator = tr.isIterator; | ||
| _r.iterable = tr.iterable; | ||
| _r.isTransformer = tr.isTransformer; | ||
| _r.transformer = tr.transformer; | ||
| _r.protocols = tr.protocols; | ||
| _r.isFunction = tr.isFunction; | ||
| _r.isArray = tr.isArray; | ||
| _r.isString = tr.isString; | ||
| _r.isRegExp = tr.isRegExp; | ||
| _r.isNumber = tr.isNumber; | ||
| _r.isUndefined = tr.isUndefined; | ||
| _r.arrayPush = tr.arrayPush; | ||
| _r.objectMerge = tr.objectMerge; | ||
| _r.stringAppend = tr.stringAppend; | ||
| _r.identity = tr.identity; | ||
| // Dispatchers | ||
@@ -39,0 +58,0 @@ // ----------- |
+1
-1
| { | ||
| "name": "underscore-transducer", | ||
| "version": "0.3.1", | ||
| "version": "0.3.2", | ||
| "description": "Transducers for Underscore", | ||
@@ -5,0 +5,0 @@ "main": "underscore-transducer.js", |
+60
-41
@@ -9,3 +9,3 @@ # Underscore Transducer | ||
| Too much API for you? Just grab what you need from the [transduce][14] libraries, which underscore-transudcer is based. Want more? Check out [underarm][18] for asynchronous (reactive) extensions. | ||
| Too much API for you? Just grab what you need from the [transduce][14] libraries, which underscore-transducer is based. Want more? Check out [underarm][18] for asynchronous (reactive) extensions. | ||
@@ -33,3 +33,3 @@ ## Install | ||
| First some helper functions and imports. You can optionally mix in `_r` into the underscore object | ||
| First some helper functions and imports. | ||
@@ -39,3 +39,2 @@ ```javascript | ||
| var _r = require('underscore-transducer'); | ||
| var _ = require('underscore'); | ||
@@ -61,3 +60,3 @@ function isEven(x){ | ||
| ```javascript | ||
| result = _r.into([], _.compose(_r.filter(isEven), _r.map(inc)), [1,2,3,4]); | ||
| result = _r.into([], _r.compose(_r.filter(isEven), _r.map(inc)), [1,2,3,4]); | ||
| // [ 3, 5 ] | ||
@@ -103,7 +102,3 @@ | ||
| // [true] | ||
| result = _r.into([], _r.every(isEven), [0, 2, 7, 8, 9]); | ||
| // [false] | ||
| result = _r.into([], _r.some(isEven), [1, 3, 7, 8, 9]); | ||
| // [true] | ||
| result = _r.into([], _r.some(isEven), [1, 3, 7, 11, 9]); | ||
@@ -114,18 +109,8 @@ // [false] | ||
| // [true] | ||
| result = _r.into([], _r.contains(3), [1, 10, 7, 11, 9]); | ||
| // [false] | ||
| result = _r.into([], _r.find(isEven), [7, 8, 7, 11, 12]); | ||
| // [8] | ||
| result = _r.into([], _r.find(isEven), [1, 9, 13, 11, 9]); | ||
| // [] | ||
| result = _r.into([], _r.first(3), [1, 9, 13, 11, 9]); | ||
| // [1, 9, 13 ] | ||
| result = _r.into([], _r.max(), [1, 9, 13, 11, 9]); | ||
| // [13] | ||
| result = _r.into([], _r.min(), [11, 9, 13, 11, 9]); | ||
| // [9] | ||
| ``` | ||
@@ -201,5 +186,2 @@ | ||
| ##### tap(interceptor) | ||
| Invokes interceptor with each result and item, and then steps through unchanged. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. Executes interceptor with current result and item. | ||
| #### Array | ||
@@ -374,5 +356,2 @@ Array transducers mixing functionality from [transduce-array][15]. | ||
| yield 4; | ||
| yield 4; | ||
| yield 7; | ||
| yield 4; | ||
| } | ||
@@ -402,20 +381,6 @@ | ||
| Different ways to use `_r.generate`. If not chaining, creates an iterator that can be used with transduce. If chaining, creates an iterator a wraps the result. Pass true as second argument optionally call function to init on each iteration (allows reuse). | ||
| If not chaining, creates an iterator that can be used with transduce. If chaining, creates an iterator a wraps the result. Pass true as second argument optionally call function to init on each iteration (allows reuse). | ||
| ```javascript | ||
| // All results below the same | ||
| // [ 1, 1, 2, 3, 5, 8, 13 ] | ||
| result = _r.seqeuence(_r.first(7), _r.generate(fib())); | ||
| result = _r.into([], _r.first(7), _r.generate(fib())); | ||
| result = _r().first(7).seqeuence(_r.generate(fib())); | ||
| result = _r().first(7).generate(fib()).value(); | ||
| result = _r(_r.generate(fib())).first(7).value(); | ||
| result = _r().generate(fib()).first(7).value(); | ||
| // call on init to allow reuse | ||
| trans = _r(_r.generate(fib, true)).first(7); | ||
| result = trans.value(); | ||
| result = trans.value(); | ||
| trans = _r().generate(fib, true).first(7); | ||
@@ -428,3 +393,3 @@ result = trans.value(); | ||
| Transducers are normally consumed by reduce, but since they are designed to be independent, we can use them in a variety of processes that consume an input and produce a result, such as [CSP][3]. We can also create a process using a simple callback where each call advances a step in the process. These can be used as event handlers (like the [demo][4]). | ||
| Transducers can be consumed by reduce, but since they are designed to be independent, we can use them in a variety of contexts that consume an input and produce a result, such as [CSP][3]. We can also create a process using a callback where each call advances a step in the process. These can be used as event handlers (like the [demo][4]). | ||
@@ -463,4 +428,8 @@ Uses [transduce-push][17] to create push streams from transducers. | ||
| ``` | ||
| We are simply composing transducers. The previous examples are all using transducers behind the scenes. Method chaining is implicit and is simple composition, `_r.generate` uses an iterator and passes on to `transduce`. Even `asCallback` uses transducers but steps through the results using the argument of a callback, instead of reducing over the results. | ||
| We are composing transducers. The previous examples are all using transducers behind the scenes. Method chaining is implicit and is composition, `_r.generate` uses an iterator and passes on to `transduce`. Even `asCallback` uses transducers but steps through the results using the argument of a callback, instead of reducing over the results. | ||
| ##### tap(interceptor) | ||
| Transduce also adds `tap`, which invokes interceptor with each result and item, and then steps through unchanged. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. Executes interceptor with current result and item. | ||
| ### Node Async | ||
@@ -596,2 +565,52 @@ | ||
| #### Utils | ||
| Finally, adds utils from [transduce][14]. | ||
| ##### toArray(xf?, coll) | ||
| Transduce a collection into an array with an optional transformation. | ||
| From [transduce-toarray](https://github.com/transduce/transduce-toarray) | ||
| ##### compose() | ||
| Simple function composition of arguments. Useful for composing (combining) transducers. | ||
| From [transduce-compose](https://github.com/transduce/transduce-compose) | ||
| ##### isIterable(value) | ||
| Does the parameter conform to the iterable protocol? | ||
| ##### iterable(value) | ||
| Returns the iterable for the parameter. Returns value if conforms to iterable protocol. Returns `undefined` if cannot return en iterable. | ||
| The return value will either conform to iterator protocol that can be invoked for iteration or will be undefined. | ||
| Supports anything that returns true for `isIterable` and converts arrays to iterables over each indexed item. Converts to functions to infinite iterables that always call function on next | ||
| ##### isIterator(value) | ||
| Does the parameter have an iterator protocol or have a next method? | ||
| ##### isTransformer(value) | ||
| Does the parameter have a [transformer protocol][10] or have `init`, `step`, `result` methods? | ||
| ##### transformer(value) | ||
| Attempts to convert the parameter into a transformer. If cannot be converted, returns `undefined`. If defined, the return value will have `init`, `step`, `result` methods that can be used for transformation. Converts arrays (`arrayPush`), strings (`stringAppend`), objects (`objectMerge`), functions (wrap as reducing function) or anything that `isTransformer` into a transformer. | ||
| ##### protocols | ||
| Symbols (or strings that act as symbols) for `@@iterator` and [`@@transformer`][10] that you can use to configure your custom objects. | ||
| ##### identity(value) | ||
| Always returns value | ||
| ##### arrayPush(arr, item) | ||
| Array.push as a reducing function. Calls push and returns array; | ||
| ##### objectMerge(object, item) | ||
| Merges the item into the object. If `item` is an array of length 2, uses first (0 index) as the key and the second (1 index) as the value. Otherwise iterates over own properties of items and merges values with same keys into the result object. | ||
| ##### stringAppend(string, item) | ||
| Appends item onto result using `+`. | ||
| ##### is{Array, String, RegExp, Number, Undefined} | ||
| Predicates for object types | ||
| #### License | ||
@@ -598,0 +617,0 @@ MIT |
49913
3.81%813
2.14%625
3.14%