> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# scan

Like `reduce` but returns an array of all intermediate accumulator values.

The result array starts with the initial value and ends with the final
accumulator, so its length is `array.length + 1`.

```typescript
scan([1, 2, 3, 4], (acc, n) => acc + n, 0)
// [0, 1, 3, 6, 10]
```

## Usage

### `scan<T, R>(array: readonly T[], fn: (accumulator: R, value: T, index: number) => R, initial: R)`

Like `reduce` but returns an array of all intermediate accumulator values.

The result array starts with the initial value and ends with the final
accumulator, so its length is `array.length + 1`.

```typescript
import { scan } from 'massaman'
// or:  import { scan } from 'massaman/array'

scan([1, 2, 3, 4], (acc, n) => acc + n, 0)
// [0, 1, 3, 6, 10]
```

#### Parameters


arrayreadonly T[]required

the source array.


fn(accumulator: R, value: T, index: number) => Rrequired

the function to apply.


initialRrequired

the initial accumulator value.

#### Returns

an array containing the initial value followed by every intermediate accumulator.

```typescript
R[]
```
