Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Fantasy do is a generalization of mozilla's task.js
from Promises/A+ to any monad, as defined by the Fantasy Land Spec. While usage is syntactically similar to Haskell's Do Notation, it's implemented completely at runtime with ES6 generators.
Fantasy Do requires ES6 generators. In node, you can enable these with the --harmony
option.
If you happen to have a browser with ES6 support, use the included fantasydo.min.js
with your module loader of choice, or just with a script
tag.
The library is available for node.js
on npm
under fantasydo
If your monad only calls the argument to the chain
function once ('non-branching'), you can use Fantasy Do's normal, high-performance mode.
First, you'll need a monad. See the Fantasy Land Implementation List to find some monads that may work for you.
Here's a very simple Maybe
monad:
var Maybe = {}
Maybe.chain = function(f) {
if(this.val !== null)
return f(this.val);
return this;
};
Maybe.of = function(t) {
return {"val" : t, "chain" : Maybe.chain};
};
Maybe.none = function() {
return {"val" : null, "chain" : Maybe.chain};
};
Now, we can write a function that depends on multiple maybe values, and will only complete if all of them are not none
:
Do(function*(){
var a = yield testm.of(7);
var b = yield testm.of(a + 9);
return b;
}).val // => 16
Do(function*(){
var a = yield testm.of(7);
var q = yield testm.none();
var b = yield testm.of(a + 9);
return b;
}, testm).val // => null
Fantasy Do also supports monads that may call their chain
parameter multiple times, like the non-determinism context (aka the list monad). Without the ability to copy generator state, this works by re-runninng the generator from the beginning for each branch. This may behave strangely if your bind argument has significant side-effects.
Array.prototype.chain = function(f) {
let next = [];
let len = this.length;
this.forEach(function(it){
let v = f(it);
v.forEach(function(it){next.push(it)});
});
return next;
};
Array.prototype.of = function(t) {return [t];}
then,
Do.Multi(function*(){
let c = yield [1, 2];
let d = yield [c + 1, c + 2];
return d;
} // => [2, 3, 3, 4]
To the extent possible under law,
Russell McClellan
has waived all copyright and related or neighboring rights to
Fantasy Do.
This work is published from:
United States.
FAQs
ES6 do-notation for fantasyland
The npm package fantasydo receives a total of 1 weekly downloads. As such, fantasydo popularity was classified as not popular.
We found that fantasydo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.