UNPKG

6.84 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7
8var R = _interopRequireWildcard(require("ramda"));
9
10var _pipe2 = _interopRequireDefault(require("./pipe"));
11
12var _either = require("./either");
13
14function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
16function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
17
18function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
19
20function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
22function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
23
24function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
25
26function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
27
28function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
29
30function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
31
32function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
33
34function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
35
36function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
37
38function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
39
40function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
41
42function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
43
44var Fromise =
45/*#__PURE__*/
46function (_Promise) {
47 _inherits(Fromise, _Promise);
48
49 function Fromise() {
50 _classCallCheck(this, Fromise);
51
52 return _possibleConstructorReturn(this, _getPrototypeOf(Fromise).apply(this, arguments));
53 }
54
55 _createClass(Fromise, [{
56 key: "pipe",
57 value: function pipe() {
58 for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
59 funcs[_key] = arguments[_key];
60 }
61
62 return this.then(function (arg0) {
63 return _pipe2["default"].apply(void 0, funcs)(arg0);
64 });
65 }
66 }, {
67 key: 'if',
68 value: function _if(f, if_true, if_false) {
69 return this.then(function (value0) {
70 return f(value0) ? if_true(value0) : if_false(value0);
71 });
72 }
73 }, {
74 key: "tap",
75 value: function tap() {
76 var f = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : console.log;
77 return this.then(function (value0) {
78 return R.tap(f(value0));
79 });
80 }
81 }, {
82 key: "either",
83 value: function either(f) {
84 return this.then(function (value) {
85 return _either.Either.of(f, value);
86 });
87 }
88 }, {
89 key: "map",
90 value: function map(f) {
91 return this.then(function (v0) {
92 return _either.Either.is(v0) ? v0.map(f) : _either.Either.of(f, v0);
93 });
94 }
95 }, {
96 key: "fold",
97 value: function fold(f, g) {
98 return this.then(function (v0) {
99 return _either.Either.is(v0) ? v0.fold(f, g) : v0;
100 });
101 }
102 }, {
103 key: "chain",
104 value: function chain(f) {
105 return this.then(function (v0) {
106 return _either.Either.is(v0) ? v0.chain(f) : f(v0);
107 });
108 }
109 }], [{
110 key: "resolve",
111 value: function resolve(arg0) {
112 return new Fromise(function (resolve) {
113 return resolve(arg0);
114 });
115 }
116 }, {
117 key: "reject",
118 value: function reject(arg0) {
119 return new Fromise(function (_, reject) {
120 return reject(arg0);
121 });
122 }
123 }, {
124 key: "isPromise",
125 value: function isPromise(v) {
126 return v instanceof Promise || v instanceof Fromise;
127 }
128 }]);
129
130 return Fromise;
131}(_wrapNativeSuper(Promise));
132
133var _default = Fromise;
134exports["default"] = _default;
\No newline at end of file