diff --git a/docs/index.html b/docs/index.html
new file mode 100644
index 0000000..ff68dc2
--- /dev/null
+++ b/docs/index.html
@@ -0,0 +1,131 @@
+
+
+
+
+ index.js
+
+
+
+
+
+
+
+
+
+
+ Jump To …
+ +
+
+
+
+
+
+
+
+
+
+
index.js
+
+
+
+
+
+
+
+
+ ['array.builders' ,
+ 'array.selectors' ,
+ 'collections.walk' ,
+ 'function.arity' ,
+ 'function.combinators' ,
+ 'function.iterators' ,
+ 'function.predicates' ,
+ 'object.builders' ,
+ 'object.selectors' ,
+ 'util.existential' ,
+ 'util.strings' ,
+ 'util.trampolines' ].forEach(function (lib) {
+ require('./underscore.' +lib);
+ });
+
+module.exports = require('underscore' );
+
+
+
+
+
+
+
diff --git a/docs/underscore.array.builders.html b/docs/underscore.array.builders.html
index e930f6a..3f4a002 100644
--- a/docs/underscore.array.builders.html
+++ b/docs/underscore.array.builders.html
@@ -19,6 +19,11 @@
-
+
@@ -110,8 +120,7 @@ underscore.array.builders.js
-
-Baseline setup
+ Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,8 +148,7 @@ Baseline setup
-
-Helpers
+ Helpers
@@ -155,30 +162,25 @@ Helpers
¶
-Create quick reference variables for speed access to core prototypes.
-
- var slice = Array . prototype . slice ,
- concat = Array . prototype . concat ;
-
- var existy = function ( x ) { return x != null ; };
-
-
+
-
-
Mixing in the array builders
+
Create quick reference variables for speed access to core prototypes.
-
+
var slice = Array.prototype.slice,
+ concat = Array.prototype.concat;
+
+ var existy = function (x) { return x != null ; };
@@ -186,28 +188,13 @@
Mixing in the array builders
-
+
-
-
Concatenates one or more arrays given as arguments. If given objects and
-scalars as arguments cat will plop them down in place in the result
-array. If given an arguments object, cat will treat it like an array
-and concatenate it likewise.
+
Mixing in the array builders
-
cat : function () {
- return _ . reduce ( arguments , function ( acc , elem ) {
- if ( _ . isArguments ( elem )) {
- return concat . call ( acc , slice . call ( elem ));
- }
- else {
- return concat . call ( acc , elem );
- }
- }, []);
- },
-
@@ -218,13 +205,9 @@
Mixing in the array builders
¶
-'Constructs' an array by putting an element at its front
-
- cons : function ( head , tail ) {
- return _ . cat ([ head ], tail );
- },
+
@@ -235,294 +218,324 @@ Mixing in the array builders
+ Concatenates one or more arrays given as arguments. If given objects and
+scalars as arguments cat will plop them down in place in the result
+array. If given an arguments object, cat will treat it like an array
+and concatenate it likewise.
+
+
+
+ cat: function () {
+ return _.reduce(arguments, function (acc, elem) {
+ if (_.isArguments(elem)) {
+ return concat.call(acc, slice.call(elem));
+ }
+ else {
+ return concat.call(acc, elem);
+ }
+ }, []);
+ },
+
+
+
+
+
+
+
+
+
'Constructs' an array by putting an element at its front
+
+
+
+ cons: function (head, tail) {
+ return _.cat([head], tail);
+ },
+
+
+
+
+
+
-
Takes an array and parititions it some number of times into
+
+
Takes an array and parititions it some number of times into
sub-arrays of size n. Allows and optional padding array as
the third argument to fill in the tail partition when n is
not sufficient to build paritions of the same size.
- partition : function ( array , n , pad ) {
- var p = function ( array ) {
- if ( array == null ) return [];
+ partition: function (array, n, pad) {
+ var p = function (array) {
+ if (array == null ) return [];
- var part = _ . take ( array , n );
+ var part = _.take(array, n);
- if ( n === _ . size ( part )) {
- return _ . cons ( part , p ( _ . drop ( array , n )));
- }
- else {
- return pad ? [ _ . take ( _ . cat ( part , pad ), n )] : [];
- }
- };
+ if (n === _.size(part)) {
+ return _.cons(part, p(_.drop(array, n)));
+ }
+ else {
+ return pad ? [_.take(_.cat(part, pad), n)] : [];
+ }
+ };
- return p ( array );
- },
+ return p(array);
+ },
-
+
-
-
Takes an array and parititions it some number of times into
+
Takes an array and parititions it some number of times into
sub-arrays of size n. If the array given cannot fill the size
needs of the final partition then a smaller partition is used
for the last.
- partitionAll : function ( array , n , step ) {
- step = ( step != null ) ? step : n ;
+ partitionAll: function (array, n, step) {
+ step = (step != null ) ? step : n;
- var p = function ( array , n , step ) {
- if ( _ . isEmpty ( array )) return [];
+ var p = function (array, n, step) {
+ if (_.isEmpty(array)) return [];
- return _ . cons ( _ . take ( array , n ),
- p ( _ . drop ( array , step ), n , step ));
- };
+ return _.cons(_.take(array, n),
+ p(_.drop(array, step), n, step));
+ };
- return p ( array , n , step );
- },
+ return p(array, n, step);
+ },
-
+
-
-
Maps a function over an array and concatenates all of the results.
+
Maps a function over an array and concatenates all of the results.
- mapcat : function ( array , fun ) {
- return _ . cat . apply ( null , _ . map ( array , fun ));
- },
+ mapcat: function (array, fun) {
+ return _.cat.apply(null , _.map(array, fun));
+ },
-
+
-
-
Returns an array with some item between each element
+
Returns an array with some item between each element
of a given array.
- interpose : function ( array , inter ) {
- if ( ! _ . isArray ( array )) throw new TypeError ;
- var sz = _ . size ( array );
- if ( sz === 0 ) return array ;
- if ( sz === 1 ) return array ;
+ interpose: function (array, inter) {
+ if (!_.isArray(array)) throw new TypeError;
+ var sz = _.size(array);
+ if (sz === 0 ) return array;
+ if (sz === 1 ) return array;
- return slice . call ( _ . mapcat ( array , function ( elem ) {
- return _ . cons ( elem , [ inter ]);
- }), 0 , - 1 );
- },
+ return slice.call(_.mapcat(array, function (elem) {
+ return _.cons(elem, [inter]);
+ }), 0 , -1 );
+ },
-
+
-
-
Weaves two or more arrays together
+
Weaves two or more arrays together
- weave : function ( /* args */ ) {
- if ( ! _ . some ( arguments )) return [];
+ weave: function () {
+ if (!_.some(arguments)) return [];
- return _ . filter ( _ . flatten ( _ . zip . apply ( null , arguments ), true ), function ( elem ) {
- return elem != null ;
- });
- },
- interleave : _ . weave ,
+ return _.filter(_.flatten(_.zip.apply(null , arguments), true ), function (elem) {
+ return elem != null ;
+ });
+ },
+ interleave: _.weave,
-
+
-
-
Returns an array of a value repeated a certain number of
+
Returns an array of a value repeated a certain number of
times.
- repeat : function ( t , elem ) {
- return _ . times ( t , function () { return elem ; });
- },
+ repeat: function (t, elem) {
+ return _.times(t, function () { return elem; });
+ },
-
+
-
-
Returns an array built from the contents of a given array repeated
+
Returns an array built from the contents of a given array repeated
a certain number of times.
- cycle : function ( t , elems ) {
- return _ . flatten ( _ . times ( t , function () { return elems ; }), true );
- },
+ cycle: function (t, elems) {
+ return _.flatten(_.times(t, function () { return elems; }), true );
+ },
-
+
-
-
Returns an array with two internal arrays built from
+
Returns an array with two internal arrays built from
taking an original array and spliting it at an index.
- splitAt : function ( array , index ) {
- return [ _ . take ( array , index ), _ . drop ( array , index )];
- },
+ splitAt: function (array, index) {
+ return [_.take(array, index), _.drop(array, index)];
+ },
-
+
-
-
Call a function recursively f(f(f(args))) until a second
+
Call a function recursively f(f(f(args))) until a second
given function goes falsey. Expects a seed value to start.
- iterateUntil : function ( doit , checkit , seed ) {
- var ret = [];
- var result = doit ( seed );
+ iterateUntil: function (doit, checkit, seed) {
+ var ret = [];
+ var result = doit(seed);
- while ( checkit ( result )) {
- ret . push ( result );
- result = doit ( result );
- }
+ while (checkit(result)) {
+ ret.push(result);
+ result = doit(result);
+ }
- return ret ;
- },
+ return ret;
+ },
-
+
-
-
Takes every nth item from an array, returning an array of
+
Takes every nth item from an array, returning an array of
the results.
- takeSkipping : function ( array , n ) {
- var ret = [];
- var sz = _ . size ( array );
+ takeSkipping: function (array, n) {
+ var ret = [];
+ var sz = _.size(array);
- if ( n <= 0 ) return [];
- if ( n === 1 ) return array ;
+ if (n <= 0 ) return [];
+ if (n === 1 ) return array;
- for ( var index = 0 ; index < sz ; index += n ) {
- ret . push ( array [ index ]);
- }
+ for (var index = 0 ; index < sz; index += n) {
+ ret.push(array[index]);
+ }
- return ret ;
- },
+ return ret;
+ },
-
+
-
-
Returns an array of each intermediate stage of a call to
+
Returns an array of each intermediate stage of a call to
a reduce-like function.
- reductions : function ( array , fun , init ) {
- var ret = [];
- var acc = init ;
+ reductions: function (array, fun, init) {
+ var ret = [];
+ var acc = init;
- _ . each ( array , function ( v , k ) {
- acc = fun ( acc , array [ k ]);
- ret . push ( acc );
- });
+ _.each(array, function (v,k) {
+ acc = fun(acc, array[k]);
+ ret.push(acc);
+ });
- return ret ;
- },
+ return ret;
+ },
-
+
-
-
Runs its given function on the index of the elements rather than
+
Runs its given function on the index of the elements rather than
the elements themselves, keeping all of the truthy values in the end.
- keepIndexed : function ( array , pred ) {
- return _ . filter ( _ . map ( _ . range ( _ . size ( array )), function ( i ) {
- return pred ( i , array [ i ]);
- }),
- existy );
- }
- });
-
-})( this );
+ keepIndexed: function (array, pred) {
+ return _.filter(_.map(_.range(_.size(array)), function (i) {
+ return pred(i, array[i]);
+ }),
+ existy);
+ }
+ });
-
+})(this );
diff --git a/docs/underscore.array.selectors.html b/docs/underscore.array.selectors.html
index 68fa626..04e4b0f 100644
--- a/docs/underscore.array.selectors.html
+++ b/docs/underscore.array.selectors.html
@@ -19,6 +19,11 @@
-
+
@@ -110,8 +120,7 @@ underscore.array.selectors.js
-
-Baseline setup
+ Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,8 +148,7 @@ Baseline setup
-
-Helpers
+ Helpers
@@ -154,17 +161,16 @@ Helpers
-
-Create quick reference variables for speed access to core prototypes.
+ Create quick reference variables for speed access to core prototypes.
- var slice = Array . prototype . slice ,
- concat = Array . prototype . concat ;
+ var slice = Array.prototype.slice,
+ concat = Array.prototype.concat;
- var existy = function ( x ) { return x != null ; };
- var truthy = function ( x ) { return ( x !== false ) && existy ( x ); };
- var isSeq = function ( x ) { return ( _ . isArray ( x )) || ( _ . isArguments ( x )); };
+ var existy = function (x) { return x != null ; };
+ var truthy = function (x) { return (x !== false ) && existy(x); };
+ var isSeq = function (x) { return (_.isArray(x)) || (_.isArguments(x)); };
@@ -175,13 +181,10 @@ Helpers
-
-Mixing in the array selectors
+ Mixing in the array selectors
-
-
@@ -192,16 +195,9 @@ Mixing in the array selectors
¶
-Returns the second element of an array. Passing n will return all but
-the first of the head N values in the array. The guard check allows it
-to work with _.map.
-
- second : function ( array , n , guard ) {
- if ( array == null ) return void 0 ;
- return ( n != null ) && ! guard ? slice . call ( array , 1 , n ) : array [ 1 ];
- },
+
@@ -212,16 +208,16 @@ Mixing in the array selectors
-
-A function to get at an index into an array
+ Returns the second element of an array. Passing n will return all but
+the first of the head N values in the array. The guard check allows it
+to work with _.map.
- nth : function ( array , index ) {
- if (( index < 0 ) || ( index > array . length - 1 )) throw Error ( "Attempting to index outside the bounds of the array." );
-
- return array [ index ];
- },
+ second: function (array, n, guard) {
+ if (array == null ) return void 0 ;
+ return (n != null ) && !guard ? slice.call(array, 1 , n) : array[1 ];
+ },
@@ -232,24 +228,15 @@ Mixing in the array selectors
-
-Takes all items in an array while a given predicate returns truthy.
+ A function to get at an index into an array
- takeWhile : function ( array , pred ) {
- if ( ! isSeq ( array )) throw new TypeError ;
+ nth: function (array, index) {
+ if ((index < 0 ) || (index > array.length - 1 )) throw Error("Attempting to index outside the bounds of the array." );
- var sz = _ . size ( array );
-
- for ( var index = 0 ; index < sz ; index ++ ) {
- if ( ! truthy ( pred ( array [ index ]))) {
- break ;
- }
- }
-
- return _ . take ( array , index );
- },
+ return array[index];
+ },
@@ -260,23 +247,23 @@ Mixing in the array selectors
-
-Drops all items from an array while a given predicate returns truthy.
+ Takes all items in an array while a given predicate returns truthy.
- dropWhile : function ( array , pred ) {
- if ( ! isSeq ( array )) throw new TypeError ;
+ takeWhile: function (array, pred) {
+ if (!isSeq(array)) throw new TypeError;
- var sz = _ . size ( array );
+ var sz = _.size(array);
- for ( var index = 0 ; index < sz ; index ++ ) {
- if ( ! truthy ( pred ( array [ index ])))
- break ;
- }
+ for (var index = 0 ; index < sz; index++) {
+ if (!truthy(pred(array[index]))) {
+ break ;
+ }
+ }
- return _ . drop ( array , index );
- },
+ return _.take(array, index);
+ },
@@ -287,16 +274,22 @@ Mixing in the array selectors
-
-Returns an array with two internal arrays built from
-taking an original array and spliting it at the index
-where a given function goes falsey.
+ Drops all items from an array while a given predicate returns truthy.
- splitWith : function ( array , pred ) {
- return [ _ . takeWhile ( pred , array ), _ . dropWhile ( pred , array )];
- },
+ dropWhile: function (array, pred) {
+ if (!isSeq(array)) throw new TypeError;
+
+ var sz = _.size(array);
+
+ for (var index = 0 ; index < sz; index++) {
+ if (!truthy(pred(array[index])))
+ break ;
+ }
+
+ return _.drop(array, index);
+ },
@@ -307,23 +300,15 @@ Mixing in the array selectors
-
-Takes an array and partitions it as the given predicate changes
-truth sense.
+ Returns an array with two internal arrays built from
+taking an original array and spliting it at the index
+where a given function goes falsey.
- partitionBy : function ( array , fun ){
- if ( _ . isEmpty ( array ) || ! existy ( array )) return [];
-
- var fst = _ . first ( array );
- var fstVal = fun ( fst );
- var run = concat . call ([ fst ], _ . takeWhile ( _ . rest ( array ), function ( e ) {
- return _ . isEqual ( fstVal , fun ( e ));
- }));
-
- return concat . call ([ run ], _ . partitionBy ( _ . drop ( array , _ . size ( run )), fun ));
- },
+ splitWith: function (array, pred) {
+ return [_.takeWhile(pred, array), _.dropWhile(pred, array)];
+ },
@@ -334,17 +319,22 @@ Mixing in the array selectors
-
-Returns the 'best' value in an array based on the result of a
-given function.
+ Takes an array and partitions it as the given predicate changes
+truth sense.
- best : function ( array , fun ) {
- return _ . reduce ( array , function ( x , y ) {
- return fun ( x , y ) ? x : y ;
- });
- },
+ partitionBy: function (array, fun){
+ if (_.isEmpty(array) || !existy(array)) return [];
+
+ var fst = _.first(array);
+ var fstVal = fun(fst);
+ var run = concat.call([fst], _.takeWhile(_.rest(array), function (e) {
+ return _.isEqual(fstVal, fun(e));
+ }));
+
+ return concat.call([run], _.partitionBy(_.drop(array, _.size(run)), fun));
+ },
@@ -355,23 +345,40 @@ Mixing in the array selectors
-
-Returns an array of existy results of a function over an source array.
+ Returns the 'best' value in an array based on the result of a
+given function.
- keep : function ( array , fun ) {
- if ( ! isSeq ( array )) throw new TypeError ( "expected an array as the first argument" );
+ best: function (array, fun) {
+ return _.reduce(array, function (x, y) {
+ return fun(x, y) ? x : y;
+ });
+ },
+
+
+
+
+
+
+
+
+
Returns an array of existy results of a function over an source array.
-
return _ . filter ( _ . map ( array , function ( e ) {
-
return fun ( e );
-
}), existy );
-
}
-
});
+
+
+ keep: function (array, fun) {
+ if (!isSeq(array)) throw new TypeError("expected an array as the first argument" );
-})( this );
+ return _.filter(_.map(array, function (e) {
+ return fun(e);
+ }), existy);
+ }
+ });
-
+})(this );
diff --git a/docs/underscore.collections.walk.html b/docs/underscore.collections.walk.html
new file mode 100644
index 0000000..9ef6842
--- /dev/null
+++ b/docs/underscore.collections.walk.html
@@ -0,0 +1,377 @@
+
+
+
+
+ underscore.collections.walk.js
+
+
+
+
+
+
+
+
+
+
+ Jump To …
+ +
+
+
+
diff --git a/docs/underscore.function.arity.html b/docs/underscore.function.arity.html
index 714fd65..186f0ba 100644
--- a/docs/underscore.function.arity.html
+++ b/docs/underscore.function.arity.html
@@ -19,6 +19,11 @@
-
+
@@ -110,8 +120,7 @@ underscore.function.arity.js
-
-Baseline setup
+ Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,8 +148,7 @@ Baseline setup
-
-Helpers
+ Helpers
@@ -151,27 +158,22 @@ Helpers
-
+
-
Mixing in the arity functions
-
-
-
-
+
-
-
Fixed arguments
+
Mixing in the arity functions
@@ -185,79 +187,139 @@
Fixed arguments
¶
+
+
+
+
+
+
+
+
+
+
+
+
Fixed arguments
Fixes the arguments to a function based on the parameter template defined by
the presence of values and the _ placeholder.
- fix : function ( fun ) {
- var args = _ . rest ( arguments );
+ fix: function (fun) {
+ var args = _.rest(arguments);
- var f = function () {
- var arg = 0 ;
+ var f = function () {
+ var arg = 0 ;
- for ( var i = 0 ; i < args . length && arg < arguments . length ; i ++ ) {
- if ( args [ i ] === _ ) {
- args [ i ] = arguments [ arg ++ ];
- }
- }
+ for ( var i = 0 ; i < args.length && arg < arguments.length; i++ ) {
+ if ( args[i] === _ ) {
+ args[i] = arguments[arg++];
+ }
+ }
- return fun . apply ( null , args );
- };
+ return fun.apply(null , args);
+ };
- f . _original = fun ;
+ f._original = fun;
- return f ;
- },
+ return f;
+ },
- unary : function ( fun ) {
- return function unary ( a ) {
- return fun . call ( this , a );
- }
- },
+ unary: function (fun) {
+ return function unary (a) {
+ return fun.call(this , a);
+ };
+ },
- binary : function ( fun ) {
- return function binary ( a , b ) {
- return fun . call ( this , a , b );
- }
- },
+ binary: function (fun) {
+ return function binary (a, b) {
+ return fun.call(this , a, b);
+ };
+ },
- ternary : function ( fun ) {
- return function ternary ( a , b , c ) {
- return fun . call ( this , a , b , c );
- }
- },
+ ternary: function (fun) {
+ return function ternary (a, b, c) {
+ return fun.call(this , a, b, c);
+ };
+ },
- quaternary : function ( fun ) {
- return function quaternary ( a , b , c , d ) {
- return fun . call ( this , a , b , c , d );
- }
- }
-
- });
-
- _ . arity = ( function () {
- var FUNCTIONS = {};
- return function arity ( numberOfArgs , fun ) {
- if ( FUNCTIONS [ numberOfArgs ] == null ) {
- var parameters = new Array ( numberOfArgs );
- for ( var i = 0 ; i < numberOfArgs ; ++ i ) {
- parameters [ i ] = "__" + i ;
- }
- var pstr = parameters . join ();
- var code = "return function (" + pstr + ") { return fun.apply(this, arguments); };" ;
- FUNCTIONS [ numberOfArgs ] = new Function ([ 'fun' ], code );
- }
- if ( fun == null ) {
- return function ( fun ) { return arity ( numberOfArgs , fun ); };
- }
- else return FUNCTIONS [ numberOfArgs ]( fun );
- };
- })();
+ quaternary: function (fun) {
+ return function quaternary (a, b, c, d) {
+ return fun.call(this , a, b, c, d);
+ };
+ },
+
+
+
+
+
+
+
+
+
greedy currying for functions taking two arguments.
-
})( this );
+
+
+ curry2: function (fun) {
+ return function curried (first, optionalLast) {
+ if (arguments.length === 1 ) {
+ return function (last) {
+ return fun(first, last);
+ };
+ }
+ else return fun(first, optionalLast);
+ };
+ },
+
+
+
+
+
+
+
+
+
greedy flipped currying for functions taking two arguments.
+
+
+
+ curry2flipped: function (fun) {
+ return function curried (last, optionalFirst) {
+ if (arguments.length === 1 ) {
+ return function (first) {
+ return fun(first, last);
+ };
+ }
+ else return fun(optionalFirst, last);
+ };
+ }
+
+ });
+
+ _.arity = (function () {
+ var FUNCTIONS = {};
+ return function arity (numberOfArgs, fun) {
+ if (FUNCTIONS[numberOfArgs] == null ) {
+ var parameters = new Array(numberOfArgs);
+ for (var i = 0 ; i < numberOfArgs; ++i) {
+ parameters[i] = "__" + i;
+ }
+ var pstr = parameters.join();
+ var code = "return function (" +pstr+") { return fun.apply(this, arguments); };" ;
+ FUNCTIONS[numberOfArgs] = new Function(['fun' ], code);
+ }
+ if (fun == null ) {
+ return function (fun) { return arity(numberOfArgs, fun); };
+ }
+ else return FUNCTIONS[numberOfArgs](fun);
+ };
+ })();
-
+})(this );
diff --git a/docs/underscore.function.combinators.html b/docs/underscore.function.combinators.html
index dabaea1..43a5ba3 100644
--- a/docs/underscore.function.combinators.html
+++ b/docs/underscore.function.combinators.html
@@ -19,6 +19,11 @@
-
+
@@ -110,8 +120,7 @@ underscore.function.combinators.js
-
-Baseline setup
+ Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,32 +148,37 @@ Baseline setup
-
-Helpers
+ Helpers
- var existy = function ( x ) { return x != null ; };
- var truthy = function ( x ) { return ( x !== false ) && existy ( x ); };
- var __reverse = []. reverse ;
- var __slice = []. slice ;
-
-
-
+
-
Mixing in the combinator functions
-
-
+
var existy = function (x) { return x != null ; };
+ var truthy = function (x) { return (x !== false ) && existy(x); };
+ var __reverse = [].reverse;
+ var __slice = [].slice;
+ var __map = [].map;
+ var curry2 = function (fun) {
+ return function curried (first, optionalLast) {
+ if (arguments.length === 1 ) {
+ return function (last) {
+ return fun(first, last);
+ };
+ }
+ else return fun(first, optionalLast);
+ };
+ };
@@ -176,16 +189,10 @@
Mixing in the combinator functions
-
-
Takes a value and returns a function that always returns
-said value.
+
n.b. depends on underscore.function.arity.js
- always : function ( value ) {
- return function () { return value ; };
- },
-
@@ -195,21 +202,16 @@ Mixing in the combinator functions
-
-Takes some value as its first argument and runs it through a
-pipeline of functions given as the rest arguments.
+ Takes a target function and a mapping function. Returns a function
+that applies the mapper to its arguments before evaluating the body.
- pipeline : function ( /*, funs */ ){
- var funs = arguments ;
-
- return function ( seed ) {
- return _ . reduce ( funs ,
- function ( l , r ) { return r ( l ); },
- seed );
- };
- },
+ function baseMapArgs (fun, mapFun) {
+ return _.arity(fun.length, function () {
+ return fun.apply(this , __map.call(arguments, mapFun));
+ });
+ };
@@ -217,28 +219,13 @@ Mixing in the combinator functions
-
+
-
-
Composes a bunch of predicates into a single predicate that
-checks all elements of an array for conformance to all of the
-original predicates.
+
Mixing in the combinator functions
-
conjoin : function ( /* preds */ ) {
- var preds = arguments ;
-
- return function ( array ) {
- return _ . every ( array , function ( e ) {
- return _ . every ( preds , function ( p ) {
- return p ( e );
- });
- });
- };
- },
-
@@ -249,23 +236,9 @@
Mixing in the combinator functions
¶
-Composes a bunch of predicates into a single predicate that
-checks all elements of an array for conformance to any of the
-original predicates.
-
- disjoin : function ( /* preds */ ) {
- var preds = arguments ;
-
- return function ( array ) {
- return _ . some ( array , function ( e ) {
- return _ . some ( preds , function ( p ) {
- return p ( e );
- });
- });
- };
- },
+
@@ -276,21 +249,14 @@ Mixing in the combinator functions
-
-Takes a predicate-like and returns a comparator (-1,0,1).
+ Takes a value and returns a function that always returns
+said value.
- comparator : function ( fun ) {
- return function ( x , y ) {
- if ( truthy ( fun ( x , y )))
- return - 1 ;
- else if ( truthy ( fun ( y , x )))
- return 1 ;
- else
- return 0 ;
- };
- },
+ always: function (value) {
+ return function () { return value; };
+ },
@@ -301,16 +267,21 @@ Mixing in the combinator functions
-
-Returns a function that reverses the sense of a given predicate-like.
+ Takes some number of functions, either as an array or variadically
+and returns a function that takes some value as its first argument
+and runs it through a pipeline of the original functions given.
- complement : function ( pred ) {
- return function () {
- return ! pred . apply ( null , arguments );
- };
- },
+ pipeline: function (){
+ var funs = (_.isArray(arguments[0 ])) ? arguments[0 ] : arguments;
+
+ return function (seed) {
+ return _.reduce(funs,
+ function (l,r) { return r(l); },
+ seed);
+ };
+ },
@@ -321,171 +292,332 @@ Mixing in the combinator functions
+ Composes a bunch of predicates into a single predicate that
+checks all elements of an array for conformance to all of the
+original predicates.
+
+
+
+ conjoin: function () {
+ var preds = arguments;
+
+ return function (array) {
+ return _.every(array, function (e) {
+ return _.every(preds, function (p) {
+ return p(e);
+ });
+ });
+ };
+ },
+
+
+
+
+
+
-
Takes a function expecting varargs and
+
+
Composes a bunch of predicates into a single predicate that
+checks all elements of an array for conformance to any of the
+original predicates.
+
+
+
+ disjoin: function () {
+ var preds = arguments;
+
+ return function (array) {
+ return _.some(array, function (e) {
+ return _.some(preds, function (p) {
+ return p(e);
+ });
+ });
+ };
+ },
+
+
+
+
+
+
+
+
+
Takes a predicate-like and returns a comparator (-1,0,1).
+
+
+
+ comparator: function (fun) {
+ return function (x, y) {
+ if (truthy(fun(x, y)))
+ return -1 ;
+ else if (truthy(fun(y, x)))
+ return 1 ;
+ else
+ return 0 ;
+ };
+ },
+
+
+
+
+
+
+
+
+
Returns a function that reverses the sense of a given predicate-like.
+
+
+
+ complement: function (pred) {
+ return function () {
+ return !pred.apply(null , arguments);
+ };
+ },
+
+
+
+
+
+
+
+
+
Takes a function expecting varargs and
returns a function that takes an array and
uses its elements as the args to the original
function
- splat : function ( fun ) {
- return function ( array ) {
- return fun . apply ( null , array );
- };
- },
+ splat: function (fun) {
+ return function (array) {
+ return fun.apply(null , array);
+ };
+ },
-
+
-
-
Takes a function expecting an array and returns
+
Takes a function expecting an array and returns
a function that takes varargs and wraps all
in an array that is passed to the original function.
- unsplat : function ( fun ) {
- var funLength = fun . length ;
-
- if ( funLength < 1 ) {
- return fun ;
- }
- else if ( funLength === 1 ) {
- return function () {
- return fun . call ( this , __slice . call ( arguments , 0 ))
- }
- }
- else {
- return function () {
- var numberOfArgs = arguments . length ,
- namedArgs = __slice . call ( arguments , 0 , funLength - 1 ),
- numberOfMissingNamedArgs = Math . max ( funLength - numberOfArgs - 1 , 0 ),
- argPadding = new Array ( numberOfMissingNamedArgs ),
- variadicArgs = __slice . call ( arguments , fun . length - 1 );
-
- return fun . apply ( this , namedArgs . concat ( argPadding ). concat ([ variadicArgs ]))
- }
- }
- },
+ unsplat: function (fun) {
+ var funLength = fun.length;
+
+ if (funLength < 1 ) {
+ return fun;
+ }
+ else if (funLength === 1 ) {
+ return function () {
+ return fun.call(this , __slice.call(arguments, 0 ));
+ };
+ }
+ else {
+ return function () {
+ var numberOfArgs = arguments.length,
+ namedArgs = __slice.call(arguments, 0 , funLength - 1 ),
+ numberOfMissingNamedArgs = Math.max(funLength - numberOfArgs - 1 , 0 ),
+ argPadding = new Array(numberOfMissingNamedArgs),
+ variadicArgs = __slice.call(arguments, fun.length - 1 );
+
+ return fun.apply(this , namedArgs.concat(argPadding).concat([variadicArgs]));
+ };
+ }
+ },
-
+
+
Same as unsplat, but the rest of the arguments are collected in the
+first parameter, e.g. unsplatl( function (args, callback) { ... ]})
+
+
+
+ unsplatl: function (fun) {
+ var funLength = fun.length;
+
+ if (funLength < 1 ) {
+ return fun;
+ }
+ else if (funLength === 1 ) {
+ return function () {
+ return fun.call(this , __slice.call(arguments, 0 ))
+ };
+ }
+ else {
+ return function () {
+ var numberOfArgs = arguments.length,
+ namedArgs = __slice.call(arguments, Math.max(numberOfArgs - funLength + 1 , 0 )),
+ variadicArgs = __slice.call(arguments, 0 , Math.max(numberOfArgs - funLength + 1 , 0 ));
+
+ return fun.apply(this , [variadicArgs].concat(namedArgs));
+ };
+ }
+ },
+
+
+
+
+
+
+
+
+
map the arguments of a function
+
+
+
+ mapArgs: curry2(baseMapArgs),
+
+
+
+
+
+
-
Returns a function that returns an array of the calls to each
+
+
Returns a function that returns an array of the calls to each
given function for some arguments.
- juxt : function ( /* funs */ ) {
- var funs = arguments ;
+ juxt: function () {
+ var funs = arguments;
- return function ( arg ) {
- return _ . map ( funs , function ( f ) {
- return f ( arg );
- });
- };
- },
+ return function () {
+ var args = arguments;
+ return _.map(funs, function (f) {
+ return f.apply(null , args);
+ });
+ };
+ },
-
+
-
-
Returns a function that protects a given function from receiving
+
Returns a function that protects a given function from receiving
non-existy values. Each subsequent value provided to fnull acts
as the default to the original function should a call receive non-existy
values in the defaulted arg slots.
- fnull : function ( fun /*, defaults */ ) {
- var defaults = _ . rest ( arguments );
+ fnull: function (fun ) {
+ var defaults = _.rest(arguments);
- return function ( /*args*/ ) {
- var args = _ . toArray ( arguments );
- var sz = _ . size ( defaults );
+ return function () {
+ var args = _.toArray(arguments);
+ var sz = _.size(defaults);
- for ( var i = 0 ; i < sz ; i ++ ) {
- if ( ! existy ( args [ i ]))
- args [ i ] = defaults [ i ];
- }
+ for (var i = 0 ; i < sz; i++) {
+ if (!existy(args[i]))
+ args[i] = defaults[i];
+ }
- return fun . apply ( null , args );
- };
- },
+ return fun.apply(null , args);
+ };
+ },
-
+
-
-
Flips the first two args of a function
+
Flips the first two args of a function
- flip2 : function ( fun ) {
- return function ( /* args */ ) {
- var tmp = arguments [ 0 ];
- arguments [ 0 ] = arguments [ 1 ];
- arguments [ 1 ] = tmp ;
+ flip2: function (fun) {
+ return function () {
+ var tmp = arguments[0 ];
+ arguments[0 ] = arguments[1 ];
+ arguments[1 ] = tmp;
- return fun . apply ( null , arguments );
- };
- },
+ return fun.apply(null , arguments);
+ };
+ },
-
+
-
-
Flips an arbitrary number of args of a function
+
Flips an arbitrary number of args of a function
- flip : function ( fun ) {
- return function ( /* args */ ) {
- var reversed = __reverse . call ( arguments );
+ flip: function (fun) {
+ return function () {
+ var reversed = __reverse.call(arguments);
- return fun . apply ( null , reversed );
- };
- },
+ return fun.apply(null , reversed);
+ };
+ },
- k : _ . always ,
- t : _ . pipeline
- });
+ k: _.always,
+ t: _.pipeline
+ });
+
+ _.unsplatr = _.unsplat;
+
+
+
+
+
+
+
+
+
map the arguments of a function, takes the mapping function
+first so it can be used as a combinator
-
})( this );
+
+
+ _.mapArgsWith = curry2(_.flip(baseMapArgs));
+
+
-
+})(this );
diff --git a/docs/underscore.function.iterators.html b/docs/underscore.function.iterators.html
index 03f2c62..26116f4 100644
--- a/docs/underscore.function.iterators.html
+++ b/docs/underscore.function.iterators.html
@@ -19,6 +19,11 @@
-
+
@@ -110,8 +120,7 @@ underscore.function.iterators.js
-
-Baseline setup
+ Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,326 +148,342 @@ Baseline setup
-
-Helpers
+ Helpers
-
- var HASNTBEENRUN = {};
+
+
+
+
+
+
+
+ var HASNTBEENRUN = {};
- function unary ( fun ) {
- return function ( first ) {
- return fun . call ( this , first );
- };
- }
+ function unary (fun) {
+ return function (first) {
+ return fun.call(this , first);
+ };
+ }
- function binary ( fun ) {
- return function ( first , second ) {
- return fun . call ( this , first , second );
- };
- }
+ function binary (fun) {
+ return function (first, second) {
+ return fun.call(this , first, second);
+ };
+ }
- var undefined = void 0 ;
-
-
+ var undefined = void 0 ;
-
+
-
-
Mixing in the iterator functions
+
Mixing in the iterator functions
- function foldl ( iter , binaryFn , seed ) {
- var state , element ;
- if ( seed !== void 0 ) {
- state = seed ;
- }
- else {
- state = iter ();
- }
- element = iter ();
- while ( element != null ) {
- state = binaryFn . call ( element , state , element );
- element = iter ();
- }
- return state ;
- };
+
+
+
+
+
+
+ function foldl (iter, binaryFn, seed) {
+ var state, element;
+ if (seed !== void 0 ) {
+ state = seed;
+ }
+ else {
+ state = iter();
+ }
+ element = iter();
+ while (element != null ) {
+ state = binaryFn.call(element, state, element);
+ element = iter();
+ }
+ return state;
+ };
- function unfold ( seed , unaryFn ) {
- var state = HASNTBEENRUN ;
- return function () {
- if ( state === HASNTBEENRUN ) {
- return ( state = seed );
- }
- else if ( state != null ) {
- return ( state = unaryFn . call ( state , state ));
- }
- else return state ;
- };
- };
-
+ function unfold (seed, unaryFn) {
+ var state = HASNTBEENRUN;
+ return function () {
+ if (state === HASNTBEENRUN) {
+ return (state = seed);
+ }
+ else if (state != null ) {
+ return (state = unaryFn.call(state, state));
+ }
+ else return state;
+ };
+ };
-
+
-
-
note that the unfoldWithReturn behaves differently than
+
note that the unfoldWithReturn behaves differently than
unfold with respect to the first value returned
- function unfoldWithReturn ( seed , unaryFn ) {
- var state = seed ,
- pair ,
- value ;
- return function () {
- if ( state != null ) {
- pair = unaryFn . call ( state , state );
- value = pair [ 1 ];
- state = value != null
- ? pair [ 0 ]
- : void 0
- return value ;
- }
- else return void 0 ;
- };
- };
+ function unfoldWithReturn (seed, unaryFn) {
+ var state = seed,
+ pair,
+ value;
+ return function () {
+ if (state != null ) {
+ pair = unaryFn.call(state, state);
+ value = pair[1 ];
+ state = value != null
+ ? pair[0 ]
+ : void 0 ;
+ return value;
+ }
+ else return void 0 ;
+ };
+ };
- function accumulate ( iter , binaryFn , initial ) {
- var state = initial ;
- return function () {
- element = iter ();
- if ( element == null ) {
- return element ;
- }
- else {
- if ( state === void 0 ) {
- return ( state = element );
- }
- else return ( state = binaryFn . call ( element , state , element ));
- }
- }
- };
+ function accumulate (iter, binaryFn, initial) {
+ var state = initial;
+ return function () {
+ element = iter();
+ if (element == null ) {
+ return element;
+ }
+ else {
+ if (state === void 0 ) {
+ return (state = element);
+ }
+ else return (state = binaryFn.call(element, state, element));
+ }
+ };
+ };
- function accumulateWithReturn ( iter , binaryFn , initial ) {
- var state = initial ,
- stateAndReturnValue ;
- return function () {
- element = iter ();
- if ( element == null ) {
- return element ;
- }
- else {
- if ( state === void 0 ) {
- return ( state = element );
- }
- else {
- stateAndReturnValue = binaryFn . call ( element , state , element );
- state = stateAndReturnValue [ 0 ];
- return stateAndReturnValue [ 1 ];
- }
- }
- }
- };
+ function accumulateWithReturn (iter, binaryFn, initial) {
+ var state = initial,
+ stateAndReturnValue;
+ return function () {
+ element = iter();
+ if (element == null ) {
+ return element;
+ }
+ else {
+ if (state === void 0 ) {
+ return (state = element);
+ }
+ else {
+ stateAndReturnValue = binaryFn.call(element, state, element);
+ state = stateAndReturnValue[0 ];
+ return stateAndReturnValue[1 ];
+ }
+ }
+ };
+ };
- function map ( iter , unaryFn ) {
- return function () {
- var element ;
- element = iter ();
- if ( element != null ) {
- return unaryFn . call ( element , element );
- } else {
- return void 0 ;
- }
- };
- };
+ function map (iter, unaryFn) {
+ return function () {
+ var element;
+ element = iter();
+ if (element != null ) {
+ return unaryFn.call(element, element);
+ } else {
+ return void 0 ;
+ }
+ };
+ };
- function select ( iter , unaryPredicateFn ) {
- return function () {
- var element ;
- element = iter ();
- while ( element != null ) {
- if ( unaryPredicateFn . call ( element , element )) {
- return element ;
- }
- element = iter ();
- }
- return void 0 ;
- };
- };
+ function select (iter, unaryPredicateFn) {
+ return function () {
+ var element;
+ element = iter();
+ while (element != null ) {
+ if (unaryPredicateFn.call(element, element)) {
+ return element;
+ }
+ element = iter();
+ }
+ return void 0 ;
+ };
+ };
- function reject ( iter , unaryPredicateFn ) {
- return select ( iter , function ( something ) {
- return ! unaryPredicateFn ( something );
- });
- };
+ function reject (iter, unaryPredicateFn) {
+ return select(iter, function (something) {
+ return !unaryPredicateFn(something);
+ });
+ };
- function find ( iter , unaryPredicateFn ) {
- return select ( iter , unaryPredicateFn )();
- }
+ function find (iter, unaryPredicateFn) {
+ return select(iter, unaryPredicateFn)();
+ }
- function slice ( iter , numberToDrop , numberToTake ) {
- var count = 0 ;
- while ( numberToDrop -- > 0 ) {
- iter ();
- }
- if ( numberToTake != null ) {
- return function () {
- if ( ++ count <= numberToTake ) {
- return iter ();
- } else {
- return void 0 ;
- }
- };
- }
- else return iter ;
- };
+ function slice (iter, numberToDrop, numberToTake) {
+ var count = 0 ;
+ while (numberToDrop-- > 0 ) {
+ iter();
+ }
+ if (numberToTake != null ) {
+ return function () {
+ if (++count <= numberToTake) {
+ return iter();
+ } else {
+ return void 0 ;
+ }
+ };
+ }
+ else return iter;
+ };
- function drop ( iter , numberToDrop ) {
- return slice ( iter , numberToDrop == null ? 1 : numberToDrop );
- }
+ function drop (iter, numberToDrop) {
+ return slice(iter, numberToDrop == null ? 1 : numberToDrop);
+ }
- function take ( iter , numberToTake ) {
- return slice ( iter , 0 , numberToTake == null ? 1 : numberToTake );
- }
+ function take (iter, numberToTake) {
+ return slice(iter, 0 , numberToTake == null ? 1 : numberToTake);
+ }
- function List ( array ) {
- var index = 0 ;
- return function () {
- return array [ index ++ ];
- };
- };
+ function List (array) {
+ var index = 0 ;
+ return function () {
+ return array[index++];
+ };
+ };
- function Tree ( array ) {
- var index , myself , state ;
- index = 0 ;
- state = [];
- myself = function () {
- var element , tempState ;
- element = array [ index ++ ];
- if ( element instanceof Array ) {
- state . push ({
- array : array ,
- index : index
- });
- array = element ;
- index = 0 ;
- return myself ();
- } else if ( element === void 0 ) {
- if ( state . length > 0 ) {
- tempState = state . pop (), array = tempState . array , index = tempState . index ;
- return myself ();
- } else {
- return void 0 ;
- }
- } else {
- return element ;
- }
- };
- return myself ;
- };
+ function Tree (array) {
+ var index, myself, state;
+ index = 0 ;
+ state = [];
+ myself = function () {
+ var element, tempState;
+ element = array[index++];
+ if (element instanceof Array) {
+ state.push({
+ array: array,
+ index: index
+ });
+ array = element;
+ index = 0 ;
+ return myself();
+ } else if (element === void 0 ) {
+ if (state.length > 0 ) {
+ tempState = state.pop(), array = tempState.array, index = tempState.index;
+ return myself();
+ } else {
+ return void 0 ;
+ }
+ } else {
+ return element;
+ }
+ };
+ return myself;
+ };
- function K ( value ) {
- return function () {
- return value ;
- };
- };
+ function K (value) {
+ return function () {
+ return value;
+ };
+ };
- function upRange ( from , to , by ) {
- return function () {
- var was ;
+ function upRange (from, to, by) {
+ return function () {
+ var was;
- if ( from > to ) {
- return void 0 ;
- }
- else {
- was = from ;
- from = from + by ;
- return was ;
- }
- }
- };
+ if (from > to) {
+ return void 0 ;
+ }
+ else {
+ was = from;
+ from = from + by;
+ return was;
+ }
+ }
+ };
- function downRange ( from , to , by ) {
- return function () {
- var was ;
+ function downRange (from, to, by) {
+ return function () {
+ var was;
- if ( from < to ) {
- return void 0 ;
- }
- else {
- was = from ;
- from = from - by ;
- return was ;
- }
- }
- };
+ if (from < to) {
+ return void 0 ;
+ }
+ else {
+ was = from;
+ from = from - by;
+ return was;
+ }
+ };
+ };
- function range ( from , to , by ) {
- if ( from == null ) {
- return upRange ( 1 , Infinity , 1 );
- }
- else if ( to == null ) {
- return upRange ( from , Infinity , 1 );
- }
- else if ( by == null ) {
- if ( from <= to ) {
- return upRange ( from , to , 1 );
- }
- else return downRange ( from , to , 1 )
- }
- else if ( by > 0 ) {
- return upRange ( from , to , by );
- }
- else if ( by < 0 ) {
- return downRange ( from , to , Math . abs ( by ))
- }
- else return k ( from );
- };
+ function range (from, to, by) {
+ if (from == null ) {
+ return upRange(1 , Infinity , 1 );
+ }
+ else if (to == null ) {
+ return upRange(from, Infinity , 1 );
+ }
+ else if (by == null ) {
+ if (from <= to) {
+ return upRange(from, to, 1 );
+ }
+ else return downRange(from, to, 1 )
+ }
+ else if (by > 0 ) {
+ return upRange(from, to, by);
+ }
+ else if (by < 0 ) {
+ return downRange(from, to, Math.abs(by))
+ }
+ else return k(from);
+ };
- var numbers = unary ( range );
-
- _ . iterators = {
- accumulate : accumulate ,
- accumulateWithReturn : accumulateWithReturn ,
- foldl : foldl ,
- reduce : foldl ,
- unfold : unfold ,
- unfoldWithReturn : unfoldWithReturn ,
- map : map ,
- select : select ,
- reject : reject ,
- filter : select ,
- find : find ,
- slice : slice ,
- drop : drop ,
- take : take ,
- List : List ,
- Tree : Tree ,
- constant : K ,
- K : K ,
- numbers : numbers ,
- range : range
- };
+ var numbers = unary(range);
-})( this );
+ _.iterators = {
+ accumulate: accumulate,
+ accumulateWithReturn: accumulateWithReturn,
+ foldl: foldl,
+ reduce: foldl,
+ unfold: unfold,
+ unfoldWithReturn: unfoldWithReturn,
+ map: map,
+ select: select,
+ reject: reject,
+ filter: select,
+ find: find,
+ slice: slice,
+ drop: drop,
+ take: take,
+ List: List,
+ Tree: Tree,
+ constant: K,
+ K: K,
+ numbers: numbers,
+ range: range
+ };
-
+})(this );
diff --git a/docs/underscore.function.predicates.html b/docs/underscore.function.predicates.html
index 0258fb2..420c45f 100644
--- a/docs/underscore.function.predicates.html
+++ b/docs/underscore.function.predicates.html
@@ -19,6 +19,11 @@
-
+
@@ -110,8 +120,7 @@ underscore.function.predicates.js
-
-Baseline setup
+ Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,8 +148,7 @@ Baseline setup
-
-Helpers
+ Helpers
@@ -154,13 +161,10 @@ Helpers
-
-Mixing in the predicate functions
+ Mixing in the predicate functions
-
-
@@ -171,11 +175,9 @@ Mixing in the predicate functions
¶
-A wrapper around instanceof
-
- isInstanceOf : function ( x , t ) { return ( x instanceof t ); },
+
@@ -186,13 +188,11 @@ Mixing in the predicate functions
-
-An associative object is one where its elements are
-accessed via a key or index. (i.e. array and object)
+ A wrapper around instanceof
- isAssociative : function ( x ) { return _ . isArray ( x ) || _ . isObject ( x ) || _ . isArguments ( x ); },
+ isInstanceOf: function (x, t) { return (x instanceof t); },
@@ -203,16 +203,12 @@ Mixing in the predicate functions
-
-An indexed object is anything that allows numerical index for
-accessing its elements (e.g. arrays and strings). NOTE: Underscore
-does not support cross-browser consistent use of strings as array-like
-objects, so be wary in IE 8 when using String objects and IE<8.
-on string literals & objects.
+ An associative object is one where its elements are
+accessed via a key or index. (i.e. array and object)
- isIndexed : function ( x ) { return _ . isArray ( x ) || _ . isString ( x ) || _ . isArguments ( x ); },
+ isAssociative: function (x) { return _.isArray(x) || _.isObject(x) || _.isArguments(x); },
@@ -223,12 +219,15 @@ Mixing in the predicate functions
-
-A seq is something considered a sequential composite type (i.e. arrays and arguments).
+ An indexed object is anything that allows numerical index for
+accessing its elements (e.g. arrays and strings). NOTE: Underscore
+does not support cross-browser consistent use of strings as array-like
+objects, so be wary in IE 8 when using String objects and IE<8.
+on string literals & objects.
- isSequential : function ( x ) { return ( _ . isArray ( x )) || ( _ . isArguments ( x )); },
+ isIndexed: function (x) { return _.isArray(x) || _.isString(x) || _.isArguments(x); },
@@ -239,17 +238,11 @@ Mixing in the predicate functions
-
-These do what you think that they do
+ A seq is something considered a sequential composite type (i.e. arrays and arguments).
- isZero : function ( x ) { return 0 === x ; },
- isEven : function ( x ) { return _ . isFinite ( x ) && ( x & 1 ) === 0 ; },
- isOdd : function ( x ) { return _ . isFinite ( x ) && ! _ . isEven ( x ); },
- isPositive : function ( x ) { return x > 0 ; },
- isNegative : function ( x ) { return x < 0 ; },
- isValidDate : function ( x ) { return _ . isDate ( x ) && ! _ . isNaN ( x . getTime ()); },
+ isSequential: function (x) { return (_.isArray(x)) || (_.isArguments(x)); },
@@ -260,16 +253,16 @@ Mixing in the predicate functions
-
-A numeric is a variable that contains a numeric value, regardless its type
-It can be a String containing a numeric value, exponential notation, or a Number object
-See here for more discussion: http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric/1830844#1830844
+ These do what you think that they do
- isNumeric : function ( n ) {
- return ! isNaN ( parseFloat ( n )) && isFinite ( n );
- },
+ isZero: function (x) { return 0 === x; },
+ isEven: function (x) { return _.isFinite(x) && (x & 1 ) === 0 ; },
+ isOdd: function (x) { return _.isFinite(x) && !_.isEven(x); },
+ isPositive: function (x) { return x > 0 ; },
+ isNegative: function (x) { return x < 0 ; },
+ isValidDate: function (x) { return _.isDate(x) && !_.isNaN(x.getTime()); },
@@ -280,17 +273,15 @@ Mixing in the predicate functions
-
-An integer contains an optional minus sign to begin and only the digits 0-9
-Objects that can be parsed that way are also considered ints, e.g. "123"
-Floats that are mathematically equal to integers are considered integers, e.g. 1.0
-See here for more discussion: http://stackoverflow.com/questions/1019515/javascript-test-for-an-integer
+ A numeric is a variable that contains a numeric value, regardless its type
+It can be a String containing a numeric value, exponential notation, or a Number object
+See here for more discussion: http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric/1830844#1830844
- isInteger : function ( i ) {
- return _ . isNumeric ( i ) && i % 1 === 0 ;
- },
+ isNumeric: function (n) {
+ return !isNaN(parseFloat(n)) && isFinite(n);
+ },
@@ -301,14 +292,16 @@ Mixing in the predicate functions
-
-A float is a numbr that is not an integer.
+ An integer contains an optional minus sign to begin and only the digits 0-9
+Objects that can be parsed that way are also considered ints, e.g. "123"
+Floats that are mathematically equal to integers are considered integers, e.g. 1.0
+See here for more discussion: http://stackoverflow.com/questions/1019515/javascript-test-for-an-integer
- isFloat : function ( n ) {
- return _ . isNumeric ( n ) && ! _ . isInteger ( n );
- },
+ isInteger: function (i) {
+ return _.isNumeric(i) && i % 1 === 0 ;
+ },
@@ -319,59 +312,72 @@ Mixing in the predicate functions
+ A float is a numbr that is not an integer.
+
+
+
+ isFloat: function (n) {
+ return _.isNumeric(n) && !_.isInteger(n);
+ },
+
+
+
+
+
+
-
Returns true if its arguments are monotonically
+
+
Returns true if its arguments are monotonically
increaing values; false otherwise.
- isIncreasing : function () {
- var count = _ . size ( arguments );
- if ( count === 1 ) return true ;
- if ( count === 2 ) return arguments [ 0 ] < arguments [ 1 ];
+ isIncreasing: function () {
+ var count = _.size(arguments);
+ if (count === 1 ) return true ;
+ if (count === 2 ) return arguments[0 ] < arguments[1 ];
- for ( var i = 1 ; i < count ; i ++ ) {
- if ( arguments [ i - 1 ] >= arguments [ i ]) {
- return false ;
- }
- }
+ for (var i = 1 ; i < count; i++) {
+ if (arguments[i-1 ] >= arguments[i]) {
+ return false ;
+ }
+ }
- return true ;
- },
+ return true ;
+ },
-
+
-
-
Returns true if its arguments are monotonically
+
Returns true if its arguments are monotonically
decreaing values; false otherwise.
- isDecreasing : function () {
- var count = _ . size ( arguments );
- if ( count === 1 ) return true ;
- if ( count === 2 ) return arguments [ 0 ] > arguments [ 1 ];
-
- for ( var i = 1 ; i < count ; i ++ ) {
- if ( arguments [ i - 1 ] <= arguments [ i ]) {
- return false ;
- }
- }
+ isDecreasing: function () {
+ var count = _.size(arguments);
+ if (count === 1 ) return true ;
+ if (count === 2 ) return arguments[0 ] > arguments[1 ];
- return true ;
- }
- });
+ for (var i = 1 ; i < count; i++) {
+ if (arguments[i-1 ] <= arguments[i]) {
+ return false ;
+ }
+ }
-})( this );
+ return true ;
+ }
+ });
-
+})(this );
diff --git a/docs/underscore.object.builders.html b/docs/underscore.object.builders.html
index 14d56fb..c6e868b 100644
--- a/docs/underscore.object.builders.html
+++ b/docs/underscore.object.builders.html
@@ -19,6 +19,11 @@
-
+
@@ -110,8 +120,7 @@ underscore.object.builders.js
-
-Baseline setup
+ Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,8 +148,7 @@ Baseline setup
-
-Helpers
+ Helpers
@@ -154,25 +161,23 @@ Helpers
-
-Create quick reference variables for speed access to core prototypes.
+ Create quick reference variables for speed access to core prototypes.
- var slice = Array . prototype . slice ,
- concat = Array . prototype . concat ;
+ var slice = Array.prototype.slice,
+ concat = Array.prototype.concat;
- var existy = function ( x ) { return x != null ; };
- var truthy = function ( x ) { return ( x !== false ) && existy ( x ); };
- var isAssociative = function ( x ) { return _ . isArray ( x ) || _ . isObject ( x ); };
- var curry2 = function ( fun ) {
- return function ( last ) {
- return function ( first ) {
- return fun ( first , last );
- };
- };
- };
-
+ var existy = function (x) { return x != null ; };
+ var truthy = function (x) { return (x !== false ) && existy(x); };
+ var isAssociative = function (x) { return _.isArray(x) || _.isObject(x); };
+ var curry2 = function (fun) {
+ return function (last) {
+ return function (first) {
+ return fun(first, last);
+ };
+ };
+ };
@@ -183,13 +188,10 @@ Helpers
-
-Mixing in the object builders
+ Mixing in the object builders
-
-
@@ -200,90 +202,100 @@ Mixing in the object builders
¶
-Merges two or more objects starting with the left-most and
+
+
+
+
+
+
+
+
+
+
+
+
Merges two or more objects starting with the left-most and
applying the keys right-word
{any:any}* -> {any:any}
- merge : function ( /* objs */ ){
- var dest = _ . some ( arguments ) ? {} : null ;
+ merge: function (){
+ var dest = _.some(arguments) ? {} : null ;
- if ( truthy ( dest )) {
- _ . extend . apply ( null , concat . call ([ dest ], _ . toArray ( arguments )));
- }
+ if (truthy(dest)) {
+ _.extend.apply(null , concat.call([dest], _.toArray(arguments)));
+ }
- return dest ;
- },
+ return dest;
+ },
-
+
-
-
Takes an object and another object of strings to strings where the second
+
Takes an object and another object of strings to strings where the second
object describes the key renaming to occur in the first object.
- renameKeys : function ( obj , kobj ) {
- return _ . reduce ( kobj , function ( o , nu , old ) {
- if ( existy ( obj [ old ])) {
- o [ nu ] = obj [ old ];
- return o ;
- }
- else
- return o ;
- },
- _ . omit . apply ( null , concat . call ([ obj ], _ . keys ( kobj ))));
- },
+ renameKeys: function (obj, kobj) {
+ return _.reduce(kobj, function (o, nu, old) {
+ if (existy(obj[old])) {
+ o[nu] = obj[old];
+ return o;
+ }
+ else
+ return o;
+ },
+ _.omit.apply(null , concat.call([obj], _.keys(kobj))));
+ },
-
+
-
-
Snapshots an object deeply. Based on the version by
+
Snapshots an object deeply. Based on the version by
Keith Devens
until we can find a more efficient and robust way to do it.
- snapshot : function ( obj ) {
- if ( obj == null || typeof ( obj ) != 'object' ) {
- return obj ;
- }
+ snapshot: function (obj) {
+ if (obj == null || typeof (obj) != 'object' ) {
+ return obj;
+ }
- var temp = new obj . constructor ();
+ var temp = new obj.constructor();
- for ( var key in obj ) {
- temp [ key ] = _ . snapshot ( obj [ key ]);
- }
+ for (var key in obj) {
+ temp[key] = _.snapshot(obj[key]);
+ }
- return temp ;
- },
+ return temp;
+ },
-
+
-
-
Updates the value at any depth in a nested object based on the
+
Updates the value at any depth in a nested object based on the
path described by the keys given. The function provided is supplied
the current value and is expected to return a value for use as the
new value. If no keys are provided, then the object itself is presented
@@ -291,66 +303,62 @@
Mixing in the object builders
- updatePath : function ( obj , fun , ks ) {
- if ( ! isAssociative ( obj )) throw new TypeError ( "Attempted to update a non-associative object." );
- if ( ! existy ( ks )) return fun ( obj );
+ updatePath: function (obj, fun, ks) {
+ if (!isAssociative(obj)) throw new TypeError("Attempted to update a non-associative object." );
+ if (!existy(ks)) return fun(obj);
- var deepness = _ . isArray ( ks );
- var keys = deepness ? ks : [ ks ];
- var ret = deepness ? _ . snapshot ( obj ) : _ . clone ( obj );
- var lastKey = _ . last ( keys );
- var target = ret ;
+ var deepness = _.isArray(ks);
+ var keys = deepness ? ks : [ks];
+ var ret = deepness ? _.snapshot(obj) : _.clone(obj);
+ var lastKey = _.last(keys);
+ var target = ret;
- _ . each ( _ . initial ( keys ), function ( key ) {
- target = target [ key ];
- });
+ _.each(_.initial(keys), function (key) {
+ target = target[key];
+ });
- target [ lastKey ] = fun ( target [ lastKey ]);
- return ret ;
- },
+ target[lastKey] = fun(target[lastKey]);
+ return ret;
+ },
-
+
-
-
Sets the value at any depth in a nested object based on the
+
Sets the value at any depth in a nested object based on the
path described by the keys given.
- setPath : function ( obj , value , ks ) {
- if ( ! existy ( ks )) throw new TypeError ( "Attempted to set a property at a null path." );
+ setPath: function (obj, value, ks) {
+ if (!existy(ks)) throw new TypeError("Attempted to set a property at a null path." );
- return _ . updatePath ( obj , function () { return value ; }, ks );
- },
+ return _.updatePath(obj, function () { return value; }, ks);
+ },
-
+
-
-
Returns an object where each element of an array is keyed to
+
Returns an object where each element of an array is keyed to
the number of times that it occurred in said array.
- frequencies : curry2 ( _ . countBy )( _ . identity )
- });
-
-})( this );
+ frequencies: curry2(_.countBy)(_.identity)
+ });
-
+})(this );
diff --git a/docs/underscore.object.selectors.html b/docs/underscore.object.selectors.html
index bdc79a0..7b70e8f 100644
--- a/docs/underscore.object.selectors.html
+++ b/docs/underscore.object.selectors.html
@@ -19,6 +19,11 @@
-
+
@@ -110,8 +120,7 @@ underscore.object.selectors.js
-
-Baseline setup
+ Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,8 +148,7 @@ Baseline setup
-
-Helpers
+ Helpers
@@ -154,12 +161,11 @@ Helpers
-
-Create quick reference variables for speed access to core prototypes.
+ Create quick reference variables for speed access to core prototypes.
- var concat = Array . prototype . concat ;
+ var concat = Array.prototype.concat;
@@ -170,13 +176,10 @@ Helpers
-
-Mixing in the object selectors
+ Mixing in the object selectors
-
-
@@ -187,16 +190,9 @@ Mixing in the object selectors
¶
-Returns a function that will attempt to look up a named field
-in any object that it's given.
-
- accessor : function ( field ) {
- return function ( obj ) {
- return ( obj && obj [ field ]);
- };
- },
+
@@ -207,19 +203,170 @@ Mixing in the object selectors
+ Returns a function that will attempt to look up a named field
+in any object that it's given.
+
+
+
+ accessor: function (field) {
+ return function (obj) {
+ return (obj && obj[field]);
+ };
+ },
+
+
+
+
+
+
+
+
+
Given an object, returns a function that will attempt to look up a field
+that it's given.
+
+
+
+ dictionary: function (obj) {
+ return function (field) {
+ return (obj && field && obj[field]);
+ };
+ },
+
+
+
+
+
+
+
+
+
Like _.pick except that it takes an array of keys to pick.
+
+
+
+ selectKeys: function (obj, ks) {
+ return _.pick.apply(null , concat.call([obj], ks));
+ },
+
+
+
+
+
+
-
Like _.pick except that it takes an array of keys to pick.
+
+
Returns the key/value pair for a given property in an object, undefined if not found.
- selectKeys : function ( obj , ks ) {
- return _ . pick . apply ( null , concat . call ([ obj ], ks ));
- }
- });
+ kv: function (obj, key) {
+ if (_.has(obj, key)) {
+ return [key, obj[key]];
+ }
+
+ return void 0 ;
+ },
+
+
+
+
+
+
+
+
+
Gets the value at any depth in a nested object based on the
+path described by the keys given.
+
+
+
+ getPath: function getPath (obj, ks) {
+
+
+
+
+
+
+
+
+
If we have reached an undefined property
+then stop executing and return undefined
+
+
+
+ if (obj === undefined ) return void 0 ;
+
+
+
+
+
+
+
+
+
If the path array has no more elements, we've reached
+the intended property and return its value
+
+
+
+ if (ks.length === 0 ) return obj;
+
+
+
+
+
+
+
+
+
If we still have elements in the path array and the current
+value is null, stop executing and return undefined
+
+
+
+ if (obj === null ) return void 0 ;
+
+ return getPath(obj[[].shift.call(ks)], ks);
+ },
+
+
+
+
+
+
+
+
+
Returns a boolean indicating whether there is a property
+at the path described by the keys given
+
+
+
+ hasPath: function hasPath (obj, ks) {
+ var numKeys = ks.length;
+
+ if (obj == null && numKeys > 0 ) return false ;
+
+ if (!(ks[0 ] in obj)) return false ;
+
+ if (numKeys === 1 ) return true ;
-})( this );
+ return hasPath(obj[[].shift.call(ks)], ks);
+ }
+ });
-
+})(this );
diff --git a/docs/underscore.util.existential.html b/docs/underscore.util.existential.html
index 887d489..28d716d 100644
--- a/docs/underscore.util.existential.html
+++ b/docs/underscore.util.existential.html
@@ -19,6 +19,11 @@
-
+
@@ -110,8 +120,7 @@ underscore.util.existential.js
-
-Baseline setup
+ Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,8 +148,7 @@ Baseline setup
-
-Helpers
+ Helpers
@@ -151,24 +158,45 @@ Helpers
-
+
-
Mixing in the truthiness
-
-
_ . mixin ({
- exists : function ( x ) { return x != null ; },
- truthy : function ( x ) { return ( x !== false ) && _ . exists ( x ); },
- falsey : function ( x ) { return ! _ . truthy ( x ); },
- not : function ( b ) { return ! b ; }
- });
+
+
+
+
+
+
+
+
Mixing in the truthiness
-
})( this );
+
+
+
+
+
+
+
+
+ _.mixin({
+ exists: function (x) { return x != null ; },
+ truthy: function (x) { return (x !== false ) && _.exists(x); },
+ falsey: function (x) { return !_.truthy(x); },
+ not: function (b) { return !b; }
+ });
-
+})(this );
diff --git a/docs/underscore.util.strings.html b/docs/underscore.util.strings.html
index 145efee..3cf074f 100644
--- a/docs/underscore.util.strings.html
+++ b/docs/underscore.util.strings.html
@@ -19,6 +19,11 @@
+
+ index.js
+
+
+
underscore.array.builders.js
@@ -29,6 +34,11 @@
+
+ underscore.collections.walk.js
+
+
+
underscore.function.arity.js
@@ -93,13 +103,13 @@
underscore.util.strings.js
-
Underscore-contrib (underscore.array.builders.js 0.0.1)
+
Underscore-contrib (underscore.util.strings.js 0.0.1)
(c) 2013 Michael Fogus, DocumentCloud and Investigative Reporters & Editors
Underscore-contrib may be freely distributed under the MIT license.
-
+
@@ -110,8 +120,7 @@
underscore.util.strings.js
-
-
Baseline setup
+
Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,8 +148,7 @@ Baseline setup
-
-Helpers
+ Helpers
@@ -154,13 +161,10 @@ Helpers
-
-Mixing in the array builders
+ Mixing in the string utils
-
-
@@ -171,13 +175,9 @@ Mixing in the array builders
¶
-Explodes a string into an array of chars
-
- explode : function ( s ) {
- return s . split ( '' );
- },
+
@@ -188,18 +188,32 @@ Mixing in the array builders
-
-Implodes and array of chars into a string
+ Explodes a string into an array of chars
- implode : function ( a ) {
- return a . join ( '' );
- }
- });
-})( this );
+ explode: function (s) {
+ return s.split('' );
+ },
+
+
+
+
+
+
+
+
+
Implodes and array of chars into a string
-
+
+
+ implode: function (a) {
+ return a.join('' );
+ }
+ });
+})(this );
diff --git a/docs/underscore.util.trampolines.html b/docs/underscore.util.trampolines.html
index bd784a2..9eb8b75 100644
--- a/docs/underscore.util.trampolines.html
+++ b/docs/underscore.util.trampolines.html
@@ -19,6 +19,11 @@
-
+
@@ -110,8 +120,7 @@ underscore.util.trampolines.js
-
-Baseline setup
+ Baseline setup
@@ -124,12 +133,11 @@ Baseline setup
-
-Establish the root object, window in the browser, or global on the server.
+ Establish the root object, window in the browser, or global on the server.
- var _ = root . _ || require ( 'underscore' );
+ var _ = root._ || require('underscore' );
@@ -140,8 +148,7 @@ Baseline setup
-
-Helpers
+ Helpers
@@ -151,36 +158,57 @@ Helpers
-
+
-
Mixing in the truthiness
-
-
_ . mixin ({
- done : function ( value ) {
- var ret = _ ( value );
- ret . stopTrampoline = true ;
- return ret ;
- },
+
+
+
+
+
+
+
+
Mixing in the truthiness
-
trampoline : function ( fun /*, args */ ) {
-
var result = fun . apply ( fun , _ . rest ( arguments ));
+
+
+
+
+
+
+
+
+ _.mixin({
+ done: function (value) {
+ var ret = _(value);
+ ret.stopTrampoline = true ;
+ return ret;
+ },
- while ( _ . isFunction ( result )) {
- result = result ();
- if (( result instanceof _ ) && ( result . stopTrampoline )) break ;
- }
+ trampoline: function (fun ) {
+ var result = fun.apply(fun, _.rest(arguments));
- return result . value ();
- }
- });
+ while (_.isFunction(result)) {
+ result = result();
+ if ((result instanceof _) && (result.stopTrampoline)) break ;
+ }
-})( this );
+ return result.value();
+ }
+ });
-
+})(this );
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..de9ea08
--- /dev/null
+++ b/index.html
@@ -0,0 +1,131 @@
+
+
+
+
+
index.js
+
+
+
+
+
+
+
+
+
+
+ Jump To …
+ +
+
+
+
+
+
+
+
+
+
+
index.js
+
+
+
+
+
+
+
+
+ ['array.builders' ,
+ 'array.selectors' ,
+ 'collections.walk' ,
+ 'function.arity' ,
+ 'function.combinators' ,
+ 'function.iterators' ,
+ 'function.predicates' ,
+ 'object.builders' ,
+ 'object.selectors' ,
+ 'util.existential' ,
+ 'util.strings' ,
+ 'util.trampolines' ].forEach(function (lib) {
+ require('./underscore.' +lib);
+ });
+
+module.exports = require('underscore' );
+
+
+
+
+
+
+