Socket
Socket
Sign inDemoInstall

free-monoid

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    free-monoid

Free monoid in JavaScript


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
6.62 kB
Created
Weekly downloads
 

Readme

Source

Free Monoid

npm package: https://www.npmjs.com/package/free-monoid

Free moniod in JavaScript

const M = freeMonoid(operator);

Identity: (M)

(M)(a) = (a) = (a)(M)

Associative

((a)(b))(c) = (a)(b)(c) = (a)((b)(c))

Installation

$ npm install free-monoid

Usage

const freeMonoid = require("free-monoid");

Additive monoid derived from free-monoid

const _M = () => freeMonoid(operator);
const operator = list => {
  list.eval = () => list.val.reduce((a, b) => (a + b));
};
const M = _M();

const x = (M)(1);
const y = (M)(2);
const z = (M)(5);

console.log(x);
console.log(
  (M)(x) // === (x) left identity
);
console.log(
  (x)(M) // === (x) right identity
);

const xyz = (x)(y)(z);
console.log(xyz);
console.log(xyz.eval()); //lazy eval
8

List monad derived from free-monoid

https://www.npmjs.com/package/list-monad

monad laws validation
const util = require("util");
const validate = a => b => util.inspect(a) === util.inspect(b)
  ? true : false;

const f = x => (M)(x + 7);
const g = x => (M)(x * 5);
const a = 9;
const m = (M)(3)(5)(7);

console.log(
  validate(
    (M)(a).bind(f)
  )(
    f(a)
  )
);
console.log(
  validate(
    m.bind(M)
  )(
    m
  )
);
console.log(
  validate(
    m.bind(f)
      .bind(g)
  )(
    m.bind(x => f(x)
      .bind(g))
  )
);
true
true
true

Other derivatives from free-monoid

Timeline Monoid

https://www.npmjs.com/package/timeline-monoid

Keywords

FAQs

Last updated on 25 Jun 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc