| 3635 | * @since 2.0.0 |
| 3636 | */ |
| 3637 | export 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`. |