Created
April 14, 2020 17:15
-
-
Save UserGalileo/6ad64ea8449d72cf091fb931457538d1 to your computer and use it in GitHub Desktop.
Functions under composition form a Monoid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // These are our elements | |
| const f = x => x + 1; | |
| const g = x => x + 2; | |
| const h = x => x + 3; | |
| // This is our neutral element, a function which does nothing | |
| const id = x => x; | |
| // This is the composition | |
| f(g(h(1))) // 7 | |
| // Which is associative by definition... | |
| compose(f, compose(g,h)) === compose(compose(f,g),h) | |
| // If we compose a function with "id", it's like calling the function directly | |
| compose(f, id) === f | |
| compose(id, f) === f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment