"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.reduceRight = exports.reduceRight_ = void 0
const tracing_1 = __importStar(require("../../../../Tracing"))
const tracing_2 = __importStar(require("../../../../Tracing"))
const fileName_1 =
  "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/reduceRight.ts"
const definition_1 = require("../definition")
/**
 * Folds over the elements in this chunk from the right.
 */
function reduceRight_(self, s, f) {
  switch (self._typeId) {
    case definition_1.SingletonTypeId: {
      return f(self.a, s)
    }
    case definition_1.ArrTypeId: {
      const arr = self.arrayLike()
      const len = arr.length
      let s1 = s
      let i = len - 1
      while (i >= 0) {
        s1 = f(arr[i], s1)
        i--
      }
      return s1
    }
    default: {
      const iterator = self.reverseArrayLikeIterator()
      let next
      let s1 = s
      while ((next = iterator.next()) && !next.done) {
        const array = next.value
        const len = array.length
        let i = len - 1
        while (i >= 0) {
          const a = array[i]
          s1 = f(a, s1)
          i--
        }
      }
      return s1
    }
  }
}
exports.reduceRight_ = reduceRight_
/**
 * Folds over the elements in this chunk from the right.
 *
 * @dataFirst reduceRight_
 */
function reduceRight(s, f) {
  return (self) => reduceRight_(self, s, f)
}
exports.reduceRight = reduceRight
//# sourceMappingURL=reduceRight.js.map
