Socket
Socket
Sign inDemoInstall

monadic.js-playground

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

monadic.js-playground

Here you can play with Haskell-like do notation language extension


Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

monadic.js-playground

To install package from npm type:

npm install monadic.js-playground

To build type into root dir:

npm install
webpack

To run type into root dir:

node build/monadic.dev.js

# or (depend on NODE_ENV value during build stage)

node build/monadic.min.js

If you wanna change something, entry point is here: index.js

Enjoy ;)

How it looks like:

const unit = {};
const log = msg => console.log(msg);
const curry2 = fn => a => b => fn(a, b);
const fetch = curry2((url, cb) => setTimeout(cb, 100, url));
const apply = (fn, arg) => fn(arg);

const listMonad = apply(() => {
    const mreturn = a => [a];
    const mbind = (mval, fn) => mval
        .map(val => fn(val))
        .reduce((prev, next) => prev.concat(next), []);

    // MonadPlus
    const mzero = [];
    const mplus = (a, b) => a.concat(b);

    const guard =  p => p ? mreturn(unit) : mzero;

    return {
        mreturn,
        mbind,
        mzero,
        mplus,
        guard
    };
}, null);

const contMonad = {
    mreturn: a => fn => fn(a),
    mbind: (mval, fn) => c => mval(val => fn(val)(c))
};

const demoList = do listMonad {
    a <- [1, 2, 3];
    b <- do listMonad {
        c <- [1, 2, 3];
        d <- [1, 2, 3];
        return c + d;
    };
    listMonad.guard(a + b > 7);
    return a + b;
};

const demoCont = do contMonad {
    data         <- fetch("data");
    moreData     <- fetch("data_data");
    evenMoreData <- fetch(moreData + "_data_data");
    return { data, moreData, evenMoreData };
};

// DEMO:

log(demoList);
demoCont(log);

Keywords

FAQs

Package last updated on 14 Jun 2017

Did you know?

Socket

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.

Install

Related posts

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