You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+10-12Lines changed: 10 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -305,14 +305,12 @@ const g = x => x * 2;
305
305
```
306
306
307
307
## 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.
309
309
310
-
Array Implementation:
310
+
ES2015 adds `Array.of` making arrays a pointed functor.
311
311
312
312
```js
313
-
Array.prototype.of= (v) => [v];
314
-
315
-
[].of(1) // [1]
313
+
Array.of(1) // [1]
316
314
```
317
315
318
316
## Lift
@@ -377,29 +375,29 @@ randIter.next(); // Each execution gives a random value, expression is evaluated
377
375
378
376
## Monoid
379
377
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.
381
379
382
-
One very simple monoid is numbers and addition:
380
+
One simple monoid is the addition of numbers:
383
381
384
382
```js
385
383
1+1; // 2
386
384
```
385
+
In this case number is the object and `+` is the function.
387
386
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.
389
388
389
+
The identity value for addition is `0`.
390
390
```js
391
391
1+0; // 1
392
392
```
393
393
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):
397
395
398
396
```js
399
397
1+ (2+3) === (1+2) +3; // true
400
398
```
401
399
402
-
Array concatenation can also be said to be a monoid:
0 commit comments