Hyperlinkv0.8.0-beta.28

Stream

Stream.groupedconsteffect/Stream.ts:8182
(n: number): <A, E, R>(
  self: Stream<A, E, R>
) => Stream<Arr.NonEmptyReadonlyArray<A>, E, R>
<A, E, R>(self: Stream<A, E, R>, n: number): Stream<
  Arr.NonEmptyReadonlyArray<A>,
  E,
  R
>

Partitions the stream into non-empty arrays of the specified size.

Details

The final array may be smaller if there are not enough elements to fill it.

Example (Grouping elements by size)

import { Console, Effect, Stream } from "effect"

const program = Effect.gen(function*() {
  const grouped = yield* Stream.range(1, 8).pipe(
    Stream.grouped(3),
    Stream.runCollect
  )
  yield* Console.log(grouped)
})

Effect.runPromise(program)
// Output: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]
grouping
Source effect/Stream.ts:81827 lines
export const grouped: {
  (n: number): <A, E, R>(self: Stream<A, E, R>) => Stream<Arr.NonEmptyReadonlyArray<A>, E, R>
  <A, E, R>(self: Stream<A, E, R>, n: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R>
} = dual(
  2,
  <A, E, R>(self: Stream<A, E, R>, n: number): Stream<Arr.NonEmptyReadonlyArray<A>, E, R> => chunks(rechunk(self, n))
)