Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

p

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p - npm Package Compare versions

Comparing version
0.0.2
to
0.0.3
.npmignore

Sorry, the diff of this file is not supported yet

+5
/* [ 2, 4, 6 ] */
var map = require('./hof').map;
map(function duplicate(x) { return x*2; }, [1,2,3], [],
function (x) { console.error(x); });
var map = require('../pattern')
, mapa = require('../pattern')
, zip_with = require('../pattern')
, _, f, ac, l, l1, l2, cb
;
// high order functions
map(f, [], ac, cb,
function map_done(f, l, ac, cb) { return cb(ac); });
map(f, l, ac, cb,
function map_catch_all(f, l, ac, cb) {
ac.push(f(l.shift())); // head
map(f, l, ac, cb); // l is now tail
});
mapa(f, [], ac, cb,
function map_done(f, l, ac, cb) { return cb(ac); });
mapa(f, l, ac, cb,
function map_catch_all(f, l, ac, cb) {
f(l.shift(), function(x) {
ac.push(x);
mapa(f, l, ac, cb); // l is now tail
});
});
// filter
// foldl
zip_with(f, [], l2, ac, cb, function emptyl1(f, l1, l2, ac, cb) { cb(ac); });
zip_with(f, l1, [], ac, cb, function emptyl2(f, l1, l2, ac, cb) { cb(ac); });
zip_with(f, l1, l2, ac, cb, function all(f, l1, l2, ac, cb) {
ac.push(f(l1.shift, l2.shift));
zip_with(f, l1, l2, ac, cb);
});
module.exports = { map: map, map_async: mapa, zip_with: zip_with };
/* [ 2, 4, 6 ] */
var map_async = require('./hof').map_async;
function duplicate(x, cb) {
setTimeout(function() { cb(x*2); }, Math.ceil(Math.random() * 100));
}
map_async(duplicate, [1,2,3], [], function(ac) { console.error(ac); });
/* [ 2, 3, 4 ] */
var map = require('../pattern')
, _, f, ac
;
map(f, [], ac, function done(_, _, ac) { return console.error(ac); });
map(f, _, ac, function all(f, l, ac) {
ac.push(f(l.shift())); // head
map(f, l, ac); // l is now tail
});
map(function plusone(x) { return x+1; }, [1,2,3], []);
/* done */
var insert_all = require('../pattern'), _;
// pretending we are doing an async call
function insert_element(data, callback) {
setTimeout(function() { callback(data); },
Math.ceil(Math.random() * 100));
}
insert_all([], _, function stop(l,cb) { cb(); });
insert_all(_, _, function catchall(l, cb) {
insert_element(l.shift(), function elem_cb(elem) {
console.log(elem + ' inserted');
insert_all(l, cb);
});
});
insert_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
function done() { console.error('done'); });
/* CAT */
var insert_all = require('../pattern'), _;
function insert_element(data, callback) {
setTimeout(function() { callback(data); }, Math.ceil(Math.random() * 10));
}
insert_all([], function () { console.error('CAT'); });
insert_all(_, function (l) {
insert_element(l.shift(), function (elem) {
console.log('‣ ', elem);
insert_all(l);
});
});
insert_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
var zip = require('./hof').zip_with;
zip(function concat(a,b) { return a + ':' + b; },
[1,3,5], [2,4,6,8], [], function (ac) {
console.log(ac);
});
var fs = require('fs')
, assert = require('assert')
, path = __dirname + '/../samples/'
, files = fs.readdirSync(path)
, spawn = require('child_process').spawn
, colors
, return_code = 0
, i = 0
;
try { colors = require('colors'); } catch (e) {}
function c(msg,color) { return colors ? msg[color] : msg; }
var tests = files.filter(function (f) { return f.indexOf('.test.') !== -1; });
var expected = tests.length;
tests.forEach(
function (f) {
var contents = fs.readFileSync(path + f, 'utf-8')
, output = /\/\*\s*(.*?)\s*\*\//.exec(contents)[1]
, node = spawn('node', [path + f])
, buffer = ''
;
node.stderr.on('data', function(data) { buffer += data; });
node.on('exit', function() {
i++;
buffer = buffer.replace(/^\s+|\s+$/g,"");
var ok = buffer === output;
console.log(c(ok ? '✔' : '✗', ok ? 'green' : 'red'), 'samples/'+f);
if(!ok) {
return_code=1;
console.log(c(' ♯', 'cyan'), buffer);
console.log(c(' δ', 'magenta'), output);
}
if(i===expected) {
process.exit(return_code);
}
});
}
);
+2
-1
{ "name" : "p"
, "description" : "pattern matching in javascript for asyncronous iteration"
, "author" : "nuno job <nunojobpinto@gmail.com> (http://nunojob.com/)"
, "version" : "0.0.2"
, "version" : "0.0.3"
, "main" : "./pattern.js"

@@ -11,2 +11,3 @@ , "homepage" : "https://github.com/dscape/p"

, "engines" : { "node" : ">=0.4.0" }
, "scripts" : { "test": "node test"}
}

@@ -28,2 +28,3 @@ <a name="pattern"/>

then we normally register the iteration pattern:
``` js

@@ -37,3 +38,4 @@ // var _; was set in the top, value is undefined

``` js
// one argument, arity #1. run forest, run.
// one argument, arity #1
// run forest, run
insert_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

@@ -55,3 +57,3 @@ ```

<a name="samples"/>
## samples
# samples

@@ -61,3 +63,3 @@ there are samples in the `samples` directory. check them out

<a name="disclaimer"/>
## disclaimer
# disclaimer

@@ -106,3 +108,3 @@ if you are not familiar with `haskell` and you love your javascript object oriented code you better look away right now. this pretty much breaks everything you love and care about in javascript

copyright 2012 nuno job <nunojob.com> (oO)--',--
copyright 2012 nuno job <nunojob.com> `(oO)--',--`

@@ -119,3 +121,3 @@ licensed under the apache license, version 2.0 (the "license");

see the license for the specific language governing permissions and
limitations under the license.
limitations under the license

@@ -122,0 +124,0 @@ [npm]: http://npmjs.org

@@ -12,3 +12,3 @@ var p1 = require('../pattern')

function done() { console.log('done'); }
function done(l) { console.log('done'); }

@@ -15,0 +15,0 @@ function any_generator (name,context) {

var map = require('../pattern')
, _, f, ac
;
map(f, [], ac, function done(_,_,ac) { return console.log(ac); });
map(f, _, ac, function all(f, l, ac) {
ac.push(f(l.shift())); // head
map(f, l, ac); // l is now tail
});
map(function duplicate(x) { console.log(x*2); return x*2; }, [1,2,3], []);
var map = require('../pattern')
, _, f, ac
;
map(f, [], ac, function done(_,_,ac) { return console.log(ac); });
map(f, _, ac, function all(f, l, ac) {
ac.push(f(l.shift())); // head
map(f, l, ac); // l is now tail
});
map(function duplicate(x) { console.log(x*2); return x*2; }, [1,2,3], []);
map(function plusone(x) { return x+1; }, [1,2,3], []);
var insert_all = require('../pattern'), _;
// pretending we are doing an async call
function insert_element(data, callback) {
setTimeout(function() { callback(data); },
Math.ceil(Math.random() * 1000));
}
insert_all([], function done() { console.log('done'); });
insert_all(_, function catchall(l) {
insert_element(l.shift(), function elem_cb(elem) {
console.log(elem + ' inserted');
insert_all(l);
});
});
insert_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);