Skip to content

Commit da2cca1

Browse files
jethrolarsonhemanth
authored andcommitted
Used Array.of for pointed functor definition #77 (#86)
Also adjusted monoid description until my kid could understand it.
1 parent bc895ef commit da2cca1

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

readme.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,12 @@ const g = x => x * 2;
305305
```
306306

307307
## Pointed Functor
308-
A functor with an `of` function that puts _any_ single value into that functor.
308+
An object with an `of` function that puts _any_ single value into it.
309309

310-
Array Implementation:
310+
ES2015 adds `Array.of` making arrays a pointed functor.
311311

312312
```js
313-
Array.prototype.of = (v) => [v];
314-
315-
[].of(1) // [1]
313+
Array.of(1) // [1]
316314
```
317315

318316
## Lift
@@ -377,29 +375,29 @@ randIter.next(); // Each execution gives a random value, expression is evaluated
377375

378376
## Monoid
379377

380-
A monoid is some data type and a two parameter function that "combines" two values of the type, where an identity value that does not affect the result of the function also exists.
378+
An object with a function that "combines" that object with another of the same type.
381379

382-
One very simple monoid is numbers and addition:
380+
One simple monoid is the addition of numbers:
383381

384382
```js
385383
1 + 1; // 2
386384
```
385+
In this case number is the object and `+` is the function.
387386

388-
The data type is number and the function is `+`, the addition of two numbers.
387+
An "identity" value must also exist that when combined with a value doesn't change it.
389388

389+
The identity value for addition is `0`.
390390
```js
391391
1 + 0; // 1
392392
```
393393

394-
The identity value is `0` - adding `0` to any number will not change it.
395-
396-
For something to be a monoid, it's also required that the grouping of operations will not affect the result:
394+
It's also required that the grouping of operations will not affect the result (associativity):
397395

398396
```js
399397
1 + (2 + 3) === (1 + 2) + 3; // true
400398
```
401399

402-
Array concatenation can also be said to be a monoid:
400+
Array concatenation also forms a monoid:
403401

404402
```js
405403
[1, 2].concat([3, 4]); // [1, 2, 3, 4]

0 commit comments

Comments
 (0)