"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.
 */

/**
 * Need a reference object in memory for uniqueness. Symbols causes troubles.
 */
var empty = {
  __MASALA_EMPTY__: 'empty'
};

/**
 * Private class Option, accessible from someOrNone() or none()
 */
var Option = /*#__PURE__*/function () {
  function Option(value) {
    _classCallCheck(this, Option);
    this.value = value;
  }
  return _createClass(Option, [{
    key: "isPresent",
    value: function isPresent() {
      return this.value !== empty;
    }
  }, {
    key: "map",
    value: function map(bindCall) {
      if (this.isPresent()) {
        return someOrNone(bindCall(this.value));
      } else {
        return this;
      }
    }
  }, {
    key: "flatMap",
    value: function flatMap(bindCall) {
      if (this.isPresent()) {
        return bindCall(this.value);
      } else {
        return this;
      }
    }
  }, {
    key: "filter",
    value: function filter(f) {
      if (this.isPresent() && f(this.value)) {
        return this;
      }

      // equivalent of return none() without cyclic creation
      // eslint : no-use-before-define
      return new Option(empty);
    }
  }, {
    key: "get",
    value: function get() {
      return this.value;
    }
  }, {
    key: "orElse",
    value: function orElse(value) {
      if (this.isPresent()) {
        return this.value;
      } else {
        return value;
      }
    }
  }, {
    key: "orLazyElse",
    value: function orLazyElse(value) {
      if (this.isPresent()) {
        return this.value;
      } else {
        return value();
      }
    }
  }]);
}();
function someOrNone(value) {
  return new Option(value);
}
function none() {
  return new Option(empty);
}
var _default = exports["default"] = {
  some: someOrNone,
  none: none
};
//# sourceMappingURL=option.js.map