Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cosy-lang

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cosy-lang - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

lib/protocols/ISeq.js

49

lib/promise.js

@@ -21,3 +21,3 @@ // Generated by CoffeeScript 1.3.3

})(this, function(protocol) {
var IPromise, promise;
var IPromise, Promise, promise;
IPromise = protocol.define('IPromise', ['when', 'Regester a callback with a deffered'], ['deliver', 'Resolve a deffered']);

@@ -44,5 +44,50 @@ protocol.extend(IPromise, null, [

], ['deliver', function(deffered, val) {}]);
Promise = (function() {
function Promise() {
var listeners, realised, val;
listeners = [];
realised = false;
val = null;
this.addListener = function(fn) {
if (realised) {
return fn(val);
}
return listeners.push(fn);
};
this.realise = function(realisedVal) {
var listener, _i, _len, _results;
if (realised) {
throw new Error('Already realised');
}
val = realisedVal;
realised = true;
_results = [];
for (_i = 0, _len = listeners.length; _i < _len; _i++) {
listener = listeners[_i];
_results.push(listener(val));
}
return _results;
};
this.isRealised = function() {
return realised;
};
}
return Promise;
})();
protocol.extend(IPromise, Promise, [
'when', function(prom, fn) {
return prom.addListener(fn);
}
], [
'deliver', function(prom, val) {
return prom.realise(val);
}
]);
return promise = {
IPromise: IPromise
IPromise: IPromise,
Promise: Promise
};
});

219

lib/sequence.js

@@ -9,3 +9,3 @@ // Generated by CoffeeScript 1.3.3

(function(root, factory) {
var dispatch, protocol, stream, tail, _base, _ref, _ref1;
var ISeq, IStream, ISync, dispatch, promise, protocol, sink, tail, _base, _ref, _ref1;
if ("object" === typeof exports) {

@@ -15,6 +15,10 @@ protocol = require('./protocol');

dispatch = require('./dispatch');
stream = require('./stream');
module.exports = factory(protocol, tail, dispatch, stream);
ISeq = require('./protocols/ISeq');
ISync = require('./protocols/ISync');
IStream = require('./protocols/IStream');
sink = require('./stream/sink');
promise = require('./promise');
module.exports = factory(protocol, tail, dispatch, ISeq, ISync, IStream, sink, promise);
} else if (typeof define !== "undefined" && define !== null ? define.amd : void 0) {
define(['./protocol', './tail', './dispatch', './stream'], factory);
define(['./protocol', './tail', './dispatch', './protocols/ISeq', './protocols/ISync', './protocols/IStream', './stream/sink', './promise'], factory);
} else {

@@ -27,9 +31,9 @@ if ((_ref = root.cosy) == null) {

}
root.cosy.lang.sequence = factory(root.cosy.protocol, root.cosy.tail, root.cosy.dispatch(root.cosy.stream));
root.cosy.lang.sequence = factory(root.cosy.protocol, root.cosy.tail, root.cosy.dispatch, root.cosy.protocols.ISeq, root.cosy.protocols.ISync, root.cosy.protocols.IStream, root.cosy.stream.sink, root.cosy.lang.promise);
}
})(this, function(protocol, tail, _arg, _arg1) {
var ISeq, IStream, LazySeqence, Sequence, StreamSequence, concat, cons, drop, dropWhile, empty, filter, first, fn$, lazy, map, partition, reduce, rest, seq, sequence, take, takeWhile, vec;
})(this, function(protocol, tail, _arg, ISeq, ISync, IStream, sink, promise) {
var IPromise, LazySeqence, Promise, Sequence, SyncedLazySequence, concat, cons, drop, dropWhile, empty, filter, first, fn$, lazy, map, partition, reduce, rest, seq, sequence, skip, take, takeWhile, vec;
fn$ = _arg.fn$;
IStream = _arg1.IStream;
ISeq = protocol.define('ISeq', 'A logical list', ['first', 'Returns the first item in the collection. If coll is null, returns null'], ['rest', 'Returns a sequence of the items after the first. If there are no more items, returns a logical sequence for which seq returns null.']);
skip = IStream.skip;
IPromise = promise.IPromise, Promise = promise.Promise;
protocol.extend(ISeq, null, [

@@ -80,15 +84,25 @@ 'first', function(coll) {

function LazySeqence(body) {
function LazySeqence(body, coll) {
if (typeof body !== 'function') {
throw new Error('body must be a function');
}
this.realised = false;
this.realise = function() {
var res;
res = body();
if ((coll != null) && (first(coll)) === skip) {
if (coll != null ? coll.isSink : void 0) {
return cons(skip, this);
}
coll = rest(coll);
}
res = body(coll);
while (res instanceof LazySeqence) {
res = res.realise();
}
this.realise = function() {
return res;
};
if ((first(res)) !== skip) {
this.realised = true;
this.realise = function() {
return res;
};
}
return res;

@@ -101,18 +115,32 @@ };

})(Sequence);
StreamSequence = (function() {
SyncedLazySequence = (function(_super) {
function StreamSequence(stream) {
this.stream = stream;
__extends(SyncedLazySequence, _super);
function SyncedLazySequence(body, coll) {
var ready,
_this = this;
SyncedLazySequence.__super__.constructor.call(this, body, coll);
ready = new Promise;
ISync.onReady(coll, function() {
_this.realise();
if (_this.realised) {
return IPromise.deliver(ready);
}
});
this.onReady = function(fn) {
return IPromise.when(ready, fn);
};
}
return StreamSequence;
return SyncedLazySequence;
})();
protocol.extend(IStream, StreamSequence, [
'tap', function(coll, fn) {
return stream.tap(coll.stream, fn);
})(LazySeqence);
protocol.extend(ISync, SyncedLazySequence, [
'ready', function(s) {
return s.realised;
}
], [
'emit', function(coll, val) {
return stream.emit(coll.stream, val);
'onReady', function(s, fn) {
return s.onReady(fn);
}

@@ -123,3 +151,3 @@ ]);

if (protocol["implements"](IStream, coll)) {
coll = new StreamSequence(coll);
coll = sink(coll);
} else {

@@ -147,5 +175,15 @@ throw new Error('Does not implement ISeq');

};
lazy = function(body) {
return new LazySeqence(body);
};
lazy = fn$({
1: function(body) {
return new LazySeqence(body);
},
2: function(coll, body) {
coll = seq(coll);
if (protocol["implements"](ISync, coll)) {
return new SyncedLazySequence(body, coll);
} else {
return new LazySeqence(body, coll);
}
}
});
empty = function(colls) {

@@ -163,2 +201,5 @@ var coll, _i, _len;

var makeVec;
if (coll != null ? coll.isSink : void 0) {
throw new Error('Cannot vec a sink');
}
makeVec = function(coll, A) {

@@ -179,20 +220,33 @@ var item;

};
map = function() {
var colls, fn;
fn = arguments[0], colls = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
if (empty(colls)) {
return null;
map = fn$({
0: function(fn, coll) {
if (empty(colls)) {
return null;
}
return lazy(coll, function(coll) {
return cons(fn(first(coll)), map(fn, rest(coll)));
});
},
$: function() {
var colls, fn;
fn = arguments[0], colls = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
if (empty(colls)) {
return null;
}
return lazy(function() {
var coll, firsts, rests, _i, _len;
firsts = [];
rests = [];
for (_i = 0, _len = colls.length; _i < _len; _i++) {
coll = colls[_i];
if (coll != null ? coll.isSink : void 0) {
throw new Error('Cannot multi map a sink');
}
firsts.push(first(coll));
rests.push(rest(coll));
}
return cons(fn.apply(null, firsts), map.apply(null, [fn].concat(__slice.call(rests))));
});
}
return lazy(function() {
var coll, firsts, rests, _i, _len;
firsts = [];
rests = [];
for (_i = 0, _len = colls.length; _i < _len; _i++) {
coll = colls[_i];
firsts.push(first(coll));
rests.push(rest(coll));
}
return cons(fn.apply(null, firsts), map.apply(null, [fn].concat(__slice.call(rests))));
});
};
});
reduce = fn$({

@@ -209,2 +263,5 @@ 2: function(fn, coll) {

var doReduce;
if (coll != null ? coll.isSink : void 0) {
throw new Error('Cannot reduce a sink');
}
doReduce = function(fn, val, coll) {

@@ -226,3 +283,3 @@ var nextVal;

}
return lazy(function() {
return lazy(coll, function(coll) {
var f, r;

@@ -239,9 +296,9 @@ f = first(coll);

take = function(n, coll) {
return lazy(function() {
if (!n) {
return null;
}
if (empty([coll])) {
return null;
}
if (!n) {
return null;
}
if (empty([coll])) {
return null;
}
return lazy(coll, function(coll) {
return cons(first(coll), take(n - 1, rest(coll)));

@@ -251,9 +308,9 @@ });

takeWhile = function(pred, coll) {
return lazy(function() {
if (empty([coll])) {
return null;
}
if (!pred(first(coll))) {
return null;
}
if (empty([coll])) {
return null;
}
if (!pred(first(coll))) {
return null;
}
return lazy(coll, function(coll) {
return cons(first(coll), takeWhile(pred, rest(coll)));

@@ -263,9 +320,9 @@ });

drop = function(n, coll) {
return lazy(function() {
if (!n) {
return coll;
}
if (empty([coll])) {
return null;
}
if (!n) {
return coll;
}
if (empty([coll])) {
return null;
}
return lazy(coll, function(coll) {
return drop(n - 1, rest(coll));

@@ -275,9 +332,9 @@ });

dropWhile = function(pred, coll) {
return lazy(function() {
if (empty([coll])) {
return null;
}
if (!pred(first(coll))) {
return coll;
}
if (empty([coll])) {
return null;
}
if (!pred(first(coll))) {
return coll;
}
return lazy(coll, function(coll) {
return dropWhile(pred, rest(coll));

@@ -291,6 +348,6 @@ });

3: function(n, step, coll) {
return lazy(function() {
if (empty([coll])) {
return null;
}
if (empty([coll])) {
return null;
}
return lazy(coll, function(coll) {
return cons(take(n, coll), partition(n, step, drop(step, coll)));

@@ -307,8 +364,6 @@ });

1: function(x) {
return lazy(function() {
return x;
});
return x;
},
2: function(x, y) {
return lazy(function() {
return lazy(x, function(x) {
if (empty([x])) {

@@ -315,0 +370,0 @@ return y;

@@ -5,8 +5,12 @@ // Generated by CoffeeScript 1.3.3

(function(root, factory) {
var protocol, _base, _ref, _ref1;
var IStream, ISync, protocol, sequence, sink, _base, _ref, _ref1;
if ("object" === typeof exports) {
protocol = require('./protocol');
module.exports = factory(protocol);
IStream = require('./protocols/IStream');
sequence = require('./sequence');
ISync = require('./protocols/ISync');
sink = require('./stream/sink');
module.exports = factory(protocol, IStream, sequence, ISync, sink);
} else if (typeof define !== "undefined" && define !== null ? define.amd : void 0) {
define(['./protocol'], factory);
define(['./protocol', './protocols/IStream', './sequence', './protocols/ISync', './stream/sink'], factory);
} else {

@@ -19,10 +23,96 @@ if ((_ref = root.cosy) == null) {

}
root.cosy.lang.stream = factory(root.cosy.protocol);
root.cosy.lang.stream = factory(root.cosy.lang.protocol, root.cosy.lang.protocols.IStream, root.cosy.lang.sequence, root.cosy.lang.protocols.ISync, root.cosy.lang.stream.sink);
}
})(this, function(protocol) {
var IStream, stream;
IStream = protocol.define('IStream', ['tap', 'Register on emit'], ['emit', 'Emit a value']);
})(this, function(protocol, IStream, sequence, ISync, sink) {
var Source, emit, skip, source, stream, tap;
skip = IStream.skip;
Source = (function() {
function Source(seq) {
var emit, emitAll, emitSync, init, initialised,
_this = this;
this.fns = [];
initialised = false;
init = function() {
initialised = true;
if (protocol["implements"](ISync, seq)) {
return ISync.onReady(seq, emitSync);
} else {
return emitAll();
}
};
emitSync = function() {
var value;
value = sequence.first(seq);
emit(value);
seq = sequence.rest(seq);
return ISync.onReady(seq, emitSync);
};
emitAll = function() {
var f, _results;
_results = [];
while (f = sequence.first(seq)) {
if (f !== skip) {
emit(f);
_results.push(seq = sequence.rest(seq));
} else {
_results.push(void 0);
}
}
return _results;
};
emit = function(val) {
var fn, _i, _len, _ref, _results;
_ref = _this.fns;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
fn = _ref[_i];
_results.push(fn(val));
}
return _results;
};
this.tap = function(fn) {
_this.fns.push(fn);
if (!initialised) {
return init();
}
};
}
return Source;
})();
protocol.extend(IStream, Source, [
'tap', function(s, fn) {
return s.tap(fn);
}
], [
'emit', function(s, val) {
throw new Error('Cannot emit to a source');
}
]);
source = function(seq) {
if (protocol["implements"](IStream, seq)) {
return seq;
}
if (!protocol["implements"](sequence.ISeq, seq)) {
throw new Error('Not a sequence');
}
return new Source(seq);
};
tap = function(s, fn) {
s = source(s);
return IStream.tap(s, fn);
};
emit = function(s, val) {
return IStream.emit(s, val);
};
return stream = {
IStream: IStream
IStream: IStream,
sink: sink,
source: source,
skip: skip,
tap: tap,
emit: emit
};
});
{
"name": "cosy-lang",
"version": "0.1.0",
"description": "cosy language extension library",
"main": "lib/lang",
"scripts": {
"prepublish": "coffee -bc -o lib src",
"test": "./node_modules/.bin/mocha -u tdd --compilers coffee:coffee-script test"
},
"repository": {
"type": "git",
"url": "git://github.com/getcosy/lang.git"
},
"devDependencies": {
"chai": "1.1.x",
"coffee-script": "1.3.x",
"coffeelint": "0.5.x",
"colors": "0.6.0-1",
"jake": "0.3.x",
"mocha": "1.2.x",
"sinon": "1.3.x"
},
"contributors": [
{
"name": "Neel Upadhyaya"
}
],
"license": "MIT"
}
"name": "cosy-lang",
"version": "0.2.0",
"description": "cosy language extension library",
"main": "lib/lang",
"scripts": {
"prepublish": "coffee -bc -o lib src",
"test": "./node_modules/.bin/mocha -u tdd --compilers coffee:coffee-script test"
},
"repository": {
"type": "git",
"url": "git://github.com/getcosy/lang.git"
},
"devDependencies": {
"chai": "1.1.x",
"coffee-script": "1.3.x",
"coffeelint": "0.5.x",
"colors": "0.6.0-1",
"jake": "0.3.x",
"mocha": "1.2.x",
"sinon": "1.3.x"
},
"contributors": [
{
"name": "Neel Upadhyaya"
}
],
"license": "MIT"
}

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