curry modifies functions returned from constant
See original GitHub issueDescribe the bug When a constant function is used to return another function, the returned function is automatically curried. This results in the return value no longer matching what was given to constant.
Based on my rough digging, it appears related to the logic of how the curry function works, specifically lines 25-27 in src/core/curry.js. This checks if the value returned by applying the arguments is a function, if it is, it curries the function.
This causes
To Reproduce
import { constant } from 'crocks';
// This is not curried, and should be returned unmodified.
const identity = x => x;
const constantOfIdentity = constant(identity);
// Instead, we see that the returned version is now the definition of the curry function.
console.log(constantOfIdentity().toString());
// This returns false, these are no longer reference equivalent.
console.log(constantOfIdentity() === identity);
Expected behavior The original value given to constant should be returned unmodified.
Additional context This affects any autocurried crocks function that can wind up returning a function itself. I’ve seen the same behavior with ifElse and when.
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (2 by maintainers)
Top Results From Across the Web
Everything about Currying in JavaScript | by Chidume Nnamdi
It keeps returning a new function (that expects the current argument, like we said earlier) until all the arguments are exhausted. The arguments ......
Read more >Closures, Curried Functions, and Cool Abstractions in ...
In this article, we will talk about closures and curried functions and we'll play around with these concepts to build cool abstractions.
Read more >TypeScript and currying - gists · GitHub
Note that the curried function has any as its return type. This is to make the compiler relax, which would otherwise have to...
Read more >Javascript curry: context in returned function - Stack Overflow
In a curry function like this : var curry = function() { var slice = Array.prototype.slice ...
Read more >Javascript Currying - Variadic Currying - Refine Dev
We defined two versions of the curry() function. The first one maintains unarity of the accumulator function at every level of the recursive ......
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
@goulderb yeah, I was afraid you were going to say tcomb or something to do with specs/tests. It was because of tcomb, that we started adding things like
isSameType
and a lot of the type predicates. I would recommend doing what you have been for now. We have been thinking of ways we can answer this issue of equality vs equivalence and do not have an answer yet.But as soon as we do, we will be sure to broadcast it to the world.
Closing this for now as it seems resolved. Feel free to re-open if there is more to discuss