---
title: reduceItems
description: Creates a reduce items transformation action.
source: /actions/reduceItems/reduceItems.ts
contributors:
  - fabian-hiller
---

import { ApiList, Property } from '~/components';
import { properties } from './properties';

# reduceItems

Creates a reduce items transformation action.

```ts
const Action = v.reduceItems<TInput, TOutput>(operation, initial);
```

## Generics

- `TInput` <Property {...properties.TInput} />
- `TOutput` <Property {...properties.TOutput} />

## Parameters

- `operation` <Property {...properties.operation} />
- `initial` <Property {...properties.initial} />

### Explanation

With `reduceItems` you can apply an `operation` to each item in an array to reduce it to a single value.

## Returns

- `Action` <Property {...properties.Action} />

## Examples

The following examples show how `reduceItems` can be used.

### Sum all numbers

Schema that sums all the numbers in an array.

```ts
const SumArraySchema = v.pipe(
  v.array(v.number()),
  v.reduceItems((sum, item) => sum + item, 0)
);
```

## Related

The following APIs can be combined with `reduceItems`.

### Schemas

<ApiList items={['any', 'array', 'custom', 'instance', 'tuple', 'unknown']} />

### Methods

<ApiList items={['pipe']} />

### Utils

<ApiList items={['isOfKind', 'isOfType']} />
