MCPcopy Create free account
hub / github.com/Effect-TS/effect / fromIteratorArray

Function fromIteratorArray

packages/effect/src/Channel.ts:754–779  ·  view source on GitHub ↗
(
  iterator: LazyArg<Iterator<A, L>>,
  chunkSize = DefaultChunkSize
)

Source from the content-addressed store, hash-verified

752 * @since 4.0.0
753 */
754export const fromIteratorArray = <A, L>(
755 iterator: LazyArg<Iterator<A, L>>,
756 chunkSize = DefaultChunkSize
757): Channel<Arr.NonEmptyReadonlyArray<A>, never, L> =>
758 fromPull(
759 Effect.sync(() => {
760 const iter = iterator()
761 let done = Option.none<L>()
762 return Effect.suspend(() => {
763 if (done._tag === "Some") return Cause.done(done.value)
764 const buffer: Array<A> = []
765 while (buffer.length < chunkSize) {
766 const state = iter.next()
767 if (state.done) {
768 if (buffer.length === 0) {
769 return Cause.done(state.value)
770 }
771 done = Option.some(state.value)
772 break
773 }
774 buffer.push(state.value)
775 }
776 return Effect.succeed(buffer as any as Arr.NonEmptyReadonlyArray<A>)
777 })
778 })
779 )
780
781/**
782 * Creates a `Channel` that emits all elements from an iterable.

Callers 1

fromIterableArrayFunction · 0.85

Calls 7

someMethod · 0.80
pushMethod · 0.80
fromPullFunction · 0.70
nextMethod · 0.65
syncMethod · 0.45
doneMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected