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

# partition

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

## partition<T>(array: Array<T>, condition: (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 version 2.2.0._

### 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]
}
```

## partition(array: Null, condition: (item: Nothing) -> Any): Null

Helper function that enables `partition` to work with a `null` value.

_Introduced in DataWeave version 2.4.0._
