Closed wdalmut closed 6 years ago
I think this may be an issue w/ there being no Promise
type defined in sanctuary-def
.
This issue could be resolved by adding your own type definition @wdalmut. Though a built-in type such as Promise
should probably have a definition (even though it's use may be discouraged).
You could also try using https://github.com/fluture-js/Fluture instead of promises.
@davidchambers please correct me if I've gotten anything wrong.
Here's a working example to get you unstuck, @wdalmut:
'use strict';
const {create, env} = require ('sanctuary');
const $ = require ('sanctuary-def');
// PromiseType :: Type -> Type -> Type
const PromiseType = $.BinaryType
('my-package/Promise')
('https://example.com/my-package#Promise')
(x => Object.prototype.toString.call (x) === '[object Promise]')
(p => [])
(p => []);
const S = create ({
checkTypes: true,
env: env.concat ([PromiseType ($.Unknown) ($.Unknown)]),
});
console.log (S.I (Promise.resolve (42)));
@davidchambers please correct me if I've gotten anything wrong.
Your answer was spot on, Gabe! I think providing a Promise
type constructor is a good idea.
thanks guys :+1:
No problem, Walter. Let us know if you encounter other issues.
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?
I unreservedly recommend Fluture. :butterfly:
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:
Now i think that can get a curried version of this function
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.Why there is a limitation with
curry
and types?Thanks Walter