sanctuary-js / sanctuary

:see_no_evil: Refuge from unsafe JavaScript
https://sanctuary.js.org
MIT License
3.03k stars 94 forks source link

Usage of curry with promises #572

Closed wdalmut closed 6 years ago

wdalmut commented 6 years ago

Hi 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

wdalmut commented 6 years ago

Moved to https://github.com/sanctuary-js/sanctuary-def/issues/215