Created
September 13, 2019 19:50
-
-
Save evaporei/cd258ce397e058a898941f78572ff7a6 to your computer and use it in GitHub Desktop.
Category Theory - Monoid Strings and Arrays
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
| String.prototype.mappend = function (x: String): String { | |
| return this + x | |
| } | |
| String.prototype.mempty = function (): String { | |
| return "" | |
| } | |
| console.log( | |
| 'String mappend:', | |
| String("category").mappend(" ").mappend("theory") | |
| ) // "category theory" | |
| console.log('String mempty:', String().mempty()) // "" | |
| Array.prototype.mappend = function (x: Array): Array { | |
| return this.concat(x) | |
| } | |
| Array.prototype.mempty = function (): Array { | |
| return [] | |
| } | |
| console.log('Array mappend:', Array(1, 2).mappend([3])) // [1, 2, 3] | |
| console.log('Array mempty:', Array().mempty()) // [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment