Usage of curry with promises
See original GitHub issueHi guys,
i am in a condition that i cannot figure out.
I want to curry a function that will return a promise. Let suppose there is something like:
const getUser = (token, id) => Promise.resolve({id: 1});
Now i think that can get a curried version of this function
const S = require('sanctuary');
const getUserAuthenticated = S.curry2(getUser)("Bearer test")
So now i get use the getUserAuthenticated
function and i can map it when i need to, but sadly i get a type error because the promise is not a correct type.
getUserAuthenticated(1).then(...)
TypeError: Unrecognized value
curry2 :: ((a, b) -> c) -> a -> b -> c
^
1
1) [object Promise] :: (no types)
The value at position 1 is not a member of any type in the environment.
The environment contains the following types:
- Function
- Arguments
- Array d
...
Why there is a limitation with curry
and types?
Thanks Walter
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Cleaning up Promise Chains with Partial and Curried Functions
We already have promise-returning helper methods to validate the user data, fetch the api secret, and create a new project.
Read more >JavaScript Async - Returning Promises - I Programmer
The final way of doing the job is to use bind to curry the delay function. The bind function returns another function with...
Read more >Typescript Promise curry function when using bind
The problem here is that the close function must return the value it was bound with, which, in this case is possibly of...
Read more >Callback currying, and futures (or a preface to Promises)
I have been diving into the different patterns that can be used to organize functional code. One pattern being ` curry ` ,...
Read more >Currying in JavaScript ES6 - Bene Studio
someAsyncOperation is a function that returns a promise that rejects if the path is not a string otherwise it resolves. On line 16...
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
Hi guys,
what’s the preferred way to do async operations when working with Sanctuary: using Promises and defining a custom type as above, or using Fluture? Or something entirely different?
Here’s a working example to get you unstuck, @wdalmut:
Your answer was spot on, Gabe! I think providing a
Promise
type constructor is a good idea.