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

Function zipWithPreviousAndNext

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

Source from the content-addressed store, hash-verified

3709 * @since 2.0.0
3710 */
3711export const zipWithPreviousAndNext = <A, E, R>(
3712 self: Stream<A, E, R>
3713): Stream<[Option.Option<A>, A, Option.Option<A>], E, R> =>
3714 mapAccumArray(self, () => ({
3715 prev: Option.none<A>(),
3716 current: Option.none<A>()
3717 }), (acc, arr) => {
3718 let i = 0
3719 let current: A
3720 if (acc.current._tag === "None") {
3721 i = 1
3722 current = arr[0]
3723 acc.current = Option.some(current)
3724 } else {
3725 current = acc.current.value
3726 }
3727 const pairs = Arr.empty<[Option.Option<A>, A, Option.Option<A>]>()
3728 for (; i < arr.length; i++) {
3729 const element = arr[i]
3730 acc.current = Option.some(element) as Option.Some<A>
3731 pairs.push([acc.prev, current, acc.current])
3732 acc.prev = Option.some(current)
3733 current = element
3734 }
3735 return [acc, pairs]
3736 }, {
3737 onHalt(acc) {
3738 return acc.current._tag === "Some" ? [[acc.prev, acc.current.value, Option.none<A>()]] : []
3739 }
3740 })
3741
3742/**
3743 * Zips multiple streams so that when a value is emitted by any stream, it is

Callers

nothing calls this directly

Calls 2

someMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected