0.1.1 • Published 6 years ago

pdef v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Predefine or postdefine expressions arguments

pdef

Predefinition and postdefinition

Installation

NPM

npm install --save pdef

Usage

const postdef = require('pdef').postdef;
const predef = require('pdef').predef;
// or
import {postdef, predef} from 'pdef';


const squarePost = (a, b, c) => postdef(
  ({p}) => Math.sqrt(p * (p-a) * (p-b) * (p-c))
).where({p: (a + b + c)/2});

const squarePre = (a,b,c) => predef({p: (a+b+c)/2}).in(({p}) => Math.sqrt(p * (p-a) * (p-b) * (p-c)));


squarePost(7, 8, 9);
// => 26.832815729997478
squarePost(7, 8, 9) === squarePre(7, 8, 9);
// => true