---
title: "init(upstream:initial:nextPartialResult:)"
framework: combine
role: symbol
role_heading: Initializer
path: "combine/publishers/reduce/init(upstream:initial:nextpartialresult:)"
---

# init(upstream:initial:nextPartialResult:)

Creates a publisher that applies a closure to all received elements and produces an accumulated value when the upstream publisher finishes.

## Declaration

```swift
init(upstream: Upstream, initial: Output, nextPartialResult: @escaping (Output, Upstream.Output) -> Output)
```

## Parameters

- `upstream`: The publisher from which this publisher receives elements.
- `initial`: The initial value provided on the first invocation of the closure.
- `nextPartialResult`: A closure that takes the previously-accumulated value and the next element from the upstream publisher to produce a new value.
