// tracing: off
import * as A from "../../Collections/Immutable/Chunk"
import * as Tp from "../../Collections/Immutable/Tuple"
import { pipe } from "../../Function"
import * as T from "../_internal/effect"
import * as Ref from "../_internal/ref"
import * as Pull from "../Pull"
import { Stream } from "./definitions"
/**
 * Creates a stream from an array of values
 */

export function fromChunk(c) {
  return new Stream(
    T.toManaged(
      T.map_(
        T.let_(
          T.bind_(T.do, "doneRef", () => Ref.makeRef(false)),
          "pull",
          ({ doneRef }) =>
            T.flatten(
              Ref.modify_(doneRef, (done) =>
                done || A.isEmpty(c)
                  ? Tp.tuple(Pull.end, true)
                  : Tp.tuple(T.succeed(c), true)
              )
            )
        ),
        ({ pull }) => pull
      )
    )
  )
}
//# sourceMappingURL=fromChunk.js.map
