// ets_tracing: off
import * as core from "../../../../Effect/core.js"
import type { Effect } from "../../../../Effect/effect.js"
import type * as Chunk from "../core.js"
import { concrete, SingletonTypeId } from "../definition.js"
import { reduceRight_ } from "./reduceRight.js"
/**
* Folds over the elements in this chunk from the right.
*/
export function reduceRightEffect_(
self: Chunk.Chunk,
s: S,
f: (a: A, s: S) => Effect
): Effect {
concrete(self)
if (self._typeId === SingletonTypeId) {
return f(self.a, s)
}
return reduceRight_(self, core.succeed(s) as Effect, (a, s) =>
core.chain_(s, (s1) => f(a, s1))
)
}
/**
* Folds over the elements in this chunk from the right.
*
* @ets_data_first reduceRightEffect_
*/
export function reduceRightEffect(
s: S,
f: (a: A, s: S) => Effect
): (self: Chunk.Chunk) => Effect {
return (self) => reduceRightEffect_(self, s, f)
}