Skip to content

[pull] master from hemanth:master #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update readme.md
  • Loading branch information
Jethro Larson authored Sep 23, 2020
commit b33ace04d432df161db9512802fa53edd3927cb9
15 changes: 6 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ randIter.next() // Each execution gives a random value, expression is evaluated

## Monoid

An object with a function that "combines" that object with another of the same type.
An object with a function that "combines" that object with another of the same type (semigroup) which has an "identity" value.

One simple monoid is the addition of numbers:

Expand All @@ -548,11 +548,13 @@ One simple monoid is the addition of numbers:
```
In this case number is the object and `+` is the function.

An "identity" value must also exist that when combined with a value doesn't change it.
When any value is combined with the "identity" value the result must be the original value. The identity must also be commutative.

The identity value for addition is `0`.
```js
1 + 0 // 1
0 + 1 // 1
1 + 0 === 0 + 1
```

It's also required that the grouping of operations will not affect the result (associativity):
Expand All @@ -573,15 +575,10 @@ The identity value is empty array `[]`
;[1, 2].concat([]) // [1, 2]
```

If identity and compose functions are provided, functions themselves form a monoid:
As a counterexample, subtraction does not form a monoid because there is no commutative identity value:

```js
const identity = (a) => a
const compose = (f, g) => (x) => f(g(x))
```
`foo` is any function that takes one argument.
```
compose(foo, identity) ≍ compose(identity, foo) ≍ foo
0 - 4 === 4 - 0 // false
```

## Monad
Expand Down