Hyperlinkv0.8.0-beta.28

Stream

Stream.dropconsteffect/Stream.ts:6689
(n: number): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R>
<A, E, R>(self: Stream<A, E, R>, n: number): Stream<A, E, R>

Drops the first n elements from this stream.

Example (Dropping values from the left)

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

const stream = Stream.make(1, 2, 3, 4, 5)
const result = Stream.drop(stream, 2)

const program = Effect.gen(function*() {
  const items = yield* Stream.runCollect(result)
  yield* Console.log(items)
})

Effect.runPromise(program)
// Output: [ 3, 4, 5 ]
filtering
Source effect/Stream.ts:668920 lines
export const drop: {
  (n: number): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R>
  <A, E, R>(self: Stream<A, E, R>, n: number): Stream<A, E, R>
} = dual(
  2,
  <A, E, R>(self: Stream<A, E, R>, n: number): Stream<A, E, R> =>
    transformPull(self, (pull, _scope) =>
      Effect.sync(() => {
        let dropped = 0
        const pump: Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E, void, R> = pull.pipe(
          Effect.flatMap((chunk) => {
            if (dropped >= n) return Effect.succeed(chunk)
            dropped += chunk.length
            if (dropped <= n) return pump
            return Effect.succeed(chunk.slice(n - dropped) as Arr.NonEmptyArray<A>)
          })
        )
        return pump
      }))
)
Referenced by 2 symbols