You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea is to materialise a generator in chunks. Here is a sketch of the proposed operation as a non-member method:
defchunked[R](input: Generator[R], size: Int):Generator[Iterable[R]] =newGenerator[Iterable[R]]:defgenerate(f: Iterable[R] =>Generator.Action):Generator.Action=valbuilder=Iterable.newBuilder[R]
varn=0varaction:Generator.Action=Generator.Continue
input.generate {
r =>if n < size thenif n ==0then builder.sizeHint(size)
builder.addOne(r)
n +=1
action
else
action = f(builder.result)
builder.clear
n =0
action
}
if n >0&& action ==Generator.Continuethen f(builder.result)
else action
In comparison, toBuffer, toList etc materialise the whole of the stream. The standard collection operations Iterator.grouped and Iterable.grouped are similar. Chunking is a fairly common streaming operation so I think the need for this would arise often enough. The choice of type Iterable for the chunks might or might not be the best.
The text was updated successfully, but these errors were encountered:
The idea is to materialise a generator in chunks. Here is a sketch of the proposed operation as a non-member method:
In comparison,
toBuffer
,toList
etc materialise the whole of the stream. The standard collection operationsIterator.grouped
andIterable.grouped
are similar. Chunking is a fairly common streaming operation so I think the need for this would arise often enough. The choice of typeIterable
for the chunks might or might not be the best.The text was updated successfully, but these errors were encountered: