Skip to content
/ vop Public

Value-orientated programming tools for JavaScript ๐Ÿ’Ž

License

Notifications You must be signed in to change notification settings

njlr/vop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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 

About

Value-orientated programming tools for JavaScript ๐Ÿ’Ž

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published