Socket
Book a DemoInstallSign in
Socket

monoid-map

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

monoid-map

An map as a monoid

latest
Source
npmnpm
Version
0.1.5
Version published
Maintainers
1
Created
Source

Monoid Map

Build Status

Fantasy Land Complaint! Indigenous Complaint!

An implementation of a map as a monoid that expects all of it's elements to also be monoids.

Examples

Simple Example w/ inner lists:

var Map = require("monoid-map");

var first = new Map({
    items: ["potion", "dagger"],
    spells: ["smite", "ignite"]
});

var second = new Map({
    items: ["mallet", "boots"],
    spells: ["exhaust", "teleport"]
});

var merged = first.concat(second);
console.log(merged.toObj());
/*
Prints:
{
    items: ["potion", "dagger", "mallet", "boots"],
    spells: ["smite", "ignite", "exhaust", "teleport"]
}
*/

More complex monoid example:

var Map          = require("monoid-map");
var Max          = require("monoid-max");
var Min          = require("monoid-min");
var Average      = require("monoid-average");
var StdDeviation = require("monoid-std-deviation");

var ages = [22, 23, 21, 25, 27, 30, 25]

var result = ages.map(function(n) {
    return new Map({
        max:     new Max(n),
        min:     new Min(n),
        average: new Average(n),
        stddev:  new StandardDeviation(n)
    });
}).reduce(function(m, n) {
    return m.concat(n);
}).toNative();

console.log(result);
/*
Prints:
{
    max: 30,
    min: 21,
    average: 24.714285714286,
    stddev: 2.86428
}
*/

FAQs

Package last updated on 28 Nov 2013

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