Skip to content

Instantly share code, notes, and snippets.

@ryyppy
Last active January 25, 2021 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryyppy/b6f16781dfe4f2611733e542a6c5ddc4 to your computer and use it in GitHub Desktop.
Save ryyppy/b6f16781dfe4f2611733e542a6c5ddc4 to your computer and use it in GitHub Desktop.
Prometo Misc (compiled with bs-platform@8.4.2)
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
var Curry = require("bs-platform/lib/js/curry.js");
var Caml_exceptions = require("bs-platform/lib/js/caml_exceptions.js");
var Prometo_cancelled = Caml_exceptions.create("Yawaramin__Prometo.Prometo_cancelled");
var cancelledSymbol = Symbol();
function make(a) {
return Promise.resolve({
TAG: /* Ok */0,
_0: a
});
}
function make$1(e) {
return Promise.resolve({
TAG: /* Error */1,
_0: e
});
}
function flatMap(f, t) {
return t.then(function (result) {
var match = t[cancelledSymbol];
if (match !== undefined && match) {
return Promise.resolve({
TAG: /* Error */1,
_0: "Prometo_cancelled"
});
}
if (result.TAG === /* Ok */0) {
return t;
}
var e = result._0;
if (e === "Prometo_cancelled") {
return t;
} else {
return Curry._1(f, e).catch(function (e) {
return Promise.resolve({
TAG: /* Error */1,
_0: {
NAME: "Prometo_error",
VAL: e
}
});
});
}
});
}
function map(f, t) {
return flatMap((function (e) {
var e$1 = Curry._1(f, e);
return Promise.resolve({
TAG: /* Error */1,
_0: e$1
});
}), t);
}
function recover(f, t) {
return flatMap((function (e) {
var a = Curry._1(f, e);
return Promise.resolve({
TAG: /* Ok */0,
_0: a
});
}), t);
}
function forEach(f, t) {
recover(f, t);
}
function cancel(t) {
t[cancelledSymbol] = true;
}
function updateResult(result, elem) {
if (elem.TAG !== /* Ok */0) {
return elem;
}
if (result.TAG !== /* Ok */0) {
return result;
}
var elems = result._0;
elems.push(elem._0);
return {
TAG: /* Ok */0,
_0: elems
};
}
function fromArray(array) {
return Promise.all(array).then(function (results) {
return Promise.resolve(results.reduce(updateResult, {
TAG: /* Ok */0,
_0: []
}));
});
}
function fromPromise(promise) {
return promise.then(make).catch(function (e) {
return Promise.resolve({
TAG: /* Error */1,
_0: {
NAME: "Prometo_error",
VAL: e
}
});
});
}
function flatMap$1(f, t) {
return t.then(function (result) {
var match = t[cancelledSymbol];
if (match !== undefined && match) {
return Promise.resolve({
TAG: /* Error */1,
_0: "Prometo_cancelled"
});
}
if (result.TAG === /* Ok */0) {
return Curry._1(f, result._0).catch(function (e) {
return Promise.resolve({
TAG: /* Error */1,
_0: {
NAME: "Prometo_error",
VAL: e
}
});
});
} else {
return Promise.resolve({
TAG: /* Error */1,
_0: result._0
});
}
});
}
function handle(f, t) {
return t.then(function (result) {
var match = t[cancelledSymbol];
var exit = 0;
if (result.TAG === /* Ok */0) {
exit = 2;
} else {
if (result._0 === "Prometo_cancelled") {
return Promise.resolve({
TAG: /* Error */1,
_0: "Prometo_cancelled"
});
}
exit = 2;
}
if (exit === 2 && match !== undefined && match) {
return Promise.resolve({
TAG: /* Error */1,
_0: "Prometo_cancelled"
});
}
return Promise.resolve(Curry._1(f, result)).catch(function (e) {
return Promise.resolve({
TAG: /* Error */1,
_0: {
NAME: "Prometo_error",
VAL: e
}
});
});
});
}
function map$1(f) {
return function (param) {
return flatMap$1((function (a) {
var a$1 = Curry._1(f, a);
return Promise.resolve({
TAG: /* Ok */0,
_0: a$1
});
}), param);
};
}
function forEach$1(f, t) {
map$1(f)(t);
}
function thenPromise(f) {
return function (param) {
return flatMap$1((function (a) {
return fromPromise(Curry._1(f, a));
}), param);
};
}
function toPromise(t) {
return t.then(function (result) {
var match = t[cancelledSymbol];
if (match !== undefined && match) {
return Promise.reject({
RE_EXN_ID: Prometo_cancelled
});
}
if (result.TAG === /* Ok */0) {
return Promise.resolve(result._0);
}
var e = result._0;
if (typeof e === "string") {
if (e === "Prometo_cancelled") {
return Promise.reject({
RE_EXN_ID: Prometo_cancelled
});
} else {
return Promise.reject(e);
}
} else if (e.NAME === "Prometo_error") {
return Promise.reject(e.VAL);
} else {
return Promise.reject(e);
}
});
}
function $great$great$eq(t, f) {
return flatMap$1(f, t);
}
function $great$pipe$eq(t, f) {
return map$1(f)(t);
}
var Infix = {
$great$great$eq: $great$great$eq,
$great$pipe$eq: $great$pipe$eq
};
function zip2(t1, t2) {
return flatMap$1((function (a1) {
return map$1(function (a2) {
return [
a1,
a2
];
})(t2);
}), t1);
}
function zip3(t1, t2, t3) {
return flatMap$1((function (a1) {
return flatMap$1((function (a2) {
return map$1(function (a3) {
return [
a1,
a2,
a3
];
})(t3);
}), t2);
}), t1);
}
function zip4(t1, t2, t3, t4) {
return flatMap$1((function (a1) {
return flatMap$1((function (a2) {
return flatMap$1((function (a3) {
return map$1(function (a4) {
return [
a1,
a2,
a3,
a4
];
})(t4);
}), t3);
}), t2);
}), t1);
}
function zip5(t1, t2, t3, t4, t5) {
return flatMap$1((function (a1) {
return flatMap$1((function (a2) {
return flatMap$1((function (a3) {
return flatMap$1((function (a4) {
return map$1(function (a5) {
return [
a1,
a2,
a3,
a4,
a5
];
})(t5);
}), t4);
}), t3);
}), t2);
}), t1);
}
function zip6(t1, t2, t3, t4, t5, t6) {
return flatMap$1((function (a1) {
return flatMap$1((function (a2) {
return flatMap$1((function (a3) {
return flatMap$1((function (a4) {
return flatMap$1((function (a5) {
return map$1(function (a6) {
return [
a1,
a2,
a3,
a4,
a5,
a6
];
})(t6);
}), t5);
}), t4);
}), t3);
}), t2);
}), t1);
}
var $$Error = {
forEach: forEach,
flatMap: flatMap,
make: make$1,
map: map,
recover: recover
};
exports.cancel = cancel;
exports.fromArray = fromArray;
exports.fromPromise = fromPromise;
exports.make = make;
exports.flatMap = flatMap$1;
exports.forEach = forEach$1;
exports.handle = handle;
exports.map = map$1;
exports.thenPromise = thenPromise;
exports.toPromise = toPromise;
exports.zip2 = zip2;
exports.zip3 = zip3;
exports.zip4 = zip4;
exports.zip5 = zip5;
exports.zip6 = zip6;
exports.Infix = Infix;
exports.$$Error = $$Error;
/* cancelledSymbol Not a pure module */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment