Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Move fantasy-land methods to the prototypes [PR-ready] #745

Open
cAttte opened this issue Feb 6, 2025 · 0 comments
Open

Move fantasy-land methods to the prototypes [PR-ready] #745

cAttte opened this issue Feb 6, 2025 · 0 comments

Comments

@cAttte
Copy link

cAttte commented Feb 6, 2025

currently, each class exposes its fantasy-land/ adapter methods by assigning to them in the constructor:

purify/src/Maybe.ts

Lines 434 to 441 in 9fffe0d

'fantasy-land/equals' = this.equals
'fantasy-land/map' = this.map
'fantasy-land/ap' = this.ap
'fantasy-land/alt' = this.alt
'fantasy-land/chain' = this.chain
'fantasy-land/reduce' = this.reduce
'fantasy-land/extend' = this.extend
'fantasy-land/filter' = this.filter

this isn't great because (a) it's a little memory-inefficient and (b) it's just ugly and/or out of place, for example, when enumerating an object's properties (serialization, debugging, etc.). a way to fix this is by assigning these methods in the prototype instead:

Nothing.prototype['fantasy-land/equals'] = Nothing.prototype.equals;
Nothing.prototype['fantasy-land/map'] = Nothing.prototype.map;
Nothing.prototype['fantasy-land/ap'] = Nothing.prototype.ap;
Nothing.prototype['fantasy-land/alt'] = Nothing.prototype.alt;
Nothing.prototype['fantasy-land/chain'] = Nothing.prototype.chain;
Nothing.prototype['fantasy-land/reduce'] = Nothing.prototype.reduce;
Nothing.prototype['fantasy-land/extend'] = Nothing.prototype.extend;
Nothing.prototype['fantasy-land/filter'] = Nothing.prototype.filter;

i'm down to make a PR, so just let me know

@cAttte cAttte changed the title Move fantasy-land methods to the prototypes Move fantasy-land methods to the prototypes [PR-ready] Feb 6, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant