Skip to content

Instantly share code, notes, and snippets.

@gabesullice
Created January 7, 2017 00:10
Show Gist options
  • Select an option

  • Save gabesullice/9fb25ed423b34afc925cbb3ccc59d7f8 to your computer and use it in GitHub Desktop.

Select an option

Save gabesullice/9fb25ed423b34afc925cbb3ccc59d7f8 to your computer and use it in GitHub Desktop.
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)
});
@gabesullice

Copy link
Copy Markdown
Author

Run with:

babel --presets ["latest"] <filename> | node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment