Sum

monoid. Sum

new Sum()

The Sum monoid. Sum can be used to sum up multiple numbers into a final number via concatenation

Version:
  • 3.0.0
Source:
Example
const {Sum} = require('futils').monoid;

Sum(1); // -> Sum(1)

Sum(1).value; // -> 1

Extends

  • module:generics/Show
  • module:generics/Eq
  • module:generics/Ord

Methods

(static) empty() → {Sum}

Monoid implementation for Sum. Returns a Sum of 0

Source:
Returns:
Type:
Sum

The empty Sum

Example
const {Sum} = require('futils').monoid;

Sum.empty(); // -> Sum(0)

(static) of(a) → {Sum}

Lifts a value into a Sum. Returns a Sum of 0 if the value isn't a number

Source:
Parameters:
Name Type Description
a any

The value to lift

Returns:
Type:
Sum

A new Sum

Example
const {Sum} = require('futils').monoid;

Sum.of(1);    // -> Sum(1)
Sum.of(null); // -> Sum(0)
Sum.of({});   // -> Sum(0)

concat(a) → {Sum}

Concatenates a Sum with another using addition

Source:
Parameters:
Name Type Description
a Sum

The Sum instance to concatenate with

Returns:
Type:
Sum

A new Sum

Example
const {Sum} = require('futils').monoid;

const sum = Sum(1);

sum.concat(Sum(1)); // -> Sum(2)