digitake / bs-promise-monad Goto Github PK
View Code? Open in Web Editor NEWMonadic syntax to work with promise in ReasonML
License: MIT License
Monadic syntax to work with promise in ReasonML
License: MIT License
Can't seem to understand what this wants me to return;
type idTokenT = {
idToken,
} and idToken = {jwtToken: string};
let decodeJwt = json => Json.Decode.{jwtToken: json |> field("jwtToken",string)}
let decodeToken = json => Json.Decode.{
idToken: json |> field("idToken", decodeJwt),
};
type auth;
[@bs.module "@aws-amplify/auth/lib"] external auth: auth = "default";
[@bs.send] external getCurrentSession:(auth,unit)=> Js.Promise.t(Js.Json.t) = "currentSession";
let getJwtToken = () => {
open PromiseMonad;
getCurrentSession(auth,())
>>= (response => {
let jwtToken = decodeToken(response);
Js.log(jwtToken);
return(jwtToken);
})
>>| (err => {
let errMsg = err |> Js.Json.stringifyAny |> Js.Option.getWithDefault("");
Js.log2("Failure!!", err);
return(errMsg))
});
};
This is the compiler error:
This has type:
Js.Promise.t(Js.Promise.error) (defined as
Js.Promise.t(Js.Promise.error))
But somewhere wanted:
Js.Promise.t(idTokenT) (defined as Js.Promise.t(idTokenT))
The incompatible parts:
Js.Promise.error (defined as Js.Promise.error)
vs
idTokenT
Any guidance would be appreciated. Thank you, sir.
Hi! Digging this stuff, makes it so much cleaner. I've added the following to mine just now:
let (>>/) = (m: Js.Promise.t('a), f: Js.Promise.error => 'a) => Js.Promise.catch(e => return(f(e)), m);
I would have made a PR, but the console is spewing errors at me when I try to compile and I'm not that familiar with Reason just yet :P
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.