"use strict"
var __createBinding =
  (this && this.__createBinding) ||
  (Object.create
    ? function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        Object.defineProperty(o, k2, {
          enumerable: true,
          get: function () {
            return m[k]
          }
        })
      }
    : function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        o[k2] = m[k]
      })
var __setModuleDefault =
  (this && this.__setModuleDefault) ||
  (Object.create
    ? function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v })
      }
    : function (o, v) {
        o["default"] = v
      })
var __importStar =
  (this && this.__importStar) ||
  function (mod) {
    if (mod && mod.__esModule) return mod
    var result = {}
    if (mod != null)
      for (var k in mod)
        if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
          __createBinding(result, mod, k)
    __setModuleDefault(result, mod)
    return result
  }
Object.defineProperty(exports, "__esModule", { value: true })
exports.concat_ =
  exports.concat =
  exports.prepend_ =
  exports.prepend =
  exports.append_ =
  exports.append =
  exports.update_ =
  exports.update =
  exports.fromNative =
  exports.toNative =
  exports.get_ =
  exports.get =
  exports.tuple =
  exports.Tuple =
  exports.isTuple =
  exports.TupleSym =
    void 0
const tracing_1 = __importStar(require("../../../Tracing"))
const tracing_2 = __importStar(require("../../../Tracing"))
const fileName_1 = "(@effect-ts/system): _src/Collections/Immutable/Tuple/index.ts"
const Tp = __importStar(require("../../../Structural"))
exports.TupleSym = Symbol.for("@effect-ts/system/Collections/Immutable/Tuple")
function isTuple(self) {
  return typeof self === "object" && self != null && exports.TupleSym in self
}
exports.isTuple = isTuple
class Tuple {
  constructor(tuple) {
    this.tuple = tuple
  }
  [exports.TupleSym]() {
    return exports.TupleSym
  }
  [Symbol.iterator]() {
    return this.tuple[Symbol.iterator]()
  }
  get [Tp.hashSym]() {
    return Tp.hashArray(this.tuple)
  }
  [Tp.equalsSym](that) {
    if (isTuple(that)) {
      return (
        this.tuple.length === that.tuple.length &&
        this.tuple.every((v, i) => Tp.equals(v, that.tuple[i]))
      )
    }
    return false
  }
  get(i) {
    return this.tuple[i]
  }
}
exports.Tuple = Tuple
/**
 * Creates a new Tuple
 */
function tuple(...args) {
  return new Tuple(args)
}
exports.tuple = tuple
/**
 * Gets an element from the tuple
 *
 * @dataFirst get_
 */
function get(i) {
  return (self) => self.get(i)
}
exports.get = get
/**
 * Gets an element from the tuple
 */
function get_(self, i) {
  return self.get(i)
}
exports.get_ = get_
/**
 * Converts to native tuple type
 */
function toNative(self) {
  return self.tuple
}
exports.toNative = toNative
/**
 * Converts from native tuple type
 */
function fromNative(self) {
  return new Tuple(self)
}
exports.fromNative = fromNative
/**
 * Replaces the element in position I
 *
 * @dataFirst update_
 */
function update(i, f) {
  return (self) => update_(self, i, f)
}
exports.update = update
/**
 * Replaces the element in position I
 */
function update_(self, i, f) {
  const len = self.tuple.length
  const r = new Array(len)
  for (let k = 0; k < len; k++) {
    if (k === i) {
      r[k] = f(self.tuple[k])
    } else {
      r[k] = self.tuple[k]
    }
  }
  return new Tuple(r)
}
exports.update_ = update_
/**
 * Appends a value to a tuple
 *
 * @dataFirst append_
 */
function append(k) {
  return (self) => append_(self, k)
}
exports.append = append
/**
 * Appends a value to a tuple
 */
function append_(self, k) {
  return new Tuple([...self.tuple, k])
}
exports.append_ = append_
/**
 * Appends a value to a tuple
 *
 * @dataFirst prepend_
 */
function prepend(k) {
  return (self) => prepend_(self, k)
}
exports.prepend = prepend
/**
 * Prepends a value to a tuple
 */
function prepend_(self, k) {
  return new Tuple([k, ...self.tuple])
}
exports.prepend_ = prepend_
/**
 * Concat tuples
 *
 * @dataFirst concat_
 */
function concat(that) {
  return (self) => concat_(self, that)
}
exports.concat = concat
/**
 * Concat tuples
 */
function concat_(self, that) {
  return new Tuple([...self.tuple, ...that.tuple])
}
exports.concat_ = concat_
//# sourceMappingURL=index.js.map
