Created
September 13, 2019 19:53
-
-
Save evaporei/c16c1c1d966cf661346c34755b038a13 to your computer and use it in GitHub Desktop.
Category Theory - Functor Container Implementation
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
| class Container<T> implements Functor<T> { | |
| private value: T | |
| constructor(value: T) { | |
| this.value = value | |
| } | |
| fmap<U>(f: (a: T) => U): Functor<U> { | |
| return new Container(f(this.value)) | |
| } | |
| } | |
| console.log( | |
| 'map integer container to string container:', | |
| new Container(5).fmap((a) => String(a)) | |
| ) // Container { value: "5" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment