"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/*
 * Masala Parser
 * https://github.com/masala/masala-parser
 *
 * Copyright (c) 2016-2025 Didier Plaindoux & Nicolas Zozol
 * Licensed under the LGPL2 license.
 */
var Try = /*#__PURE__*/function () {
  function Try(value, error) {
    _classCallCheck(this, Try);
    this.value = value;
    this.error = error;
  }
  return _createClass(Try, [{
    key: "isSuccess",
    value: function isSuccess() {
      return this.error === null;
    }
  }, {
    key: "isFailure",
    value: function isFailure() {
      return !this.isSuccess();
    }
  }, {
    key: "onSuccess",
    value: function onSuccess(bindCall) {
      if (this.isSuccess()) {
        bindCall(this.value);
      }
      return this;
    }
  }, {
    key: "onFailure",
    value: function onFailure(bindCall) {
      if (this.isFailure()) {
        bindCall(this.error);
      }
      return this;
    }
  }, {
    key: "map",
    value: function map(bindCall) {
      if (this.isSuccess()) {
        try {
          return success(bindCall(this.value));
        } catch (e) {
          return failure(e);
        }
      } else {
        return this;
      }
    }
  }, {
    key: "flatMap",
    value: function flatMap(bindCall) {
      if (this.isSuccess()) {
        try {
          return bindCall(this.value);
        } catch (e) {
          return failure(e);
        }
      } else {
        return this;
      }
    }
  }, {
    key: "success",
    value: function success() {
      return this.value;
    }
  }, {
    key: "failure",
    value: function failure() {
      return this.error;
    }
  }, {
    key: "recoverWith",
    value: function recoverWith(value) {
      if (this.isSuccess()) {
        return this.value;
      } else {
        return value;
      }
    }
  }, {
    key: "lazyRecoverWith",
    value: function lazyRecoverWith(value) {
      if (this.isSuccess()) {
        return this.value;
      } else {
        return value(this.error);
      }
    }
  }, {
    key: "filter",
    value: function filter(f) {
      if (this.isSuccess()) {
        if (f(this.value)) {
          return this;
        } else {
          return failure(new Error('invalid filter'));
        }
      }
      return this;
    }
  }]);
}();
function success(value) {
  return new Try(value, null);
}
function failure(error) {
  return new Try(null, error);
}
var _default = exports["default"] = {
  success: success,
  failure: failure
};
//# sourceMappingURL=try.js.map