Options
All
  • Public
  • Public/Protected
  • All
Menu

funland-laws

Funland is a specification of common algebraic structures for JavaScript, TypeScript and Flow, based on Fantasy Land and compatible with static-land.

funland-laws is a sub-project of Funland exposing type-class laws for usage in tests.

Usage

For the TypeScript / Flow types, which are very light (no accompanying JavaScript code, just types):

npm install --save funland

For the laws:

npm install --save funland-laws

Usage of laws mostly makes sense in tests, being built for property-based testing, so usage of jsverify is recommended, but not required.

Documentation

API docs:

Exposed type classes:

Testing the Included Type-class Laws

The included laws are meant for usage with property-based testing, so you'll need something like jsverify as a dependency.

And then you can do something like this:

import * as jv from "jsverify"
import { Setoid } from "funland"
import { Equiv, SetoidLaws } from "funland-laws"

export function setoidCheck<A>(
  genA: jv.Arbitrary<A>,
  F: Setoid<A>,
  lawsRef?: SetoidLaws<A>) {

  const laws = lawsRef || new SetoidLaws<A>(F)
  const eq = (p: Equiv<boolean>) => p.lh === p.rh

  jv.property("setoid.reflexivity", genA,
    x => eq(laws.reflexivity(x)))

  jv.property("setoid.symmetry", genA, genA,
    (x, y) => eq(laws.symmetry(x, y)))

  jv.property("setoid.transitivity", genA, genA, genA,
    (x, y, z) => eq(laws.transitivity(x, y, z)))
}

Such integration is currently not provided by Funland, however the project's repository has code to use for inspiration, see github.com/.../funland-laws/test-common.

Modules: UMD and ES 2015

The library has been compiled using UMD (Universal Module Definition), so it should work with CommonJS and AMD, for standalone usage in browsers or Node.js.

But it also provides a module definition in package.json, thus providing compatibility with ECMAScript 2015 modules, for usage when used with a modern JS engine, or when bundling with a tool chain that understands ES2015 modules, like Rollup or Webpack.

TypeScript or Flow?

Funland exposes both TypeScript and Flow type annotations out of the box.

License

All code in this repository is licensed under the MIT license.

Index

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc