op

Provides com­mon javas­cript op­er­at­ors as curry­able func­tions.

Source:

Methods

(inner) aint(a, b) → {Boolean}

Source:

!== as a func­tion

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { as­sertSequenceEquals, aint, fil­ter, pipe } = re­quire('fer­rum');

as­sertIs(aint(42, 42), false);
as­sertIs(aint(42)(42), false);
as­sertIs(aint(42, ""), true);
as­sertIs(aint(42)(""), true);
as­sertIs(aint({}, {}), true); // Can only suc­cess­fully com­pare prim­it­ives
as­sertIs(aint({})({}), true);

// Re­move the value 42 from the list
as­sertSequenceEquals(
  fil­ter([1,2,3,4,42,5,24], aint(42)),
  [1,2,3,4,5,24]);
Parameters:
Name Type Description
a A
b B
Returns:
Type
Boolean

(inner) and(a, b) → {A|B}

Source:

The && op­er­ator as a func­tion.

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { and } = re­quire('fer­rum');

as­sertIs(and("",   true),   "");
as­sertIs(and(true)(""),     "");
as­sertIs(and(true, 42),     42);
as­sertIs(and(42)(true),     42);
Parameters:
Name Type Description
a A
b B
Returns:
Type
A | B

(inner) is(a, b) → {Boolean}

Source:

=== as a func­tion

See eq() for a con­tent aware com­par­ison func­tion.

const { stric­tEqual: as­sertIs } = re­quire('assert');
const {is, count, fil­ter, pipe} = re­quire('fer­rum');

as­sertIs(is(42, 42), true);
as­sertIs(is(42)(42), true);
as­sertIs(is(42, ""), false);
as­sertIs(is(42)(""), false);
as­sertIs(is({}, {}), false); // Can only suc­cess­fully com­pare prim­it­ives
as­sertIs(is({})({}), false);

// Count how many times the value `42` oc­curs in the list
const cnt = pipe(
  [42, 23, 1, 4, 17, 22, 42],
  fil­ter(is(42)),
  count);
as­sertIs(cnt, 2);
Parameters:
Name Type Description
a A
b B
Returns:
Type
Boolean

(inner) mul(a, b) → {Number}

Source:

The * op­er­ator as a func­tion:

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { as­sertSequenceEquals, mul, map } = re­quire('fer­rum');

as­sertIs(mul(3, 4), 12)
as­sertIs(mul(4)(3), 12);
as­sertIs(mul(10, 1/​2), 5); // Can also be used for di­vi­sion
as­sertIs(mul(1/​2)(10), 5);

// Di­vide each ele­ment in the list by two
as­sertSequenceEquals(
  map([2, 4, 6, 8], mul(1/​2)),
  [1, 2, 3, 4]);

NOTE: There is no di­vi­sion func­tion, if you need di­vi­sion just do this: const div = (a, b) => mul(a, 1/​b);

Parameters:
Name Type Description
a Number
b Number
Returns:
Type
Number

(inner) nand(a, b) → {Boolean}

Source:

NAND as a func­tion.

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { nand } = re­quire('fer­rum');

as­sertIs(nand(true, 42),    false);
as­sertIs(nand(true)(42),    false);
as­sertIs(nand(null, false), true);
as­sertIs(nand(null)(false), true);
as­sertIs(nand(true, false), true);
as­sertIs(nand(true)(false), true);
Parameters:
Name Type Description
a A
b B
Returns:
Type
Boolean

(inner) nor(a, b) → {Boolean}

Source:

NOR as a func­tion.

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { nor } = re­quire('fer­rum');

as­sertIs(nor(true, true),   false);
as­sertIs(nor(true)(true),   false);
as­sertIs(nor(false, true),  false);
as­sertIs(nor(false)(true),  false);
as­sertIs(nor(false, false), true);
as­sertIs(nor(false)(false), true);
Parameters:
Name Type Description
a A
b B
Returns:
Type
Boolean

(inner) not(a) → {Boolean}

Source:

The ! as a func­tion

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { not } = re­quire('fer­rum');

as­sertIs(not(42),   false);
as­sertIs(not(null), true);
Parameters:
Name Type Description
a A
Returns:
Type
Boolean

(inner) or(a, b) → {A|B}

Source:

The || op­er­ator as a func­tion

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { or } = re­quire('fer­rum');

as­sertIs(or(42, false), 42);
as­sertIs(or(false)(42), 42);
as­sertIs(or(5, true),   5);
as­sertIs(or(true)(5),   5);
Parameters:
Name Type Description
a A
b B
Returns:
Type
A | B

(inner) plus(a, b) → {Number|String}

Source:

The + op­er­ator as a func­tion:

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { as­sertSequenceEquals, plus, list, map, pipe } = re­quire('fer­rum');

as­sertIs(plus(3, 4), 7);
as­sertIs(plus(3)(4), 7);
as­sertIs(plus(3, -4), -1); // Can also be used for sub­trac­tion
as­sertIs(plus(3)(-4), -1);
as­sertIs(plus("foo", "bar"), "foobar");
as­sertIs(plus("bar")("foo"), "foobar");

// Sub­tract one from each ele­ment in the list
as­sertSequenceEquals(
  map([1, 2, 3, 4, 5], plus(-1)),
  [0, 1, 2, 3, 4]);

NOTE: There is no sub­tract func­tion, if you need sub­trac­tion just neg­ate the value to sub­tract with the op­er­ator please: const minus = (a, b) => plus(a, -b)

Parameters:
Name Type Description
a Number | String
b Number | String
Returns:
Type
Number | String

(inner) xnor(a, b) → {Boolean}

Source:

XNOR as a func­tion.

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { xnor } = re­quire('fer­rum');

as­sertIs(xnor(true, true),   true);
as­sertIs(xnor(true)(true),   true);
as­sertIs(xnor(false, false), true);
as­sertIs(xnor(false)(false), true);
as­sertIs(xnor(false, true),  false);
as­sertIs(xnor(true)(false),  false);
as­sertIs(xnor(true, false),  false);
as­sertIs(xnor(false)(true),  false);
Parameters:
Name Type Description
a A
b B
Returns:
Type
Boolean

(inner) xor(a, b) → {Boolean}

Source:

XOR as a func­tion.

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { xor } = re­quire('fer­rum');

as­sertIs(xor(true, true),   false);
as­sertIs(xor(true)(true),   false);
as­sertIs(xor(false, false), false);
as­sertIs(xor(false)(false), false);
as­sertIs(xor(false, true),  true);
as­sertIs(xor(true)(false),  true);
as­sertIs(xor(true, false),  true);
as­sertIs(xor(false)(true),  true);
Parameters:
Name Type Description
a A
b B
Returns:
Type
Boolean