1.1.0 • Published 6 years ago

@njlr/vop v1.1.0

Weekly downloads
8
License
-
Repository
-
Last release
6 years ago

vop

Value-orientated programming tools for JavaScript 💎

Travis

yarn add @njlr/vop

Why?

JavaScript does not support custom value-types, but we can get most of the way there using the pipeline operator (|>) and a comparison library.

The first concept we need to abstract away is equality. Here, an equality is defined as an object with hashCode and equals. JavaScript's default equality might look like this:

const strictEquality = {
  hashCode: _ => 0, 
  equals: x => y => x === y, 
}; 

From an equality object, we can construct an equals function:

import { equalsFromEquality } from '@njlr/vop'; 

const equals = equalsFromEquality(strictEquality);

equals(1)(1) // true

// Or using |> ...
1 |> equals(1) // true

We're almost there. This library implements structural equality, which has the behaviour we want!

import { equals } from '@njlr/vop';

const p = {
  x: 1, 
  y: 2,
};

p |> equals({ x: 1, y: 2}); // true

[ 1, 2, 3 ] |> equals([ 1, 2, 3]); // true

1 |> equals(1) // true

'abc' |> equals('abc') // true

Development

Dependencies are managed by Yarn:

yarn install --pure-lockfile

To run all tests:

yarn test 

To build the library:

yarn build 
1.1.0

6 years ago

1.0.0

6 years ago