import * as tracing_1 from "../../../../Tracing"
import * as tracing_2 from "../../../../Tracing"
const fileName_1 =
  "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/unfoldM.ts"
import * as core from "../../../../Effect/core"
import * as O from "../../../../Option"
import { append_, empty } from "../core"

function loop(s, f, builder) {
  return core.chain_(
    f(s),
    (o) => {
      if (O.isSome(o)) {
        return loop(o.value.get(1), f, append_(builder, o.value.get(0)))
      } else {
        return core.succeed(builder, fileName_1 + ":17:26")
      }
    },
    fileName_1 + ":13:21"
  )
}
/**
 * Constructs a `Chunk` by repeatedly applying the effectual function `f` as
 * long as it returns `Some`.
 */

export function unfoldM_(s, f) {
  return loop(s, f, empty())
}
/**
 * Constructs a `Chunk` by repeatedly applying the effectual function `f` as
 * long as it returns `Some`.
 *
 * @dataFirst unfoldM_
 */

export function unfoldM(f) {
  return (s) => unfoldM_(s, f)
}
//# sourceMappingURL=unfoldM.js.map
