Skip to content

Instantly share code, notes, and snippets.

@chrisdone

chrisdone/ex.js Secret

Created November 2, 2020 09:56
Show Gist options
  • Save chrisdone/9f0e974c80736d7fae6ee711f78ee37e to your computer and use it in GitHub Desktop.
Save chrisdone/9f0e974c80736d7fae6ee711f78ee37e to your computer and use it in GitHub Desktop.
Example of PS output
var rpcCall = function (dictMonadAff) {
return function (dictGenericEncode) {
return function (dictGenericDecode) {
return function (dictGeneric) {
return function (dictGeneric1) {
return function (dictShow) {
return function (endpoint0) {
return function (input) {
var endpoint = "/api/rpc/" + endpoint0;
return Effect_Aff_Class.liftAff(dictMonadAff)((function () {
var v = Data_Argonaut_Parser.jsonParser(Foreign_Generic.genericEncodeJSON(dictGeneric)(dictGenericEncode)(Inflex_Json.opts)(input));
if (v instanceof Data_Either.Left) {
return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Effect_Class_Console.error(Effect_Aff.monadEffectAff)("Own JSON was invalid! " + v.value0))(function () {
return Control_Applicative.pure(Effect_Aff.applicativeAff)(new Data_Either.Left(v.value0));
});
};
if (v instanceof Data_Either.Right) {
return Control_Bind.bind(Effect_Aff.bindAff)(Effect_Aff_Class.liftAff(Effect_Aff_Class.monadAffAff)(Affjax.post(Affjax_ResponseFormat.json)(endpoint)(new Data_Maybe.Just(Affjax_RequestBody.json(v.value0)))))(function (result) {
if (result instanceof Data_Either.Left) {
return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Effect_Class_Console.error(Effect_Aff.monadEffectAff)("POST " + (endpoint + (" response failed to decode:" + Affjax.printError(result.value0)))))(function () {
return Control_Applicative.pure(Effect_Aff.applicativeAff)(new Data_Either.Left(Affjax.printError(result.value0)));
});
};
if (result instanceof Data_Either.Right) {
var v1 = Control_Monad_Except.runExcept(Foreign_Generic.genericDecodeJSON(dictGeneric1)(dictGenericDecode)(Inflex_Json.opts)(Data_Argonaut_Core.stringify(result.value0.body)));
if (v1 instanceof Data_Either.Right) {
return Control_Applicative.pure(Effect_Aff.applicativeAff)(new Data_Either.Right(v1.value0));
};
if (v1 instanceof Data_Either.Left) {
return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Effect_Class_Console.error(Effect_Aff.monadEffectAff)("Failed to decode:" + Data_Show.show(Data_List_Types.showNonEmptyList(Foreign.showForeignError))(v1.value0)))(function () {
return Control_Applicative.pure(Effect_Aff.applicativeAff)(new Data_Either.Left(Data_Show.show(Data_List_Types.showNonEmptyList(Foreign.showForeignError))(v1.value0)));
});
};
throw new Error("Failed pattern match at Inflex.Rpc (line 70, column 17 - line 76, column 41): " + [ v1.constructor.name ]);
};
throw new Error("Failed pattern match at Inflex.Rpc (line 62, column 13 - line 76, column 41): " + [ result.constructor.name ]);
});
};
throw new Error("Failed pattern match at Inflex.Rpc (line 51, column 9 - line 76, column 41): " + [ v.constructor.name ]);
})());
};
};
};
};
};
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment