Pass prototype object to tagged and taggedSum
See original GitHub issueIt would be nice to simply pass in an object as the final parameter.
const Point3D = daggy.tagged('Point3D', ['x', 'y', 'z'], {
scale(n) {
return Point3D(this.x * n, this.y * n, this.z * n)
}
})
Point3D.toString() // 'Point3D'
const a = Point3D(1, 2, 3) // { x: 1, y: 2, z: 3 }
a.x == 1 && a.y == 2 && a.z == 3 // true
a.toString() // 'Point3D(1, 2, 3)'
Point3D.is(a) // true
const b = a.scale(2) // { x: 2, y: 4, z: 6 }
b.toString() // 'Point3D(2, 4, 6)'
const Option = daggy.taggedSum('Option', {
Some: ['x'],
None: [],
}, {
map(f) {
return this.cata({
Some: (x) => Option.Some(f(x)),
None: () => this,
})
}
})
const a = Option.Some(1) // { x: 1 }
a.toString() // 'Option.Some(1)'
Option.Some.is(a) // true
Option.is(a) // true
Option.None.is(Option.None) // true
Option.is(Option.None) // true
Option.None.toString() // 'Option.None'
Option.Some.toString() // 'Option.Some'
const b = a.map(x => x+1) // { x: 2 }
b.toString() // 'Option.Some(2)'
It would allow customizing the behavior of toString
.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Fantas, Eel, and Specification 1: Daggy - Tom Harding
A tiny little utility for creating constructors with named properties. daggy.taggedSum(typeName, constructors). Now for the interesting one.
Read more >How to use the daggy.taggedSum function in daggy - Snyk
To help you get started, we've selected a few daggy.taggedSum examples, based on popular ways it is used in public projects.
Read more >Passing a prototype to Object.Create() - Stack Overflow
I understand that whatever you pass into it returns a new object with that argument as the prototype. My teacher listed this as...
Read more >Extensible Effects in Node.js, Part 1 - HumbleSpark
A Monad is an object with a chain method and an of static method that ... of options that held on to values...
Read more >Daggy: Library for Creating Tagged Constructors - Morioh
TumblrRestClient is the object you'll make all of your calls to the Tumblr ... A note on tags: When passing tags, as params,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem it’s solving is simply reduced boilerplate. I think things could be disambiguated.
But the added complexity would probably outweigh the benefits.
closing this for now