op

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

Source:

Methods

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

Source:

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

const {and} = re­quire('fer­rum');

and("", true) // => ""
and(true, 42) // => 42

and(true)("") // => ""
and(42)(true) // => 42
Parameters:
Name Type Description
a A
b B
Returns:
Type
A | B

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

Source:

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

const {or} = re­quire('fer­rum');

or(42, false) // => 42
or(true, 5) // => 5

or(false)(42) // => 42
or(5)(true) // => 5
Parameters:
Name Type Description
a A
b B
Returns:
Type
A | B

(inner) not(a) → {Boolean}

Source:

The ! as a func­tion

const {not} = re­quire('fer­rum');

not(42); // => false
not(null); // => true
Parameters:
Name Type Description
a A
Returns:
Type
Boolean

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

Source:

NAND as a func­tion.

const {nand} = re­quire('fer­rum');

nand(true, 42) // => false
nand(null, false) // => true
nand(true, false) // => true

nand(true)(42) // => false
nand(null)(false) // => true
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 {nor} = re­quire('fer­rum');

nor(true, true) // => false
nor(false, true) // => false
nor(false, false) // => true

nor(true)(true) // => false
nor(false)(true) // => false
nor(false)(false) // => true
Parameters:
Name Type Description
a A
b B
Returns:
Type
Boolean

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

Source:

XOR as a func­tion.

const {xor} = re­quire('fer­rum');

xor(true, true) // => false
xor(false, true) // => true
xor(true, false) // => true
xor(false, false) // => false

xor(true)(true) // => false
xor(false)(true) // => true
xor(true)(false) // => true
xor(false)(false) // => false
Parameters:
Name Type Description
a A
b B
Returns:
Type
Boolean

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

Source:

XNOR as a func­tion.

const {xnor} = re­quire('fer­rum');

xnor(true, true) // => true
xnor(false, true) // => false
xnor(true, false) // => false
xnor(false, false) // => true

xnor(true)(true) // => true
xnor(false)(true) // => false
xnor(true)(false) // => false
xnor(false)(false) // => true
Parameters:
Name Type Description
a A
b B
Returns:
Type
Boolean

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

Source:

=== as a func­tion

const {is, count, fil­ter, pipe} = re­quire('fer­rum');

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

is(42)(42) // => true
is(42)("") // => false
is({})({}) // => false (Can only suc­cess­fully com­pare prim­it­ives)

// 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­sert(cnt == 42);
Parameters:
Name Type Description
a A
b B
Returns:
Type
Boolean

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

Source:

!== as a func­tion

const {aint, list, fil­ter, pipe} = re­quire('fer­rum');

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

aint(42)(42) // => false
aint(42)("") // => true
aint({})({}) // => false (Can only suc­cess­fully com­pare prim­it­ives)

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

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

Source:

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

const {plus, list, map, pipe} = re­quire('fer­rum');

plus(3, 4) // => 7
plus(3, -4) // => -1; Can also be used for sub­strac­tion
plus("foo", "bar") // => "foobar"

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

// Sub­tract one from each ele­ment in the list
pipe(
  [1,2,3,4,5],
  plus(-1),
  list
);
// => [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) mul(a, b) → {Number}

Source:

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

const {mul, list, map, pipe} = re­quire('fer­rum');

mul(3, 4) // => 12
mul(3, 1/​10) // => -1; Can also be used for s

plus(3)(4) // => 7
plus(3)(-4) // => -1; Can also be used for sub­strac­tion

// Di­vide each ele­ment in the list by ten
pipe(
  [1,2,3,4,5],
  map(div(1/​10)),
  list
);
// [0.1, 0.2, 0.3, 0.4, 0.5]

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