---
schema_version: "1"
id: 75d8440ec21b5dba0d1942a045c112864525cacc90a09e880b88d0edaba93620
title: partition
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dw-arrays-functions-partition.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dw-arrays-functions-partition
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 743b1ccfaf74f320f0bbc2b9d825f47b8ad340fb17fdce59c512fd0f96f340aa
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# partition

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## partition(Array<T>, (item: T) -> Boolean): { success: Array<T>, failure: Array<T> }

Separates the array into the elements that satisfy the condition from those that do not.

_Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>array</code></p></td><td><p>The array of elements to split.</p></td></tr><tr><td><p><code>condition</code></p></td><td><p>The condition (or expression) used to match an element in the array.</p></td></tr></tbody></table>

### Example

This example partitions numbers found within an input array. The even numbers match the criteria set
by the lambda expression `(item) → isEven(item)`. The odd do not. The function generates the
`"success"` and `"failure"` keys within the output object.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,1,2,3,4,5]
---
arr partition (item) -> isEven(item)
```

#### Output

```json
{
  "success": [0, 2, 4],
  "failure": [1, 3, 5]
}
```
