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

Function fromIteratorArray

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

Source from the content-addressed store, hash-verified

825 * @since 4.0.0
826 */
827export const fromIteratorArray = <A, L>(
828 iterator: LazyArg<Iterator<A, L>>,
829 chunkSize = DefaultChunkSize
830): Channel<Arr.NonEmptyReadonlyArray<A>, never, L> => {
831 const size = Count.normalizeNonEmpty(chunkSize)
832 return fromPull(
833 Effect.sync(() => {
834 const iter = iterator()
835 let done = Option.none<L>()
836 return Effect.suspend(() => {
837 if (done._tag === "Some") return Cause.done(done.value)
838 const buffer: Array<A> = []
839 while (buffer.length < size) {
840 const state = iter.next()
841 if (state.done) {
842 if (buffer.length === 0) {
843 return Cause.done(state.value)
844 }
845 done = Option.some(state.value)
846 break
847 }
848 buffer.push(state.value)
849 }
850 return Effect.succeed(buffer as any as Arr.NonEmptyReadonlyArray<A>)
851 })
852 })
853 )
854}
855
856/**
857 * Creates a `Channel` that emits all elements from an iterable.

Callers 1

fromIterableArrayFunction · 0.85

Calls 7

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

Tested by

no test coverage detected