# listReduceRight

This function iterates over every element of the list and calls the closure to work on that element. This function will reduce the list to a single value, from the right to the left, and will return the value.
NOTE: Use caution if using the member function. `list.reduceRight` and `list.listReduceRight` may behave differently.
NOTE:This function is not available in Lucee 5.x or lower. Potentially use `reverse()` instead.




### Syntax

```
listReduceRight(list, callback, initialValue[, delimiter][, includeEmptyFields]) returns any
```



#### Member Function Syntax

```
list.listReduceRight(callback, initialValue[, delimiter][, includeEmptyFields]) 
```




## Argument Reference

| Name | Type | Required | Default | Description | Values |
| --- | --- | --- | --- | --- | --- |
| list | string | Yes |  | The input list. |  |
| callback | any | Yes |  | Closure or a function reference that will be called for each iteration.<br>See callback arguments below. |  |
| initialValue | any | Yes |  | Initial value which will be used for the reduce operation. |  |
| delimiter | string | No | , | The list delimiter |  |
| includeEmptyFields | boolean | No | false | Include empty values? | true,false |



### callback Callback Arguments

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| result | any | Yes | The result of the reduce operation after the previous iteration. |
| item | any | Yes | The value for the current iteration's item. |
| index | numeric | No | The current index for the iteration. |
| list | string | No | A reference of the original list. |





## CFML Engine Support

The listReduceRight function is supported on the following CFML engines:

| Engine | Minimum Version | Notes |
| --- | --- | --- |
| ColdFusion | 2021 |  |
| BoxLang | 1.0.0 |  |




## Examples


### Simple listReduceRight Example

Demonstrate how the function works from right to left.

```
myList="a,b,c,d";
newList=listReduceRight(myList,function(prev,next,idx,arr){ return prev & next & idx },"");
writedump(newList);
```
Expected Result: d4c3b2a1


### listReduceRight as a Member Function

Demonstrate the member function.

```
myList="a,b,c,d";
newList=myList.listReduceRight(function(prev,next,idx,arr){ return prev & next & idx },"");
writedump(newList);
```
Expected Result: d4c3b2a1


### Empty Elements

Demonstrate the behavior when there is an empty element.

```
myList="a,,,,,b,,,c,,,d";
newList=myList.listReduceRight(function(prev,next,idx){ return prev & next & idx },"");
writedump(newList);
```
Expected Result: d4c3b2a1





## Related Tags and Functions

[ListReduce](https://cfdocs.org/ListReduce.md)
[StringMap](https://cfdocs.org/StringMap.md)
[StringFilter](https://cfdocs.org/StringFilter.md)
[reverse](https://cfdocs.org/reverse.md)




The human version of this document can be found here: [https://cfdocs.org/listreduceright](https://cfdocs.org/listreduceright) which is part of the cfdocs.org repository. Project created by [Pete Freitag](https://www.petefreitag.com) and sponsored by [Foundeo Inc.](https://foundeo.com/)
