import {
concreteStream,
StreamInternal
} from "@effect/core/stream/Stream/operations/_internal/StreamInternal"
/**
* Creates a pipeline that drops elements while the specified predicate
* evaluates to `true`.
*
* @tsplus static effect/core/stream/Stream.Aspects dropWhile
* @tsplus pipeable effect/core/stream/Stream dropWhile
*/
export function dropWhile(f: Predicate) {
return (self: Stream): Stream => {
concreteStream(self)
return new StreamInternal(self.channel >> dropWhileInternal(f))
}
}
function dropWhileInternal(
f: Predicate
): Channel, unknown, E, Chunk, unknown> {
return Channel.readWith(
(chunk: Chunk) => {
const out = chunk.dropWhile(f)
return out.isEmpty
? dropWhileInternal(f)
: Channel.write(out).flatMap(() => Channel.identity, unknown>())
},
(err) => Channel.fail(err),
(out) => Channel.succeed(out)
)
}