Created
January 7, 2017 00:10
-
-
Save gabesullice/9fb25ed423b34afc925cbb3ccc59d7f8 to your computer and use it in GitHub Desktop.
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
| const shapeFactory = { | |
| make: function () { | |
| console.log(arguments) | |
| } | |
| } | |
| class Monad { | |
| constructor ({type = undefined, scale = undefined} = {}) { | |
| this.type = type | |
| this.scale = scale | |
| } | |
| flatMap(fn) { | |
| return (this.scale !== undefined) ? fn(this.type, this.scale) : fn(this.type) | |
| } | |
| } | |
| const sqDef1 = new Monad({type: "square"}) | |
| const sqDef3 = new Monad({type: "square", scale: 3}) | |
| const definitions = [sqDef1, sqDef3]; | |
| const shapes = definitions.map(definition => { | |
| return definition.flatMap(shapeFactory.make) | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with: