New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nodash

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodash - npm Package Compare versions

Comparing version 0.9.2 to 0.10.0

.jshintrc

2

benchmark/index.js

@@ -5,3 +5,3 @@ /* vim: set et sw=2 ts=2: */

var benchmark = require('./benchmark');
var benchmark = require('../util/benchmark');
var underscore = require('underscore');

@@ -8,0 +8,0 @@ var nodash = require('../nodash.js');

Changelog
=========
v0.3 "Amdahl"

@@ -12,2 +13,3 @@ -------------

v0.4 "Babbage"

@@ -24,2 +26,3 @@ --------------

v0.5 "Curry"

@@ -37,2 +40,3 @@ ------------

v0.6 "Dijkstra"

@@ -53,2 +57,3 @@ ----------------

v0.7 "Eich"

@@ -68,2 +73,3 @@ -----------

v0.8 "Floyd"

@@ -92,2 +98,3 @@ ------------

v0.9 "Gosling"

@@ -120,3 +127,53 @@ --------------

+ `curry` and `uncurry` added
+ *experimental:* `curry` and `uncurry` added
v0.10 "Hollerith"
-----------------
**Breaking Changes:**
+ Tuples are no longer implemented by arrays but by a class
- `fst` and `snd` therefore no longer work with arrays but with Tuples only
+ Streams and infinite Lists were completely revamped. This affects:
- `lazy` generates a `List`
- `stream` takes a generator now and generates a `Stream`
- Functions dealing with old streams are updated to handle `List` and `Stream`
- `List` and `Stream` have laziness built in by using `Thunk` internally
+ `Either` is now a proper type
- Functions dealing with `Either` are updated accordingly
+ `consume` and `consumeString` removed in favor of `listToArray` and `listToString`
+ `run` was adapted to fit the node convention of passing the error in the
first argument
**Additions:**
+ `List` added, along with `listToArray` and `listToString`
- has the methods `head`, `tail`, and `isEmpty`
+ `Stream` added
- has the same interface as `List` but designates infinite Lists
+ `Tuple` added
- has the methods `fst` and `snd`
- Triples are tuples of tuples `(a, (b, c))`
+ `Either` type added, with constructors `Left` and `Right`
+ `isInteger` added - checks whether something is an integral number
+ `isBoolean` added - checks whether something is a boolean
+ `isUndefined` added - checks whether something is undefined
+ `is` added - flipped shorthand version of `instanceof`
+ `range` and `rangeStep` added - returns lazy lists for the given range
**Other Changes:**
+ Nodash is now built using [browserify](https://github.com/substack/node-browserify)
+ Legacy code like shims for `Array.isArray` and `Object.keys` were removed
- If you want to support pre-ES5 environments pull in [es5-shim](https://github.com/es-shims/es5-shim)
+ The documentation system has been revamped
v0.11 "Ichbiah"
---------------
v0.12 "Joy"
-----------
/* vim: set et sw=2 ts=2: */
/* jshint node: true */
"use strict";
'use strict';
var thresholds = {
statements: 99,
branches: 98,
functions: 100,
branches: 97,
functions: 99,
lines: 99

@@ -16,4 +15,4 @@ };

mustache = require('gulp-mustache'),
preprocess = require('gulp-preprocess'),
sourcemaps = require('gulp-sourcemaps'),
filenames = require('gulp-filenames'),
markdown = require('gulp-markdown'),

@@ -25,8 +24,10 @@ istanbul = require('gulp-istanbul'),

rename = require('gulp-rename'),
docco = require('gulp-docco'),
less = require('gulp-less'),
gzip = require('gulp-gzip'),
docco = require('docco'),
chalk = require('chalk'),
gzip = require('gulp-gzip'),
buffer = require('vinyl-buffer'),
source = require('vinyl-source-stream'),
fs = require('fs'),
apidoc = require('./documentation.js'),
browserify = require('browserify'),
filesize = require('filesize'),

@@ -40,3 +41,3 @@ gulp = require('gulp');

plugins: [
new LessPluginAutoprefix({ browsers: [ "last 2 versions" ]}),
new LessPluginAutoprefix({ browsers: [ 'last 2 versions' ]}),
new LessPluginCleanCSS({ advanced: true })

@@ -48,2 +49,4 @@ ]

var sources = [ 'nodash.js', 'lib/**/*.js' ];
function errorHandler(err) {

@@ -54,17 +57,18 @@ console.log(chalk.red(err.message));

gulp.task('minify', [ 'lint' ], function (done) {
gulp.src('nodash.js')
.pipe(sourcemaps.init())
.pipe(preprocess())
.pipe(uglify({ compressor: { global_defs: { group: true } } }))
.pipe(replace(/(group\(('[^']*'|"[^"]*")(,function\(\)\{\})?\),?)/g, ""))
.pipe(replace(/composed\(function\(\)\{return ([^}]+)\}\)/g, "$1"))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist/'))
.on('error', errorHandler)
.on('finish', done);
gulp.task('browserify', [ 'lint' ], function (done) {
browserify({
entries: [ 'nodash.js' ]
}).bundle()
.pipe(source('nodash.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify({}))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'))
.on('error', errorHandler)
.on('finish', done);
});
gulp.task('gzip', [ 'minify' ], function (done) {
gulp.task('gzip', [ 'browserify' ], function (done) {
gulp.src('dist/nodash.min.js')

@@ -77,3 +81,3 @@ .pipe(gzip({ append: true, gzipOptions: { level: 9 } }))

gulp.task('lint', function (done) {
gulp.src([ 'nodash.js', 'test/*.js', 'benchmark/*.js' ])
gulp.src([ 'nodash.js', 'lib/**/*.js', 'util/**/*.js', 'test/**/*.js', 'benchmark/*.js' ])
.pipe(jshint())

@@ -87,3 +91,3 @@ .pipe(jshint.reporter('default'))

gulp.task('coverage', [ 'lint' ], function (done) {
gulp.src('nodash.js')
gulp.src(sources)
.pipe(istanbul())

@@ -93,7 +97,7 @@ .pipe(istanbul.hookRequire())

.on('finish', function () {
gulp.src('test/*.js')
gulp.src('test/**/*.js')
.pipe(mocha())
.pipe(istanbul.writeReports({ dir: 'dist/coverage/' }))
.on('finish', done);
});
});
});

@@ -113,9 +117,9 @@

// test minified library
gulp.task('testm', [ 'test', 'minify' ], function (done) {
gulp.src('test/*.js')
.pipe(replace('../nodash', '../dist/nodash.min'))
.pipe(gulp.dest('testm/'))
// test browserified + minified library
gulp.task('testm', [ 'test', 'browserify' ], function (done) {
gulp.src('test/**/*.js')
.pipe(replace('../nodash', '../nodash-testm'))
.pipe(gulp.dest('testm'))
.on('finish', function () {
gulp.src('testm/*.js')
gulp.src('testm/**/*.js')
.pipe(mocha())

@@ -128,6 +132,17 @@ .on('error', errorHandler)

gulp.task('docco', [ 'lint' ], function (done) {
gulp.src('nodash.js')
.pipe(docco())
.pipe(gulp.dest('dist/docco/'))
.on('finish', done);
gulp.src(sources)
.pipe(filenames('javascript'))
.pipe(gulp.dest('./dist/source'))
.on('finish', function () {
var args = [
'node', 'docco',
'-o', 'dist/docco',
'-l', 'classic'
].concat(filenames.get('javascript', 'full'));
docco.run(args);
done();
});
});

@@ -143,9 +158,12 @@

gulp.task('apidoc', [ 'styles', 'lint' ], function (done) {
var library = require('./nodash.js');
var apidoc = require('./util/apidoc');
gulp.src('site/apidoc.mustache')
.pipe(mustache(apidoc(library.metadata)))
.pipe(rename({ extname: ".html" }))
.pipe(gulp.dest('dist/'))
.on('finish', done);
apidoc('./doc', function (error, documentationData) {
gulp.src('site/apidoc.mustache')
.pipe(mustache(documentationData))
.pipe(rename({ extname: ".html" }))
.pipe(gulp.dest('dist/'))
.on('finish', done);
});
});

@@ -158,11 +176,10 @@

.on('finish', function () {
var variables = {
MINIFIED_SIZE: filesize(fs.statSync('dist/nodash.min.js').size),
GZIPPED_SIZE: filesize(fs.statSync('dist/nodash.min.js.gz').size),
VERSION: npmPackage.version,
TODAY: new Date().toISOString().substring(0, 10)
};
npmPackage.readme = fs.readFileSync('./dist/README.html', 'utf8');
npmPackage.minifiedSize = filesize(fs.statSync('dist/nodash.min.js').size);
npmPackage.gzippedSize = filesize(fs.statSync('dist/nodash.min.js.gz').size);
npmPackage.today = new Date().toISOString().substring(0, 10);
gulp.src('site/*.html')
.pipe(preprocess({ context: variables }))
.pipe(mustache(npmPackage))
.pipe(gulp.dest('dist/'))

@@ -178,7 +195,8 @@ .on('finish', done);

gulp.task('build', [ 'minify', 'testm', 'gzip' ]);
gulp.task('build', [ 'browserify', 'testm', 'gzip' ]);
gulp.task('default', [ 'site', ], function (done) {
gulp.task('default', [ 'build', ], function (done) {
var minified = filesize(fs.statSync('dist/nodash.min.js').size);
var gzipped = filesize(fs.statSync('dist/nodash.min.js.gz').size);

@@ -191,12 +209,12 @@ console.log(chalk.white((function(){/*

It passed all test cases and achieved a good code coverage.
In total it is a whopping MINIFIED minified. Note that the
minified version has also been dragged through all the test
cases and passed without a doubt.
In total it is a whopping MINIFIED minified (GZIPPED gzipped).
Note that the minified version has also been dragged through
all the test cases and passed without a doubt.
*/}).toString()
.slice(14, -3)
.replace("CHECKMARK", chalk.green("✓"))
.replace("MINIFIED", chalk.yellow(minified))
.replace('CHECKMARK', chalk.green('✓'))
.replace('MINIFIED', chalk.yellow(minified))
.replace('GZIPPED', chalk.yellow(gzipped))
));
});
/* vim: set et sw=2 ts=2: */
(function () {
// Save a reference to `Set` (if defined). Otherwise this variable will
// be `undefined`. References to some native types (`Math`, `Array`,
// `Object`) are kept here so that native objects can be distinguished
// from local polyfills.
var NativeSet = typeof Set !== 'undefined' && Set;
var NativeMath = Math;
var NativeArray = Array;
var NativeObject = Object;
var NativeString = String;
function makeNodash(options) {
'use strict';
//function install(Nodash, Math, Array, Object, dontUseNatives, refObj, undefined) {
function makeNodash(options, undefined) {
"use strict";
options = options || {};
// This is the object the nodash functions will be attached to.
var Nodash = {};
// Basic ECMA Script 5 checks (if these fail pull in `es5-shim`).
// Use either the supplied objects from the arguments,
// or the references saved above.
var Math = options.Math || NativeMath;
var Array = options.Array || NativeArray;
var Object = options.Object || NativeObject;
var String = options.String || NativeString;
function showEndOfStream() {
return "end of stream";
if (typeof Object.keys !== 'function' || Object.keys({ x: 7 })[0] !== 'x' ||
typeof Array.isArray !== 'function' || !Array.isArray([]) ||
typeof Array.prototype.forEach !== 'function') {
throw new Error('ES5 environment required (`es5-shim` will do).');
}
var eos = {
toString: showEndOfStream,
inspect: showEndOfStream
};
Nodash.endOfStream = eos;
var stream = {};
function mkStream(f) {
f.__stream__ = stream;
return f;
}
function isStream(x) { return isFunction(x) && x.__stream__ === stream; }
function mkInfinite(f) {
f = mkStream(f);
f.__infinite__ = true;
return f;
}
function isInfinite(f) {
return !!f.__infinite__;
}
function checkFinite(xs) {
if (isInfinite(xs)) {
throw new Error('this function can not consume infinite streams');
}
}
// `isArray` checks whether a thing is actually an array object.
// If `Array.isArray` is not available in this environment it will
// fall back to comparing the toString representation. The `toString`
// method used is the one from the `NativeObject` to make sure that
// client code can not temper with an object and make it look like an
// array. The fallback is necessary to cope with legacy browser
// environments.
var isArray = Array.isArray || function _isArray(arr) {
return NativeObject.prototype.toString.call(arr) === '[object Array]';
};
// `isObject` checks whether a thing is an object and neither an
// array nor null.
var isObject = function _isObject(obj) {
if (typeof obj === 'object') {
return obj !== null && !isArray(obj);
}
return false;
};
// Utility functions for checking basic JavaScript types.
function isFunction(x) { return typeof x === 'function'; }
function isString(x) { return typeof x === 'string'; }
function isNumber(x) { return typeof x === 'number'; }
function isNodash(f) { return isFunction(f) && f.__isNodash; }
function isNumeric(x) { return /^[0-9]+$/.test(x); }
// Enumerates the keys of an object. If `Object.keys` is not availabe,
// fall back to a polyfill. The polyfill is so hilariously big to cope
// with oddities in IE 8 (the "don't enum bug").
var keys = Object.keys || (function() {
var hasOwnProperty = NativeObject.prototype.hasOwnProperty,
hasDontEnumBug = !(options.refObj || { toString: null }).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;
return function _Object_keys(obj) {
var result = [], prop, i;
for (prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
result.push(prop);
}
}
if (hasDontEnumBug) {
for (i = 0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) {
result.push(dontEnums[i]);
}
}
}
return result;
};
}());
// Either use the native set or (if `dontUseNatives` is `true` or
// there is no native set implementation) a drop-in replacement.
// It reproduces only the actually used functionality, which is
// `add` and `has`. It uses the keys of an object to simulate the Set.
var Set = (!options.dontUseNatives && NativeSet) || (function () {
var Set = function () {
this.xs = {};
};
Set.prototype.add = function _Set_add(value) {
this.xs[value] = true;
return this;
};
Set.prototype.has = function _Set_has(value) {
return this.xs[value] === true;
};
return Set;
}());
// A function to postpone an action on the event queue
var trampoline = function (f) { setTimeout(f, 0); };
if (!options.dontUseNatives && typeof(setImmediate) === 'function') {
trampoline = setImmediate;
}
// The identity function that returns what was passed in unaltered.
function id(x) { return x; }
// A handy shorthand to reduce a list to a string.
function listToString(x) { return x.join(''); }
// `indexOf` uses an implementation of the Knuth-Morrison-Pratt
// Algorithm for finding the index of a given subsequence
// (identified as `word` here) within a sequence (identified as
// `string` here). Thanks to JavaScript's dynamic nature it
// works equally well with strings and arrays.
function indexOf(word, string) {
var m = 0;
var i = 0;
var table = [];
var pos = 2;
var cnd = 0;
table[0] = -1;
table[1] = 0;
// build the table for KMP. This takes `O(word.length)` steps.
while (pos < word.length) {
if (word[pos - 1] == word[cnd]) {
cnd = cnd + 1;
table[pos] = cnd;
pos = pos + 1;
} else if (cnd > 0) {
cnd = table[cnd];
} else {
table[pos] = 0;
pos = pos + 1;
}
}
// scan the string. This takes `O(string.length)` steps.
while (m + i < string.length) {
if (word[i] == string[m + i]) {
if (i == word.length - 1) {
return m;
}
i = i + 1;
} else {
if (table[i] > -1) {
m = m + i - table[i];
i = table[i];
} else {
i = 0;
m = m + 1;
}
}
}
// Returns -1 if the subsequence was not found in the sequence.
return -1;
}
// ## Partial application
//
// While partial application of functions can be implemented easily
// using JavaScript's `bind` or `apply` functions, it is more
// efficient to use closures as JavaScript's native functions
// additionally do some heavy error checking and deal with `this`.
//
// Partial application of functions relies on the `length` reported
// by a function. A correct partial application returns a function
// with a length
// `length of function which is applied MINUS number of arguments consumed`.
// Unfortunately this means we need to have some biolerplate code for
// every arity of functions and results, thus the big blob of code
// below.
var funcs = {
0: id,
1: id,
2: function (fn) {
return function (a, b) {
switch (arguments.length) {
case 1:
return function (b) {
return fn(a, b);
};
}
return fn(a, b);
};
},
3: function (fn) {
return function (a, b, c) {
switch (arguments.length) {
case 1:
return funcs[2](function (b, c) {
return fn(a, b, c);
});
case 2:
return function (c) {
return fn(a, b, c);
};
}
return fn(a, b, c);
};
},
4: function (fn) {
return function (a, b, c, d) {
switch (arguments.length) {
case 1:
return funcs[3](function (b, c, d) {
return fn(a, b, c, d);
});
case 2:
return funcs[2](function (c, d) {
return fn(a, b, c, d);
});
case 3:
return function (d) {
return fn(a, b, c, d);
};
}
return fn(a, b, c, d);
};
},
5: function (fn) {
return function (a, b, c, d, e) {
switch (arguments.length) {
case 1:
return funcs[4](function (b, c, d, e) {
return fn(a, b, c, d, e);
});
case 2:
return funcs[3](function (c, d, e) {
return fn(a, b, c, d, e);
});
case 3:
return funcs[2](function (d, e) {
return fn(a, b, c, d, e);
});
case 4:
return function (e) {
return fn(a, b, c, d, e);
};
}
return fn(a, b, c, d, e);
};
},
6: function (fn) {
return function (a, b, c, d, e, f) {
switch (arguments.length) {
case 1:
return funcs[5](function (b, c, d, e, f) {
return fn(a, b, c, d, e, f);
});
case 2:
return funcs[4](function (c, d, e, f) {
return fn(a, b, c, d, e, f);
});
case 3:
return funcs[3](function (d, e, f) {
return fn(a, b, c, d, e, f);
});
case 4:
return funcs[2](function (e, f) {
return fn(a, b, c, d, e, f);
});
case 5:
return function (f) {
return fn(a, b, c, d, e, f);
};
}
return fn(a, b, c, d, e, f);
};
}
};
// Turns an ordinary function into a function which can be partially applied.
// The maximum arity that this can deal with is 8 (see above).
function curried(fn) {
return funcs[fn.length](fn);
}
/* @ifdef WITH_ONLINE_HELP */
Nodash.metadata = [];
/* @endif */
var currentGroup = "";
/* @ifdef WITH_ONLINE_HELP */
function group(name, desc) {
currentGroup = { name: name };
}
function callsites() {
var _ = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, stack) { return stack; };
var stack = new Error().stack.slice(1);
Error.prepareStackTrace = _;
return stack;
}
// This is the object the nodash functions will be attached to.
var Nodash = {};
function composed(f) {
f.composed = f;
return f;
}
/* @endif */
var register = require('./lib/register')(Nodash, options);
// I would love to name this function `export` but that is a reserved keyword
// since ECMA Script 5.
function register() {
var f, fCurried, i, arg, aliases = [];
/* @ifdef WITH_ONLINE_HELP */
var metadata = {};
/* @endif */
for (i = 0; i < arguments.length; i++) {
arg = arguments[i];
switch (typeof arg) {
case 'string':
aliases.push(arg);
break;
case 'function':
f = arg;
break;
}
}
fCurried = curried(f.composed ? f() : f);
fCurried.__isNodash = true;
for (i = 0; i < aliases.length; i++) {
Nodash[aliases[i]] = fCurried;
}
/* @ifdef WITH_ONLINE_HELP */
metadata.function = f;
metadata.group = currentGroup;
metadata.aliases = aliases;
metadata.definedAt = callsites()[1].getPosition();
Nodash.metadata.push(metadata);
/* @endif */
return fCurried;
}
register('curried', require('./lib/curried'));
// # The actual functions
//
// Every function is exported by attaching it to the `Nodash` object
// via `register`. If the function is defined immediately it is given
// a name prefixed with an underscore, i.e.
//
// register('<function-name>', function _functionName() { ... }
//
// to make stack traces more readable.
register(require('./lib/type'));
register(require('./lib/function'));
group('Types');
register(require('./lib/Thunk'));
register(require('./lib/Tuple'));
register(require('./lib/List'));
register(require('./lib/Stream'));
register('isFunction', isFunction);
register('isStream', isStream);
register('isArray', isArray);
register('isNumber', isNumber);
register('isString', isString);
register('isInfinite', isInfinite);
register('isObject', isObject);
register(require('./lib/boolean'));
register(require('./lib/eq'));
register(require('./lib/ord'));
register(require('./lib/char'));
register(require('./lib/num'));
register(require('./lib/integral'));
register(require('./lib/fractional'));
register(require('./lib/floating'));
register(require('./lib/realfrac'));
register(require('./lib/numeric'));
register(require('./lib/string'));
register(require('./lib/control'));
register(require('./lib/object'));
group('Functions');
register('id', id);
register('idf', function _idf(x) {
return function () {
return x;
};
});
register('const', 'const_', 'constant', function _const(a, b) {
return a;
});
register('$', 'apply', function _apply(f, x) {
return f(x);
});
register('invoke', function _invoke(f) {
return f();
});
register('.', 'compose', function _compose(f, g, x) {
return f(g(x));
});
register('compose2', function _compose2(f, g, x, y) {
return f(g(x, y));
});
register('flip', function _flip(f) {
return funcs[2](function (b, a) {
return f(a, b);
});
});
register('on', function _on(g, f, a, b) {
return g(f(a), f(b));
});
register('curried', curried);
register('curry', function _curry(f) {
return function (a) {
return function (b) {
return f(a, b);
};
};
});
register('uncurry', function _uncurry(f) {
return function (a, b) {
return f(a)(b);
};
});
// ## Functions for working with boolean functions
group('Boolean');
register('&&', 'AND', function _AND(a, b) { return a && b; });
register('||', 'OR', function _OR(a, b) { return a || b; });
register('not', function _not(value) { return !value; });
register('bool', function _bool(yes, no, bool) {
return bool ? yes : no;
});
// ## Tuple
register(require('./lib/coll/map'));
register(require('./lib/coll/fold'));
register(require('./lib/coll/list'));
register(require('./lib/coll/zipWith'));
register(require('./lib/collection'));
group('Tuples');
register(require('./lib/Maybe'));
register(require('./lib/Either'));
register('fst', function _fst(arr) { return arr[0]; });
register('snd', function _snd(arr) { return arr[1]; });
register(',', 'tuple', function _tuple(a, b) { return [ a, b ]; });
register(',,', 'tuple3', function _tuple3(a, b, c) { return [ a, b, c ]; });
register(',,,', 'tuple4', function _tuple4(a, b, c, d) { return [ a, b, c, d ]; });
// Eq
group("Comparisons");
register('==', 'eq', 'EQ', function _eq(a, b) {
if (a === b) {
return true;
}
var ta = typeof a;
var tb = typeof b;
if (ta !== tb) {
return false;
}
if (ta === 'object') {
var k = Nodash.union(keys(a), keys(b));
for (var i = 0; i < k.length; i++) {
if (!Nodash.eq(a[k[i]], b[k[i]])) {
return false;
}
}
return true;
}
return false;
});
register('/=', '!=', '<>', 'neq', 'NEQ', function _neq(a, b) {
return !Nodash.eq(a, b);
});
// Ord
register('compare', function _compare(a, b) {
switch (typeof a) {
case 'string':
return a.localeCompare(b);
case 'object':
if (isFunction(a.compareTo)) {
return a.compareTo(b);
} else if (isArray(a)) {
for (var i = 0; i < Math.min(a.length, b.length); i++) {
var r = Nodash.compare(a[i], b[i]);
if (r !== 0) {
return r;
}
}
return 0;
}
return a.toString().localeCompare(b.toString());
case 'number':
return Nodash.signum(a - b);
}
return undefined;
});
register('<', 'lt', 'LT', function _lt(a, b) {
return Nodash.compare(a, b) < 0;
});
register('>', 'gt', 'GT', function _gt(a, b) {
return Nodash.compare(a, b) > 0;
});
register('<=', 'lte', 'LTE', function _lte(a, b) {
return Nodash.compare(a, b) <= 0;
});
register('>=', 'gte', 'GTE', function _gte(a, b) {
return Nodash.compare(a, b) >= 0;
});
register('max', function _max(a, b) {
if (Nodash.gt(a, b)) {
return a;
}
return b;
});
register('min', function _min(a, b) {
if (Nodash.lt(a, b)) {
return a;
}
return b;
});
register('comparing', function _comparing(f, a, b) {
return Nodash.compare(f(a), f(b));
});
// Data.Char
group('Characters');
register('isDigit', 'isNumeric', isNumeric);
register('isAsciiLetter', function _isAsciiLetter(x) {
return !!x.match(/^[a-zA-Z]+$/);
});
register('isLetter', function _isLetter(x) {
var xUpper = x.toUpperCase();
var xLower = x.toLowerCase();
for (var i = 0; i < x.length; i += 1) {
if (xUpper[i] === xLower[i]) {
return false;
}
}
return true;
});
register('isUpper', function _isLetter(x) {
var xUpper = x.toUpperCase();
var xLower = x.toLowerCase();
for (var i = 0; i < x.length; i += 1) {
if (xUpper[i] === xLower[i] || x[i] !== xUpper[i]) {
return false;
}
}
return true;
});
register('isLower', function _isLetter(x) {
var xUpper = x.toUpperCase();
var xLower = x.toLowerCase();
for (var i = 0; i < x.length; i += 1) {
if (xUpper[i] === xLower[i] || x[i] !== xLower[i]) {
return false;
}
}
return true;
});
register('ord', function _ord(x) {
return x.charCodeAt(0);
});
register('chr', function _chr(x) {
return String.fromCharCode(x);
});
// Num
group('Numbers');
register('+', 'add', 'ADD', 'plus', 'PLUS', function _add(a, b) {
return a + b;
});
register('-', 'sub', 'minus', 'MINUS', 'subtract', function _sub(a, b) {
return a - b;
});
register('*', 'mul', 'MUL', 'times', 'TIMES', function _mul(a, b) {
return a * b;
});
register('abs', Math.abs);
register('negate', function _negate(a) { return -a; });
register('signum', function _signum(x) {
if (x > 0) {
return 1;
} else if (x === 0) {
return 0;
}
return -1;
});
// Integral
register('div', function _div(a, b) { return Math.floor(a / b); });
register('quot', function _quot(a, b) {
var r = a / b;
return r >= 0 ? Math.floor(r) : Math.ceil(r);
});
register('rem', function _rem(a, b) { return a % b; });
register('mod', function _mod(a, b) {
var q = Nodash.quot(a, b);
var r = Nodash.rem(a, b);
return Nodash.signum(r) == -Nodash.signum(b) ? r + b : r;
});
register('divMod', function _divMod(a, b) {
return [Nodash.div(a, b), Nodash.mod(a, b)];
});
register('quotRem', function _quotRem(a, b) {
return [Nodash.quot(a, b), Nodash.rem(a, b)];
});
// Fractional
register('/', 'frac', function _frac(a, b) { return a / b; });
register('recip', function _recip(a) { return 1 / a; });
// Floating
register('exp', Math.exp);
register('sqrt', Math.sqrt);
register('log', Math.log);
register('logBase', function _logBase(a, b) {
return Math.log(a) / Math.log(b);
});
register('**', 'pow', '^', '^^', Math.pow);
register('sin', Math.sin);
register('tan', Math.tan);
register('cos', Math.cos);
register('asin', Math.asin);
register('atan', Math.atan);
register('acos', Math.acos);
register('sinh', Math.sinh || function _sinh(x) {
return (Math.exp(x) - Math.exp(-x)) / 2;
});
register('tanh', Math.tanh || function _tanh(x) {
if (x === Infinity) {
return 1;
} else if (x === -Infinity) {
return -1;
} else {
return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));
}
});
register('cosh', Math.cosh || function _cosh(x) {
return (Math.exp(x) + Math.exp(-x)) / 2;
});
register('asinh', Math.asinh || function _asinh(x) {
if (x === -Infinity) {
return x;
} else {
return Math.log(x + Math.sqrt(x * x + 1));
}
});
register('atanh', Math.atanh || function _atanh(x) {
return Math.log((1 + x) / (1 - x)) / 2;
});
register('acosh', Math.acosh || function _acosh(x) {
return Math.log(x + Math.sqrt(x * x - 1));
});
// RealFrac
register('properFraction', function _properFraction(x) {
var num = Nodash.truncate(x);
return [ num, -(num - x) ];
});
register('truncate', Math.trunc || function _truncate(x) {
switch (Nodash.signum(x)) {
case -1:
return Math.ceil(x);
case 1:
return Math.floor(x);
}
return 0;
});
register('round', function _round(x) {
var fraction = Nodash.properFraction(x);
var n = fraction[0];
var m = fraction[1] < 0 ? n - 1 : n + 1;
switch (Nodash.signum(Math.abs(fraction[1]) - 0.5)) {
case -1:
return n;
case 0:
return n % 2 === 0 ? n : m;
case 1:
return m;
}
});
register('ceiling', Math.ceil);
register('floor', Math.floor);
// RealFloat
/* ... */
// Numeric
register('gcd', function _gcd(a, b) {
var c;
while (b !== 0) {
c = Nodash.rem(a, b);
a = b;
b = c;
}
return a;
});
register('lcm', function _lcm(a, b) {
if (a === 0 || b === 0) {
return 0;
}
return Math.abs(Nodash.quot(a, Nodash.gcd(a, b)) * b);
});
register('even', function _even(x) { return (x % 2) === 0; });
register('odd', function _odd(x) { return (x % 2) !== 0; });
group('Streams');
register('stream', 'lazy', function _stream(xs) {
if (isStream(xs)) {
return xs;
}
if (isFunction(xs)) {
return mkInfinite(function () {
return xs();
});
}
var i = 0;
return mkStream(function () {
if (i < xs.length) {
return xs[i++];
}
return eos;
});
});
register('consume', function _consume(xs) {
if (!isStream(xs)) {
return xs;
}
checkFinite(xs);
var z, zs = [];
while ((z = xs()) !== eos) {
zs.push(z);
}
return zs;
});
register('consumeString', function _consumeString(xs) {
if (!isStream(xs)) {
return "" + xs;
}
var z, zs = "";
while ((z = xs()) !== eos) {
zs += z;
}
return zs;
});
register('each', function _each(f, xs) {
if (isStream(xs)) {
var x;
while ((x = xs()) !== eos) {
f(x);
}
} else if (isArray(xs) || isString(xs)) {
for (var i = 0; i < xs.length; i++) {
f(xs[i], i);
}
} else if (isObject(xs)) {
var ks = keys(xs);
for (var j = 0; j < ks.length; j += 1) {
f(xs[ks[j]], ks[j]);
}
}
});
register('cycle', function _cycle(xs) {
if (isStream(xs)) {
if (isInfinite(xs)) {
return xs;
}
var arr = [];
var consumed = false;
var h = 0;
return mkInfinite(function () {
var z;
if (!consumed) {
if ((z = xs()) !== eos) {
arr.push(z);
return z;
}
consumed = true;
}
if (h >= arr.length) {
h = 0;
}
return arr[h++];
});
} else if (isArray(xs) || isString(xs)) {
var i = 0;
return mkInfinite(function () {
if (i >= xs.length) {
i = 0;
}
return xs[i++];
});
} else {
var ks = keys(xs);
var j = 0;
return mkInfinite(function () {
if (j >= ks.length) {
j = 0;
}
return xs[ks[j++]];
});
}
});
register('repeat', function _repeat(x) {
return mkInfinite(function () {
return x;
});
});
register('iterate', function _iterate(f, x) {
return mkInfinite(function () {
var r = x;
x = f(x);
return r;
});
});
group('Strings');
register('lines', function _lines(string) {
var result = string.split(/\n/);
if (result[result.length - 1].length === 0) {
delete result[result.length - 1];
}
return result;
});
register('unlines', function _unlines(lines) {
return lines.join('\n');
});
register('words', function _words(string) {
return string.split(/[\n\r\v\t ]/);
});
register('unwords', function _unwords(words) {
return words.join(' ');
});
group('Arrays / Lists');
register(':', 'cons', function _cons(x, xs) {
if (isStream(xs)) {
var consumedFirst = false;
return (isInfinite(xs) ? mkInfinite : mkStream)(function () {
if (!consumedFirst) {
consumedFirst = true;
return x;
}
return xs();
});
}
var zs = [x];
[].push.apply(zs, xs);
return zs;
});
register('++', 'append', function _append(xs, ys) {
if (isStream(xs) || isStream(ys)) {
xs = Nodash.stream(xs);
if (isInfinite(xs)) {
return xs;
}
ys = Nodash.stream(ys);
var atSecondStream = false;
return mkStream(function () {
if (atSecondStream) {
return ys();
}
var r = xs();
if (r == eos) {
atSecondStream = true;
return ys();
}
return r;
});
}
if (isString(xs)) {
return xs + ys;
}
if (isArray(xs)) {
return [].concat.call(xs, ys);
}
// type error
});
register('map', function _map(f, xs) {
var i, ys;
if (isArray(xs)) {
ys = [];
for (i = 0; i < xs.length; i++) {
ys.push(f(xs[i]));
}
return ys;
}
if (isString(xs)) {
ys = [];
for (i = 0; i < xs.length; i++) {
ys.push(f(xs[i]));
}
return listToString(ys);
}
if (isStream(xs)) {
return (isInfinite(xs) ? mkInfinite : mkStream)(function () {
var x = xs();
if (x === eos) {
return eos;
}
return f(x);
});
}
ys = {};
var ks = keys(xs);
for (var j = 0; j < ks.length; j++) {
ys[ks[j]] = f(xs[ks[j]], ks[j]);
}
return ys;
});
register('filter', function _filter(p, xs) {
if (isStream(xs)) {
return (isInfinite(xs) ? mkInfinite : mkStream)(function () {
var x;
while ((x = xs()) !== eos) {
if (p(x)) {
return x;
}
}
return eos;
});
}
var ys;
if (isArray(xs) || isString(xs)) {
ys = [];
for (var i = 0; i < xs.length; i++) {
if (p(xs[i])) {
ys.push(xs[i]);
}
}
return isString(xs) ? listToString(ys) : ys;
}
ys = {};
var ks = keys(xs);
for (var j = 0; j < ks.length; j++) {
if (p(xs[ks[j]])) {
ys[ks[j]] = xs[ks[j]];
}
}
return ys;
});
register('head', function _head(xs) {
if (isStream(xs)) {
var x = xs();
return x === eos ? undefined : x;
}
return xs[0];
});
register('last', function _last(xs) {
if (isStream(xs)) {
checkFinite(xs);
var x, z;
while ((x = xs()) !== eos) {
z = x;
}
return z;
}
return xs[xs.length - 1];
});
register('tail', function _tail(xs) {
if (isStream(xs)) {
xs();
return xs;
}
if (isString(xs)) {
return xs.slice(1);
}
return [].slice.call(xs, 1);
});
register('init', function _init(xs) {
if (isStream(xs)) {
checkFinite(xs);
var a = xs(), b;
return mkStream(function () {
b = xs();
if (b === eos) {
return eos;
}
var r = a;
a = b;
return r;
});
}
if (isString(xs)) {
return xs.slice(0, xs.length - 1);
}
return [].slice.call(xs, 0, xs.length - 1);
});
register('isEmpty', 'null_', function _null(xs) {
if (isStream(xs)) {
return xs() === eos;
}
if (isArray(xs) || isString(xs)) {
return xs.length === 0;
}
for (var _ in xs) {
return false;
}
return true;
});
register('length', function _length(xs) {
if (isStream(xs)) {
if (isInfinite(xs)) {
return Infinity;
}
var n = 0;
while (xs() !== eos) {
n += 1;
}
return n;
}
if (isObject(xs)) {
return keys(xs).length;
}
return xs.length;
});
register('select', function _select(path, object) {
return Nodash.foldl(Nodash.at, object, path.split(/\./));
});
register('!!', 'at', 'AT', function _at(xs, ix) {
if (isStream(xs)) {
var x;
for (var i = 0; i < ix; i++) {
if (xs() === eos) {
return x;
}
}
x = xs();
return x === eos ? undefined : x;
}
if (xs === undefined) {
return xs;
}
return xs[ix];
});
register('reverse', function _reverse(xs) {
if (isStream(xs)) {
checkFinite(xs);
xs = Nodash.consume(xs);
var i = xs.length - 1;
return mkStream(function () {
if (i < 0) {
return eos;
}
return xs[i--];
});
}
var zs = isString(xs) ? "".split.call(xs, '') : [].slice.call(xs);
zs.reverse();
return isString(xs) ? zs.join('') : zs;
});
register('take', function _take(n, xs) {
if (isStream(xs)) {
var i = 0;
return mkStream(function () {
if (i++ < n) {
return xs();
}
return eos;
});
}
return xs.slice(0, n);
});
register('drop', function _drop(n, xs) {
if (isStream(xs)) {
for (var i = 0; i < n; i++) {
xs();
}
return xs;
}
return xs.slice(n);
});
register('splitAt', function _splitAt(n, xs) {
return [ xs.slice(0, n), xs.slice(n) ];
});
register('takeWhile', function _takeWhile(p, xs) {
if (isStream(xs)) {
var exhausted = false;
return mkStream(function () {
var x = xs();
if (exhausted || x == eos || !p(x)) {
exhausted = true;
return eos;
}
return x;
});
}
var i = 0;
while (i < xs.length && p(xs[i])) {
i++;
}
return xs.slice(0, i);
});
register('dropWhile', function _dropWhile(p, xs) {
if (isStream(xs)) {
var x;
while ((x = xs()) !== eos && p(x)) {
}
return Nodash.cons(x, xs);
}
var i = 0;
while (i < xs.length && p(xs[i])) {
i++;
}
return xs.slice(i);
});
register('span', function _span(p, xs) {
var i = 0;
while (i < xs.length && p(xs[i])) {
i++;
}
return [ xs.slice(0, i), xs.slice(i) ];
});
register('break_', 'break', function _break(p, xs) {
var i = 0;
while (i < xs.length && !p(xs[i])) {
i++;
}
return [ xs.slice(0, i), xs.slice(i) ];
});
register('elem', function _elem(x, xs) {
if (isStream(xs)) {
var z;
while ((z = xs()) !== eos) {
if (Nodash.eq(z, x)) {
return true;
}
}
return false;
}
for (var i = 0; i < xs.length; i++) {
if (Nodash.eq(xs[i], x)) {
return true;
}
}
return false;
});
register('notElem', function _notElem(x, xs) {
if (isStream(xs)) {
var z;
while ((z = xs()) !== eos) {
if (Nodash.eq(z, x)) {
return false;
}
}
return true;
}
for (var i = 0; i < xs.length; i++) {
if (Nodash.eq(xs[i], x)) {
return false;
}
}
return true;
});
register('lookup', function _lookup(x, xs) {
if (isArray(xs)) {
for (var i = 0; i < xs.length; i++) {
if (xs[i] && Nodash.eq(xs[i][0], x)) {
return xs[i][1];
}
}
}
return xs[x];
});
register('foldl', 'foldl\'', function _foldl(f, x, xs) {
var streaming = isStream(xs);
if (streaming) {
xs = Nodash.consume(xs);
}
for (var i = 0; i < xs.length; i++) {
x = f(x, xs[i]);
}
if (isArray(x) && streaming) {
return Nodash.stream(x);
}
return x;
});
register('foldl1', 'foldl1\'', function _foldl1(f, xs) {
var streaming = isStream(xs);
if (streaming) {
xs = Nodash.consume(xs);
}
var x = xs[0];
for (var i = 1; i < xs.length; i++) {
x = f(x, xs[i]);
}
if (isArray(x) && streaming) {
return Nodash.stream(x);
}
return x;
});
register('foldr', function _foldr(f, x, xs) {
for (var i = xs.length - 1; i >= 0; i--) {
x = f(xs[i], x);
}
return x;
});
register('foldr1', function _foldr1(f, xs) {
var x = xs[xs.length - 1];
for (var i = xs.length - 2; i >= 0; i--) {
x = f(xs[i], x);
}
return x;
});
register('and', composed(function (){return Nodash.foldl(Nodash.AND, true);}));
register('or', composed(function (){return Nodash.foldl(Nodash.OR, false);}));
register('sum', composed(function (){return Nodash.foldl(Nodash.ADD, 0);}));
register('product', composed(function (){return Nodash.foldl(Nodash.MUL, 1);}));
register('maximum', composed(function (){return Nodash.foldl(Nodash.max, -Infinity);}));
register('minimum', composed(function (){return Nodash.foldl(Nodash.min, +Infinity);}));
register('any', function _any(p, xs) {
for (var i = 0; i < xs.length; i++) {
if (p(xs[i])) {
return true;
}
}
return false;
});
register('all', function _all(p, xs) {
for (var i = 0; i < xs.length; i++) {
if (!p(xs[i])) {
return false;
}
}
return true;
});
register('scanl', function _scanl(f, x, xs) {
if (isStream(xs)) {
return Nodash.cons(x, (isInfinite(xs) ? mkInfinite : mkStream)(function () {
var r = xs();
if (r === eos) {
return eos;
}
x = f(x, r);
return x;
}));
}
var zs = [x];
for (var i = 0; i < xs.length; i++) {
x = f(x, xs[i]);
zs.push(x);
}
return zs;
});
register('scanl1', function _scanl1(f, xs) {
if (isStream(xs)) {
return Nodash.scanl(f, xs(), xs);
}
var x = xs[0];
var zs = [x];
for (var i = 1; i < xs.length; i++) {
x = f(x, xs[i]);
zs.push(x);
}
return zs;
});
register('scanr', function _scanr(f, x, xs) {
var zs = [x];
for (var i = xs.length - 1; i >= 0; i--) {
x = f(xs[i], x);
zs.unshift(x);
}
return zs;
});
register('scanr1', function _scanr1(f, xs) {
var x = xs[xs.length - 1];
var zs = [x];
for (var i = xs.length - 2; i >= 0; i--) {
x = f(xs[i], x);
zs.unshift(x);
}
return zs;
});
register('concat', function _concat(xs) {
if (isString(xs[0])) {
return xs.join('');
}
var zs = [];
var ks = keys(xs);
for (var i = 0; i < ks.length; i++) {
[].push.apply(zs, xs[ks[i]]);
}
return zs;
});
register('concatMap', composed(function (){return Nodash.compose2(Nodash.concat, Nodash.map);}));
register('replicate', function _replicate(n, x) {
var xs = [];
for (var i = 0; i < n; i++) {
xs.push(x);
}
return xs;
});
register('zipWith', function _zipWith(f, as, bs) {
if (isStream(as) || isStream(bs)) {
as = Nodash.stream(as);
bs = Nodash.stream(bs);
return mkStream(function () {
var a = as();
var b = bs();
if (a === eos || b === eos) {
return eos;
}
return f(a, b);
});
}
var length = Math.min(as.length, bs.length);
var zs = [];
for (var i = 0; i < length; i++) {
zs[i] = f(as[i], bs[i]);
}
return zs;
});
register('zipWith3', function _zipWith3(f, as, bs, cs) {
if (isStream(as) || isStream(bs) || isStream(cs)) {
as = Nodash.stream(as);
bs = Nodash.stream(bs);
cs = Nodash.stream(cs);
return mkStream(function () {
var a = as();
var b = bs();
var c = cs();
if (a === eos || b === eos || c === eos) {
return eos;
}
return f(a, b, c);
});
}
var length = Nodash.minimum([as.length, bs.length, cs.length]);
var zs = [];
for (var i = 0; i < length; i++) {
zs[i] = f(as[i], bs[i], cs[i]);
}
return zs;
});
register('zipWith4', function _zipWith4(f, as, bs, cs, ds) {
if (isStream(as) || isStream(bs) || isStream(cs) || isStream(ds)) {
as = Nodash.stream(as);
bs = Nodash.stream(bs);
cs = Nodash.stream(cs);
ds = Nodash.stream(ds);
return mkStream(function () {
var a = as();
var b = bs();
var c = cs();
var d = ds();
if (a === eos || b === eos || c === eos || d === eos) {
return eos;
}
return f(a, b, c, d);
});
}
var length = Nodash.minimum([as.length, bs.length, cs.length, ds.length]);
var zs = [];
for (var i = 0; i < length; i++) {
zs[i] = f(as[i], bs[i], cs[i], ds[i]);
}
return zs;
});
register('zip', composed(function (){return Nodash.zipWith(Nodash.tuple);}));
register('zip3', composed(function (){return Nodash.zipWith3(Nodash.tuple3);}));
register('zip4', composed(function (){return Nodash.zipWith4(Nodash.tuple4);}));
// further from Data.List
register('intersperse', function _intersperse(x, xs) {
if (xs.length === 0) {
return [];
}
var z = [xs[0]];
for (var i = 1; i < xs.length; i++) {
z.push(x);
z.push(xs[i]);
}
return z;
});
register('intercalate', function _intercalate(x, xs) {
return Nodash.concat(Nodash.intersperse(x, xs));
});
register('transpose', function _transpose(xss) {
if (!isArray(xss)) {
var zss = {};
var ks = keys(xss);
for (var k = 0; k < ks.length; k++) {
zss[xss[ks[k]]] = ks[k];
}
return zss;
}
var j = 0;
var zs = [];
var current;
do {
current = [];
for (var i = 0; i < xss.length; i++) {
if (xss[i][j] !== undefined) {
current.push(xss[i][j]);
}
}
j += 1;
} while (current.length > 0 && zs.push(current));
if (isString(xss[0])) {
zs = Nodash.map(listToString, zs);
}
return zs;
});
// register('subsequences', function _subsequences() {
// });
// register('permutations', function _permutations() {
// });
// register('mapAccumL', function _mapAccumL() {
// });
// register('mapAccumR', function _mapAccumR() {
// });
// register('unfoldr', function _unfoldr() {
// });
// register('stripPrefix', function _stripPrefix() {
// });
// register('nubBy', function () {
// });
// register('unionBy', function () {
// });
// register('intersectBy', function () {
// });
register('inits', function _inits(xs) {
var result, current, i, length;
if (isArray(xs)) {
result = [[]];
current = [];
length = xs.length;
for (i = 0; i < length; i += 1) {
current = current.concat(xs[i]);
result.push(current);
}
return result;
}
if (isString(xs)) {
result = [''];
current = '';
length = xs.length;
for (i = 0; i < length; i += 1) {
current += xs[i];
result.push(current);
}
return result;
}
// type error
});
register('tails', function _tails(xs) {
var result, current, i;
if (isArray(xs)) {
result = [[]];
current = [];
for (i = xs.length - 1; i >= 0; i -= 1) {
current = [xs[i]].concat(current);
result.unshift(current);
}
return result;
}
if (isString(xs)) {
result = [''];
current = '';
for (i = xs.length - 1; i >= 0; i -= 1) {
current = xs[i] + current;
result.unshift(current);
}
return result;
}
// type error
});
register('isPrefixOf', function _isPrefixOf(prefix, string) {
if (isStream(prefix)) {
prefix = Nodash.consume(prefix);
}
if (isStream(string)) {
for (var i = 0; i < prefix.length; i++) {
if (prefix[i] !== string()) {
return false;
}
}
return true;
}
for (var j = 0; j < prefix.length; j++) {
if (string[j] !== prefix[j]) {
return false;
}
}
return true;
});
register('isSuffixOf', function _isSuffixOf(suffix, string) {
if (isStream(suffix)) {
suffix = Nodash.consume(suffix);
}
if (isStream(string)) {
string = Nodash.consume(string);
}
for (var i = 0; i < suffix.length; i++) {
if (string[string.length - suffix.length + i] !== suffix[i]) {
return false;
}
}
return true;
});
register('isInfixOf', function _isInfixOf(infix, string) {
return indexOf(infix, string) >= 0;
});
register('indexOf', indexOf);
register('find', function _find(p, xs) {
for (var i = 0; i < xs.length; i++) {
if (p(xs[i])) {
return xs[i];
}
}
return null;
});
register('partition', function _partition(p, xs) {
var as = [];
var bs = [];
for (var i = 0; i < xs.length; i++) {
(p(xs[i]) ? as : bs).push(xs[i]);
}
if (isString(xs)) {
return Nodash.map(listToString, [ as, bs ]);
}
return [ as, bs ];
});
register('findIndex', function _elemIndex(p, xs) {
for (var i = 0; i < xs.length; i++) {
if (p(xs[i])) {
return i;
}
}
return null;
});
register('findIndices', function _elemIndex(p, xs) {
var zs = [];
for (var i = 0; i < xs.length; i++) {
if (p(xs[i])) {
zs.push(i);
}
}
return zs;
});
register('elemIndex', function _elemIndex(x, xs) {
return Nodash.findIndex(Nodash.eq(x), xs);
});
register('elemIndices', function _elemIndex(x, xs) {
return Nodash.findIndices(Nodash.eq(x), xs);
});
register('nub', function _nub(xs) {
var set = new Set();
var zs = [];
for (var i = 0; i < xs.length; i++) {
if (!set.has(xs[i])) {
zs.push(xs[i]);
set.add(xs[i]);
}
}
return zs;
});
register('\\\\', 'difference', function _difference(xs, ys) {
var set = new Set();
var i;
for (i = 0; i < ys.length; i++) {
set.add(ys[i]);
}
var zs = [];
for (i = 0; i < xs.length; i++) {
if (!set.has(xs[i])) {
zs.push(xs[i]);
}
}
return isString(xs) ? listToString(zs) : zs;
});
register('union', function _union(xs, ys) {
var set = new Set();
var zs = [];
var i;
for (i = 0; i < xs.length; i++) {
zs.push(xs[i]);
set.add(xs[i]);
}
for (i = 0; i < ys.length; i++) {
if (!set.has(ys[i])) {
zs.push(ys[i]);
}
}
return zs;
});
register('intersect', function _intersect(xs, ys) {
var set = new Set();
var zs = [];
var i;
for (i = 0; i < ys.length; i++) {
set.add(ys[i]);
}
for (i = 0; i < xs.length; i++) {
if (set.has(xs[i])) {
zs.push(xs[i]);
}
}
return zs;
});
register('sort', function _sort(xs) {
checkFinite(xs);
if (xs.length <= 1) {
return xs;
}
var zs = isString(xs) ? "".split.call(xs, '') : [].slice.call(xs);
if (isNumber(zs[0])) {
zs.sort(function (a, b) { return a - b; });
} else if (isString(zs[0])) {
zs.sort(function (a, b) { return a.localeCompare(b); });
} else {
zs.sort(Nodash.compare);
}
return isString(xs) ? zs.join('') : zs;
});
register('deleteBy', function _deleteBy(p, x, xs) {
for (var i = 0; i < xs.length; i++) {
if (p(x, xs[i])) {
return Nodash.append(xs.slice(0,i), xs.slice(i+1));
}
}
return xs;
});
register('delete_', 'delete', function _delete(x, xs) {
var i = xs.indexOf(x);
if (i >= 0) {
return Nodash.append(xs.slice(0,i), xs.slice(i+1));
}
return xs;
});
register('insertBy', function _insertBy(f, x, xs) {
for (var i = 0; i < xs.length; i++) {
if (f(x, xs[i]) <= 0) {
return Nodash.concat([xs.slice(0,i), x, xs.slice(i)]);
}
}
return Nodash.append(xs, x);
});
register('insert', composed(function (){return Nodash.insertBy(Nodash.compare);}));
register('groupBy', function _groupBy(p, xs) {
if (xs.length === 0) {
return [];
}
var zs = [];
var current = [xs[0]];
var last = xs[0];
for (var i = 1; i < xs.length; i++) {
if (p(xs[i], last)) {
current.push(xs[i]);
} else {
zs.push(current);
current = [xs[i]];
}
last = xs[i];
}
zs.push(current);
return isString(xs) ? Nodash.map(listToString, zs) : zs;
});
register('group', composed(function (){return Nodash.groupBy(Nodash.eq);}));
register('sortBy', function _sortBy(fn, xs) {
if (isStream(xs)) {
checkFinite(xs);
xs = Nodash.consume(xs);
}
if (xs.length <= 1) {
return xs;
}
var yesItsAString = isString(xs);
var zs = yesItsAString ? "".split.call(xs, '') : [].slice.call(xs);
zs.sort(fn);
return yesItsAString ? zs.join('') : zs;
});
register('maximumBy', function _maximumBy(f, xs) {
return Nodash.foldl1(function (a, b) {
if (f(a, b) > 0) {
return a;
}
return b;
}, xs);
});
register('minimumBy', function _minimumBy(f, xs) {
return Nodash.foldl1(function (a, b) {
if (f(a, b) < 0) {
return a;
}
return b;
}, xs);
});
// ## Maybe
group('Maybe');
register('maybe', function _maybe(def, fun, maybe) {
if (maybe === undefined || maybe === null) {
return def;
}
return fun(maybe);
});
register('isJust', function _isJust(value) {
return value !== undefined && value !== null;
});
register('isNothing', function _isNothing(value) {
return value === undefined || value === null;
});
register('fromMaybe', function _fromMaybe(def, maybe) {
if (maybe === undefined || maybe === null) {
return def;
}
return maybe;
});
register('listToMaybe', function _listToMaybe(xs) {
if (isStream(xs)) {
var r = xs();
return r === eos ? null : r;
}
return xs[0];
});
register('maybeToList', function _maybeToList(maybe) {
if (maybe === undefined || maybe === null) {
return [];
}
return [maybe];
});
register('catMaybes', composed(function (){return Nodash.filter(Nodash.isJust);}));
register('mapMaybe', composed(function (){return Nodash.compose2(Nodash.filter(Nodash.isJust), Nodash.map);}));
// ## Either
group('Either');
register('either', function _either(afun, bfun, either) {
var left = either.left || either[0];
if (left) {
return afun(left);
}
var right = either.right || either[1];
if (right) {
return bfun(right);
}
return null;
});
register('Left', function _Left(value) {
return { left: value };
});
register('Right', function _Right(value) {
return { right: value };
});
register('isLeft', function _isLeft(val) {
return val.left !== undefined ||
(val[0] !== undefined && val[0] !== null);
});
register('isRight', function _isRight(val) {
return (val.right !== undefined || val[1] !== undefined) &&
!Nodash.isLeft(val);
});
register('fromLeft', function _fromLeft(val) {
if (val.left !== undefined) {
return val.left;
}
return val[0];
});
register('fromRight', function _fromRight(val) {
if (val.right !== undefined) {
return val.right;
}
return val[1];
});
register('lefts', Nodash.compose(
Nodash.map(Nodash.fromLeft),
Nodash.filter(Nodash.isLeft)
));
register('rights', Nodash.compose(
Nodash.map(Nodash.fromRight),
Nodash.filter(Nodash.isRight)
));
register('partitionEithers', function _partitionEithers(xs) {
return [ Nodash.lefts(xs), Nodash.rights(xs) ];
});
// ## Objects
group('Objects');
register('keys', keys);
register('values', function _values(object) {
var values = [];
each(function (value) {
values.push(value);
}, object);
return values;
});
register('clone', function _clone(thing) {
if (typeof thing === 'object') {
if (thing === null) {
return null;
}
return Nodash.map(Nodash.clone, thing);
}
return thing;
});
// ## Control
group('Control');
register('async', function _async(f) {
return function () {
try {
var callback = Nodash.last(arguments);
var result = f.apply(null, Nodash.init(arguments));
trampoline(function () { callback(result); });
} catch (e) {
trampoline(function () { callback(null, e); });
}
};
});
register('run', function _run(specification) {
// this function does its own currying.
if (arguments.length == 2) {
Nodash.run(specification)(arguments[1]);
return;
}
// if spec is an array, translate to object spec
if (isArray(specification)) {
var prev = null;
var newSpec = {};
Nodash.each(function (func, taskName) {
newSpec[taskName] = prev === null ? func : [ prev, func ];
prev = taskName;
}, specification);
specification = newSpec;
}
var tasks = {},
initial = [];
// prepare tasks specification.
Nodash.each(function (spec, name) {
var dependencies = [];
var func = null;
if (isArray(spec)) {
dependencies = Nodash.init(spec);
func = Nodash.last(spec);
} else {
if (isArray(spec.depends)) {
dependencies = spec.depends;
}
func = spec;
}
var task = {
func: func,
args: dependencies,
depends: {},
enables: tasks[name] ? tasks[name].enables : {}
};
Nodash.each(function (dependency) {
task.depends[dependency] = true;
if (!tasks[dependency]) {
tasks[dependency] = { enables: {} };
}
tasks[dependency].enables[name] = true;
}, dependencies);
tasks[name] = task;
}, specification);
// check spec for unmet dependencies
var unmetDependencies = [];
Nodash.each(function (task, taskName) {
Nodash.each(function (_, dependency) {
if (!specification[dependency]) {
unmetDependencies.push([ taskName, dependency ]);
}
}, task.depends);
}, tasks);
function mkError(message) {
return function (callback) {
trampoline(function () {
callback(null, message);
});
};
}
if (!isEmpty(unmetDependencies)) {
return mkError({
message: "unmet dependencies",
details: Nodash.map(function (detail) {
return "`" +
detail[0] + "` depends on `" +
detail[1] + "` which is not defined";
}, unmetDependencies)
});
}
// build initial set
Nodash.each(function (task, taskName) {
if (Nodash.isEmpty(task.depends)) {
initial.push(taskName);
}
}, tasks);
if (Nodash.isEmpty(initial)) {
return mkError({
message: "no initial task",
details: "There is no task without any dependencies."
});
}
// check spec for cycles
var cycles = [];
Nodash.each(function (taskName) {
var visited = {};
var path = [];
function visit(node) {
path.push(node);
if (visited[node]) {
cycles.push(Nodash.map(id, path));
} else {
visited[node] = true;
Nodash.each(visit, keys(tasks[node].enables));
}
delete visited[path.pop()];
}
visit(taskName);
}, initial);
if (!Nodash.isEmpty(cycles)) {
cycles = Nodash.map(function (cycle) {
cycle = Nodash.dropWhile(Nodash.NEQ(Nodash.last(cycle)), cycle);
return Nodash.reverse(cycle);
}, cycles);
return mkError({
message: "cycle detected",
details: Nodash.map(Nodash.intercalate(" -> "), cycles)
});
}
return function _runTasks(callback) {
var depends = {},
toGo = Nodash.length(tasks),
results = Nodash.map(function (task, taskName) {
return { toGo: Nodash.length(task.enables) };
}, tasks);
function callbackHandle(taskName) {
return function (result, error) {
if (!error) {
results[taskName].result = result;
} else {
results[taskName].error = error;
}
// clean up results if need be
Nodash.each(function (_, dependency) {
results[dependency].toGo -= 1;
if (results[dependency].toGo === 0) {
delete results[dependency];
}
}, tasks[taskName].depends);
toGo -= 1;
if (toGo === 0) {
// clean results object
Nodash.each(function (result) {
delete result.toGo;
}, results);
callback(results);
} else {
Nodash.each(function (_, next) {
delete depends[next][taskName];
if (isEmpty(depends[next])) {
execute(next);
}
}, tasks[taskName].enables);
}
};
}
function execute(taskName) {
var task = tasks[taskName],
callback = callbackHandle(taskName),
dependenciesFailed = false,
args = Nodash.map(function (dependency) {
if (results[dependency].error) {
dependenciesFailed = true;
}
return results[dependency].result;
}, task.args);
if (dependenciesFailed && isFunction(task.func.runOnError)) {
var tempResult = {};
Nodash.each(function (dependency) {
var result = results[dependency];
var stubResult = {};
if (result.error) {
stubResult.error = result.error;
} else {
stubResult.result = result.result;
}
tempResult[dependency] = stubResult;
}, task.args);
tempResult = task.func.runOnError(tempResult) || tempResult;
args = Nodash.map(function (dependency) {
return tempResult[dependency].result;
}, task.args);
}
args.push(callback);
trampoline(function _executeTask() {
if (dependenciesFailed && !task.func.runOnError) {
callback(null, { message: "dependencies failed" });
} else {
var f = task.func;
if (isObject(f)) {
f = f.func;
}
try {
f.apply(null, args);
} catch (e) {
callback(null, e);
}
}
});
}
Nodash.each(function (task, taskName) {
depends[taskName] = Nodash.clone(task.depends);
}, tasks);
Nodash.each(execute, initial);
};
});
register('until', function _until(p, f, v) {
while (!p(v)) {
v = f(v);
}
return v;
});
register('pipe', function _pipe() {
var functions, intermediateResult, callback;
var error = null;
if (isArray(arguments[0])) {
functions = arguments[0];
callback = arguments[1];
} else {
functions = arguments;
}
if (functions.length > 0) {
if (isFunction(functions[0])) {
intermediateResult = functions[0]();
} else {
intermediateResult = functions[0];
}
for (var i = 1; i < functions.length; i += 1) {
try {
intermediateResult = functions[i](intermediateResult);
} catch (err) {
error = err;
}
}
}
if (isFunction(callback)) {
callback(error, intermediateResult);
} else if (error) {
throw error;
}
return intermediateResult;
});
group('Nodash');
register('isNodash', isNodash);
register('install', function _install(mountpoint) {
register('install', function (mountpoint) {
var options = arguments[1];

@@ -2340,10 +60,13 @@ var nodashObject = Nodash;

var postfix = '';
if (!mountpoint) {
return Nodash;
}
if (options) {
nodashObject = makeNodash(options);
}
if (isArray(mountpoint)) {
if (isString(mountpoint[0])) {
prefix = NativeArray.prototype.shift.call(mountpoint);
if (Nodash.isArray(mountpoint)) {
if (Nodash.isString(mountpoint[0])) {
prefix = [].shift.call(mountpoint);
}
if (isString(mountpoint[1])) {
if (Nodash.isString(mountpoint[1])) {
postfix = mountpoint[1];

@@ -2354,6 +77,9 @@ }

Nodash.each(function (func, name) {
if (!isNodash(func)) {
if (name[0] === '_') {
return;
}
mountpoint[prefix + name + postfix] = func;
var key = prefix + name + postfix;
if (!(key in mountpoint)) {
mountpoint[key] = func;
}
}, nodashObject);

@@ -2363,2 +89,7 @@ return mountpoint;

delete Nodash.Thunk;
delete Nodash.resolveThunk;
register(['freeze', function (freeze) { freeze(Nodash); return {}; }]);
return Nodash;

@@ -2369,10 +100,6 @@ }

if (typeof module !== 'undefined' && module.exports) {
module.exports = Nodash;
} else if (typeof define === 'function' && define.amd) {
define(Nodash.idf(Nodash));
} else {
module.exports = Nodash;
if (typeof window !== 'undefined') {
window.Nodash = Nodash;
}
}());
{
"name": "nodash",
"version": "0.9.2",
"version": "0.10.0",
"description": "A port of the Haskell Prelude to JavaScript/NodeJS",

@@ -21,3 +21,3 @@ "main": "nodash.js",

],
"author": "Julian Fleischer",
"author": "Julian Alexander Fleischer <tirednesscankill@warhog.net>",
"license": "MIT",

@@ -29,30 +29,37 @@ "bugs": {

"devDependencies": {
"chai": "^3.0.0",
"chalk": "^1.0.0",
"filesize": "^3.1.2",
"gulp": "^3.8.11",
"gulp-docco": "0.0.4",
"browserify": "^11.2.0",
"chalk": "^1.1.1",
"directorywalker": "^1.0.2",
"filesize": "^3.1.3",
"gulp": "^3.9.0",
"gulp-esmangle": "^1.1.1",
"gulp-filenames": "^2.0.0",
"gulp-gh-pages": "^0.5.2",
"gulp-gzip": "^1.1.0",
"gulp-istanbul": "^0.8.1",
"gulp-gzip": "^1.2.0",
"gulp-istanbul": "^0.10.1",
"gulp-istanbul-enforcer": "^1.0.3",
"gulp-jshint": "^1.10.0",
"gulp-jshint": "^1.11.2",
"gulp-less": "^3.0.3",
"gulp-markdown": "^1.0.0",
"gulp-mocha": "^2.0.1",
"gulp-mustache": "^1.0.2",
"gulp-mocha": "^2.1.3",
"gulp-mustache": "^1.1.2",
"gulp-preprocess": "^1.2.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.3",
"gulp-sourcemaps": "^1.5.2",
"gulp-uglify": "^1.2.0",
"highlight.js": "^8.6.0",
"less-plugin-autoprefix": "^1.4.2",
"less-plugin-clean-css": "^1.5.0",
"gulp-replace": "^0.5.4",
"gulp-sourcemaps": "^1.6.0",
"gulp-uglify": "^1.4.1",
"highlight.js": "^8.8.0",
"less-plugin-autoprefix": "^1.5.1",
"less-plugin-clean-css": "^1.5.1",
"lodash": "^3.10.1",
"marked": "^0.3.3",
"marked": "^0.3.5",
"sprintf": "^0.1.5",
"underscore": "^1.8.3"
"underscore": "^1.8.3",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
"dependencies": {
"docco": "^0.7.0",
"knuth-morris-pratt": "^1.0.0"
}
}

@@ -5,3 +5,6 @@ nodash

[![Build Status](https://travis-ci.org/scravy/nodash.svg?branch=master)](https://travis-ci.org/scravy/nodash)
[![Dependencies](https://david-dm.org/scravy/nodash.svg)](https://david-dm.org/scravy/nodash#info=dependencies&view=table)
[![Dependencies](https://david-dm.org/scravy/nodash/dev-status.svg)](https://david-dm.org/scravy/nodash#info=devDependencies&view=table)
***nodash*** offers you a rich set of library functions, comparable to

@@ -12,12 +15,13 @@ the likes of [***underscore***](http://underscorejs.org/)

from the [***Haskell Prelude***](https://hackage.haskell.org/package/base-4.7.0.0/docs/Prelude.html)
and emphasize a functional programming style.
and emphasize a [functional programming style](https://www.cs.cmu.edu/~crary/819-f09/Backus78.pdf).
A special
trait of this library is that it discards some JavaScript concepts (like
`this`) to allow some (in the authors opinion) more useful ones. Every function
from this library can be thought of as *curried*, i.e. you can partially apply
any function and get a function in return (on the other hand this means there are
no optional arguments). Also you have a distinction between *lists* and *streams*
and it can cope with *infinite streams*.
A special trait of this library is that it discards some JavaScript concepts
(like prototypes or optional arguments) to allow some (in the authors opinion)
more useful ones (such as currying).
Every function from this library can be thought of as *curried*, i.e. you can
partially apply any function and get a function in return (on the other hand this
means there are no optional arguments). It also supports *lists* which can be
evaluated lazily and *infinite streams*.
Browse through the

@@ -29,64 +33,73 @@ [apidoc](https://scravy.github.io/nodash/apidoc.html),

Usage
-----
Example
-------
A port of the Haskell Prelude to JavaScript/NodeJS.
npm install --save nodash
Usage in Node, installed in `GLOBAL`:
```JavaScript
require('nodash').install(GLOBAL);
Nodash.install(global || window); // node or browser
var reverse = foldl(flip(cons), []);
console.log(reverse([1,2,3])); // → [3,2,1]
```
Usage in Node, installed in `GLOBAL` but prefixed:
```JavaScript
require('nodash').install([ '$', GLOBAL ]);
Usage
-----
var reverse = $foldl($flip($cons), []);
### in node
```
npm install --save nodash
```
Usage in Node, installed in `GLOBAL` but prefixed + postfixed:
```JavaScript
require('nodash').install([ '__', GLOBAL, '__' ]);
var reverse = __foldl__(__flip__(__cons__), []);
var Nodash = require('nodash');
```
Usage in Node:
```JavaScript
var Nodash = require('nodash');
### in the browser
var reverse = Nodash.foldl(Nodash.flip(Nodash.cons), []);
```HTML
<script src="nodash.js"></script>
<script>
// Nodash is available in `window.Nodash`
document.write(Nodash.foldl(Nodash.flip(cons), []));
</script>
```
Usage in the browser:
```JavaScript
### in legacy browsers
Just pull in `es5-shim` first:
```HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.1.13/es5-shim.js"></script>
<script src="nodash.js"></script>
<script>
// nodash is available in window.Nodash
var reverse = Nodash.foldl(Nodash.flip(Nodash.cons), []);
```
// you can use `Nodash.install()` like you would in node
Nodash.install(window);
var reverse2 = foldl(flip(cons, []));
### `install(mountpoint)`
// also with prefix/postfix (a postfix only in the line below)
Nodash.install([ window, '_' ]);
It is possible to attach the Nodash functions directly
to the global object (in fact, any object), optionally
with a prefix or postfix:
var reverse3 = foldl_(flip_(cons_, []));
```JavaScript
Nodash.install(global); → foldl(flip(cons), []);
Nodash.install([ '$', global ]); → $foldl($flip($cons), []);
Nodash.install([ global, '_' ]); → foldl_(flip_(cons_), []);
Nodash.install([ 'f_', global ]); → f_foldl(f_flip(f_cons), []);
```
Both a prefix and a postfix works too:
```JavaScript
Nodash.install([ '__', global, '__' ]); → __foldl__(__flip__(__cons__), []);
```
License
-------
Copyright (c) 2015 Julian Fleischer
Copyright (c) 2015 Julian Alexander Fleischer

@@ -93,0 +106,0 @@ Permission is hereby granted, free of charge, to any

@@ -1,17 +0,16 @@

+ `isDigit` vs `isNumeric` (single character or whole string?)
+ `isAsciiLetter` → single character or whole string?
+ Support streams in all functions that could support streams.
+ Devise and benchmark different ways of implementing streams
(currently functions, what about immutable singly linked lists?)
+ Implement remaining functions from `Data.List` (`permutations`, ...)
+ Benchmark more functions
+ Document all functions including examples and signatures
+ Create try-it-out
+ Create examples/gallery
+ Is `until` in the proper group @ `Control`?
+ `isAllUpper` that checks `isUpper` and `all(isLetter)`?
+ or change `isUpper`?
+ ditto: `isAllLower` and `isLower`?
+ what about `isLetter` (unicode aware)
+ support unicode code points beyond U+10000
- Website
+ Create try-it-out
+ Create examples/gallery
- Char
+ support unicode code points beyond U+10000
+ properly support letter characters
- Implement the following functions:
+ subsequences
+ permutations
+ mapAccumL
+ mapAccumR
+ unfoldr
+ stripPrefix
+ nubBy
+ unionBy
+ intersectBy
require('../nodash').install(GLOBAL);
var assert = map(flip, require('assert'));
var assert = require('../util/assert');

@@ -4,0 +4,0 @@ describe('Bool', function () {

var P = require('../nodash').install(GLOBAL);
var assert = map(flip, require('assert'));
var assert = require('../util/assert');

@@ -4,0 +4,0 @@ describe('Control', function () {

require('../nodash').install(GLOBAL);
var assert = map(flip, require('assert'));
var assert = require('../util/assert');

@@ -4,0 +4,0 @@ describe('Curried', function () {

require('../nodash').install(GLOBAL);
var assert = map(flip, require('assert'));
var assert = require('../util/assert');
describe('Either', function () {
it("either", function () {
it('either', function () {
assert.strictEqual(17, either(constant(17), constant(13), Left(19)));

@@ -11,37 +11,38 @@ assert.strictEqual(13, either(constant(17), constant(13), Right(19)));

assert.strictEqual(19, either(constant(17), id, Right(19)));
assert.throws(function () {
either(id, id, 17);
});
});
it("either /w not an either", function () {
assert.strictEqual(null, either(constant(17), constant(13), {}));
it('Left + isLeft', function () {
assert(isLeft(Left(7)));
assert(isLeft(new Left(7)));
});
it("Left", function () {
assert.deepEqual({ left: 7 }, Left(7));
it('Right + isRight', function () {
assert(isRight(Right(7)));
assert(isRight(new Right(7)));
});
it("Right", function () {
assert.deepEqual({ right: 7 }, Right(7));
it('fromLeft', function () {
assert.strictEqual(11, fromLeft(Left(11)));
});
it("isLeft", function () {
assert.strictEqual(true, isLeft([ 7 ]));
assert.strictEqual(true, isLeft(Left(7)));
assert.strictEqual(false, isLeft(Right(7)));
it('fromRight', function () {
assert.strictEqual(11, fromRight(Right(11)));
});
it("isRight", function () {
assert.strictEqual(true, isRight([ null, 7 ]));
assert.strictEqual(false, isRight(Left(7)));
assert.strictEqual(true, isRight(Right(7)));
it('fromLeft throws', function () {
assert.throws(function () {
fromLeft(Right(11));
});
});
it("fromLeft /w tuple", function () {
assert.strictEqual(17, fromLeft([ 17 ]));
it('fromRight throws', function () {
assert.throws(function () {
fromRight(Left(11));
});
});
it("fromRight /w tuple", function () {
assert.strictEqual(17, fromRight([ null, 17 ]));
});
it("lefts", function () {
it('lefts', function () {
assert.deepEqual(

@@ -53,3 +54,3 @@ [ 1, 4, 19 ],

it("rights", function () {
it('rights', function () {
assert.deepEqual(

@@ -61,10 +62,10 @@ [ 2, 8, 13 ],

it("partitionEithers", function () {
assert.deepEqual(
[ [ 1, 4, 19 ], [ 2, 8, 13 ] ],
it('partitionEithers', function () {
assert(eq(
tuple([ 1, 4, 19 ], [ 2, 8, 13 ]),
partitionEithers(
[ Left(1), Right(2), Left(4), Right(8), Right(13), Left(19) ]
)
);
));
});
});
require('../nodash').install(GLOBAL);
var assert = require('assert');
var assert = require('../util/assert');

@@ -15,2 +15,11 @@ describe('Eq', function () {

it("eq /w Tuple", function () {
assert.strictEqual(true, eq(tuple(1, 3), tuple(1, 3)));
assert.strictEqual(false, eq(tuple(1, 3), tuple(3, 1)));
assert.strictEqual(true, eq(tuple3(1, 3, 9), tuple3(1, 3, 9)));
assert.strictEqual(false, eq(tuple3(1, 3, 9), tuple3(3, 1, 9)));
assert.strictEqual(true, eq(tuple4(1, 3, 9, 27), tuple4(1, 3, 9, 27)));
assert.strictEqual(false, eq(tuple4(1, 3, 9, 27), tuple4(1, 3, 9, 81)));
});
it("eq /w object", function () {

@@ -20,2 +29,3 @@ assert.strictEqual(true, eq({}, {}));

assert.strictEqual(false, eq({ a: 7 }, {}));
assert.strictEqual(false, eq(tuple3(1, 2, 3), new Date()));
});

@@ -22,0 +32,0 @@

require('../nodash').install(GLOBAL);
var assert = map(flip, require('assert'));
var assert = require('../util/assert');

@@ -4,0 +4,0 @@ describe('Floating', function () {

@@ -1,3 +0,3 @@

var P = require('../nodash').install(GLOBAL);
var assert = map(flip, require('assert'));
require('../nodash').install(GLOBAL);
var assert = require('../util/assert');

@@ -4,0 +4,0 @@ describe('Fractional', function () {

require('../nodash').install(GLOBAL);
var assert = require('assert');
var assert = require('../util/assert');

@@ -11,2 +11,3 @@ describe('Function', function () {

it('const', function () {
// TODO
//assert.strictEqual(4, foldl(compose(constant, plus(1)), 0, [1,9,37,0]));

@@ -35,9 +36,16 @@ });

it('curry', function () {
assert.strictEqual(3, curry(Math.min)(3)(4));
var f = curry(function (x) { return fst(x) + snd(x); });
assert.strictEqual(
true,
eq(zipWith(f, [ 1, 2, 3 ], [ 3, 2, 1 ]), [ 4, 4, 4 ])
);
});
it('uncurry', function () {
assert.strictEqual(3, uncurry(curry(Math.min))(3, 4));
assert.strictEqual(
true,
eq(map(uncurry(Math.min), zip([1, 2, 3], [3, 2, 1])), [1, 2, 1])
);
});
});

@@ -1,3 +0,3 @@

var P = require('../nodash').install(GLOBAL);
var assert = map(flip, require('assert'));
require('../nodash').install(GLOBAL);
var assert = require('../util/assert');

@@ -4,0 +4,0 @@ describe('Integral', function () {

require('../nodash').install(GLOBAL);
var assert = map(flip, require('assert'));
var assert = require('../util/assert');

@@ -45,16 +45,10 @@ describe('Maybe', function () {

it("listToMaybe", function () {
assert.strictEqual(9, listToMaybe([ 9, 10 ]));
assert.strictEqual(true, isJust(listToMaybe([ 13 ])));
assert.strictEqual(true, isNothing(listToMaybe([])));
assert.strictEqual(9, listToMaybe(singleton(9)));
assert.strictEqual(17, listToMaybe(cons(17, singleton(13))));
assert.strictEqual(true, isNothing(listToMaybe(emptyList())));
});
it("listToMaybe /w stream", function () {
assert.strictEqual(9, listToMaybe(repeat(9)));
assert.strictEqual(null, listToMaybe(take(0, repeat(9))));
});
it("maybeToList", function () {
assert.deepEqual([ 9 ], maybeToList(9));
assert.deepEqual([ ], maybeToList(null));
assert.deepEqual([ ], maybeToList(undefined));
assert.strictEqual(emptyList(), maybeToList(null));
assert.strictEqual(emptyList(), maybeToList(undefined));
});

@@ -61,0 +55,0 @@

@@ -1,24 +0,30 @@

var P = require('../nodash');
var assert = require('assert');
require('../nodash').install(GLOBAL);
var assert = require('../util/assert');
describe('Num', function () {
it('plus', function () {
assert.strictEqual(10, plus(4, 6));
});
it('add', function () {
assert.strictEqual(10, P.plus(4, 6));
assert.strictEqual(10, P.add(6, 4));
assert.strictEqual(10, add(6, 4));
});
it('sub', function () {
assert.strictEqual(-2, P.minus(4, 6));
assert.strictEqual(2, P.sub(6, 4));
it('minus', function () {
assert.strictEqual(-2, minus(4, 6));
});
it('subtract', function () {
assert.strictEqual(-2, subtract(6, 4));
});
it('mul', function () {
assert.strictEqual(24, P.times(4, 6));
assert.strictEqual(24, P.mul(6, 4));
assert.strictEqual(24, times(4, 6));
assert.strictEqual(24, mul(6, 4));
});
it('negate', function () {
assert.strictEqual(-4, P.negate(4));
assert.strictEqual(6, P.negate(-6));
assert.strictEqual(-4, negate(4));
assert.strictEqual(6, negate(-6));
});

@@ -25,0 +31,0 @@

require('../nodash').install(GLOBAL);
var assert = require('assert');
var assert = require('../util/assert');

@@ -4,0 +4,0 @@ describe('Numeric', function () {

@@ -1,3 +0,3 @@

var P = require('../nodash');
var assert = require('assert');
require('../nodash');
var assert = require('../util/assert');

@@ -7,39 +7,39 @@ describe('Ord', function () {

it('lt', function () {
assert.strictEqual(true, P.lt(10, 12));
assert.strictEqual(false, P.flip(P.LT)(10, 12));
assert.strictEqual(true, lt(10, 12));
assert.strictEqual(false, flip(LT)(10, 12));
});
it('gt', function () {
assert.strictEqual(true, P.gt(10, -12));
assert.strictEqual(false, P.flip(P.GT)(10, -12));
assert.strictEqual(true, gt(10, -12));
assert.strictEqual(false, flip(GT)(10, -12));
});
it('lte', function () {
assert.strictEqual(true, P.lte(10, 10));
assert.strictEqual(true, P.LTE(10, +Infinity));
assert.strictEqual(false, P.flip(P.LTE)(10, +Infinity));
assert.strictEqual(true, lte(10, 10));
assert.strictEqual(true, LTE(10, +Infinity));
assert.strictEqual(false, flip(LTE)(10, +Infinity));
});
it('gte', function () {
assert.strictEqual(true, P.gte(10, 10));
assert.strictEqual(true, P.GTE(10, -Infinity));
assert.strictEqual(false, P.flip(P.GTE)(10, -Infinity));
assert.strictEqual(true, gte(10, 10));
assert.strictEqual(true, GTE(10, -Infinity));
assert.strictEqual(false, flip(GTE)(10, -Infinity));
});
it('compare', function () {
assert.strictEqual(0, P.compare(20, 20));
assert.strictEqual(-1, P.compare(-20, 20));
assert.strictEqual(+1, P.compare(20, -20));
assert.strictEqual(0, compare(20, 20));
assert.strictEqual(-1, compare(-20, 20));
assert.strictEqual(+1, compare(20, -20));
});
it('compare on function should yield undefined', function () {
assert.strictEqual(undefined, P.compare(id, id));
assert.strictEqual(undefined, compare(id, id));
});
it('comparing', function () {
assert.strictEqual(0, P.comparing(P.negate, 20, 20));
assert.strictEqual(+1, P.comparing(P.negate, -20, 20));
assert.strictEqual(-1, P.comparing(P.negate, 20, -20));
assert.strictEqual(0, comparing(negate, 20, 20));
assert.strictEqual(+1, comparing(negate, -20, 20));
assert.strictEqual(-1, comparing(negate, 20, -20));
});
});

@@ -1,4 +0,3 @@

var P = require('../nodash').install(GLOBAL);
var assert = map(flip, require('assert'));
var expect = require('chai').expect;
require('../nodash').install(GLOBAL);
var assert = require('../util/assert');

@@ -5,0 +4,0 @@ describe('Pipe', function () {

@@ -19,3 +19,3 @@ var DumbMath = {

var assert = require('assert');
var assert = require('../util/assert');

@@ -27,24 +27,5 @@ describe('Polyfills', function () {

before(function () {
P = require('../nodash').install({}, {
Math: DumbMath,
Array: {},
Object: {},
dontUseNatives: true
});
P = require('../nodash').install({}, { Math: DumbMath });
});
it('isArray in map', function () {
var plus1 = P.map(P.plus(1));
assert.deepEqual([2, 3, 4], plus1([1, 2, 3]));
});
it('isArray in map /w object', function () {
var plus1 = P.map(P.plus(1));
assert.deepEqual({ a: 2, b: 3 }, plus1({ a: 1, b: 2 }));
var a = { x: 3 };
var b = Object.create(a);
b.z = 19;
assert.deepEqual({ z: 20 }, plus1(b));
});
it('sinh', function () {

@@ -95,3 +76,12 @@ assert.strictEqual(0, P.sinh(0));

});
});
describe('Polyfills (`Set` missing)', function () {
var P;
before(function () {
P = require('../nodash').install({});
});
it('nub', function () {

@@ -110,3 +100,3 @@ assert.deepEqual([1,2,4], P.nub([1,1,2,4,4,4]));

describe('Polyfills /w enum bug', function () {
describe('Polyfills (`Set` available)', function () {

@@ -116,25 +106,5 @@ var P;

before(function () {
P = require('../nodash').install({}, {
Math: DumbMath,
Array: {},
Object: {},
dontUseNatives: true,
refObj: {}
});
P = require('../nodash').install({}, { Set: require('../lib/Set') });
});
it('isArray in map', function () {
var plus1 = P.map(P.plus(1));
assert.deepEqual([2, 3, 4], plus1([1, 2, 3]));
});
it('isArray in map /w object', function () {
var plus1 = P.map(P.plus(1));
assert.deepEqual({ a: 2, b: 3 }, plus1({ a: 1, b: 2 }));
var a = { x: 3 };
var b = Object.create(a);
b.toString = 19;
assert.deepEqual({ toString: 20 }, plus1(b));
});
it('nub', function () {

@@ -141,0 +111,0 @@ assert.deepEqual([1,2,4], P.nub([1,1,2,4,4,4]));

require('../nodash').install(GLOBAL);
var assert = require('assert');
var assert = require('../util/assert');

@@ -4,0 +4,0 @@ describe('RealFrac', function () {

@@ -1,3 +0,3 @@

var P = require('../nodash').install(GLOBAL);
var assert = require('assert');
require('../nodash').install(GLOBAL);
var assert = require('../util/assert');

@@ -7,13 +7,9 @@ describe('Tuple', function () {

it('fst', function () {
assert.strictEqual('x', fst(['x', 'y']));
assert.strictEqual('x', fst(tuple('x', 'y')));
});
it('snd', function () {
assert.strictEqual('y', snd(['x', 'y']));
assert.strictEqual('y', snd(tuple('x', 'y')));
});
it(',', function () {
assert.deepEqual(['x', 'y'], P[',']('x', 'y'));
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc