npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

algebra.laws

v0.1.6

Published

Verifies structures against fantasy-land algebra

Downloads

19

Readme

algebra.laws

NPM

npm version Coverage Status Build Status Dependency Status

Validates algebraic structures' laws. Laws conform to the Fantasy Land specification.

Example

(Coming soon)

Installing

You can get this package from npm. If you're in a browser environment you can use Browserify.

    $ npm install <tbd>

CommonJS

(Coming soon)

Using with AMD

(Coming soon)

Using without modules

(Coming soon)

From Source

If you want to work with this libraries source you'll need Git and Node.js, and to run these commands:

    $ git clone git://github.com/reaganthomas/algebra.laws.git
    $ cd algebra.laws
    $ npm install
    <tbd>

This will generate the distributable version of this library, dist/<pathToFile>, which you can load in any JavaScript environment.

Getting Started

This library provides laws for verifying the correctness of an algebraic structure according to the Fantasy Land specification. This is done by generating random inputs and checking that the algebraic laws hold true for the given structure.

To use these laws your algebraic structures must implement the isEqual function:

var Identity = {
  // ...
  isEqual: function(b) {
    if(this.isEmpty && b.isEmpty) return true;
    return (!this.isEmpty && this.value === b.value);
  }
  // ...
}

Laws

  • Applicatives
    1. Identity
    2. Composition
    3. Homomorphism
    4. Interchange
  • Chains
    1. Associativity
  • Functors
    1. Identity
    2. Composition
  • Monads
    1. Left Identity
    2. Right Identity
  • Monoids
    1. Left Identity
    2. Right Identity
  • Semigroups
    1. Associativity

Using the Laws

To verify a data structure correctly adheres to its algebraic laws you need only pass in a function that constructs said structure holding a single value.

For example, if you have an Identity structure and want to verify that it adheres to the Semigroup's law of associativity:

function makeIdentity(a) {
  return new Identity(a);
}

laws.semigroup.associativity(makeIdentity).asTest({ verbose: true })();
// + OK passed 100 tests

Note: applying the law to a constructor function gives you back a [Claire][] property. There are different ways to use this object, but the easiest is to use the asTest(configuration) method to return a test function. When invoked (with no parameters) this test function will repeatedly generate random inputs to test your implementation against the law.

If any of the inputs results in your structure failing a law an error is thrown with information about why the structure failed. You can control the amount of detail shown and the number of tests performed by passing a configuration object to the asTest method. By default the reports are concise and 100 random tests are performed.

class Configuration where
  verbose :: Bool -- * whether to output a detailed report
  times   :: Int  -- * number of random tests to perform

Note: if verbose is false no message will be printed by default.

Platform Support

This library assumes an ECMAScript5 environment, but can be supported in ECMAScript3 and up by the use of the es5-shim.

License

Copyright (c) 2015 Reagan Thomas.

Released under the MIT license