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

Function zipWithNext

packages/effect/src/Stream.ts:3637–3655  ·  view source on GitHub ↗
(self: Stream<A, E, R>)

Source from the content-addressed store, hash-verified

3635 * @since 2.0.0
3636 */
3637export const zipWithNext = <A, E, R>(self: Stream<A, E, R>): Stream<[A, Option.Option<A>], E, R> =>
3638 mapAccumArray(self, Option.none<A>, (acc, arr) => {
3639 let i = 0
3640 if (acc._tag === "None") {
3641 i = 1
3642 acc = Option.some(arr[0]) as Option.Some<A>
3643 }
3644 const pairs = Arr.empty<[A, Option.Option<A>]>()
3645 for (; i < arr.length; i++) {
3646 const value = acc.value
3647 acc = Option.some(arr[i]) as Option.Some<A>
3648 pairs.push([value, acc])
3649 }
3650 return [acc, pairs]
3651 }, {
3652 onHalt(state) {
3653 return state._tag === "Some" ? [[state.value, Option.none<A>()]] : []
3654 }
3655 })
3656
3657/**
3658 * Zips each element with its previous element, starting with `None`.

Callers

nothing calls this directly

Calls 2

someMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected