list_join
TABLE OF CONTENTS
Join lists of objects
Definition
array list_join(array[object] $leftArray, array[object] $rightArray, &leftEvaluateBy, &rightEvaluateBy)
Joins the objects of two arrays of objects. &leftEvaluateBy and &rightEvaluateBy are treated as object identifiers; the objects that have matching values of &leftEvaluateBy and &rightEvaluateBy will be joined into a single object with properties left and right, whose values are arrays of all the objects in $leftArray and $rightArray respectively, that have the same value of &leftEvaluateBy and &rightEvaluateBy. The objects also have a property __index, which is the position of the object in the resulting list.
Entries that do not have matching keys, either in $leftArray or $rightArray, are shown in the result with no matching counterpart.
Parameters
array[object] $leftArray
Left array to join.
array[object] $rightArray
Right array to join.
&leftEvaluateBy
Identifier key for the objects in the left array.
&rightEvaluateBy
Identifier key for the objects in the right array.
Returns
array
Array where the objects with matching &EvaluateBy values have been joined together.
Examples
{
"people": [
{ "name": "Messi", "teamId": 1 },
{ "name": "Iniesta", "teamId": 1 },
{ "name": "Ronaldo", "teamId": 2 },
{ "name": "Rooney", "teamId": 3 }
],
"teams": [
{ "name": "Barcelona", "id": 1 },
{ "name": "Real Madrid", "id": 2 },
{ "name": "Real", "id": 2 },
{ "name": "Liverpool", "id": 10 }
]
}{
list_join: list_join(people, teams, &teamId, &id)
}{
"list_join":
[
{
"left":[{"name": "Messi", "teamId": 1}, {"name": "Iniesta", "teamId": 1}],
"right":[{"name": "Barcelona", "id": 1}],
"__index": 0
},
{
"left":[{"name": "Ronaldo", "teamId": 2}],
"right":[{"name": "Real Madrid", "id": 2}, {"name": "Real", "id": 2}],
"__index": 1
},
{
"left":[{"name":"Rooney", "teamId": 3}],
"right":[],
"__index": 2
},
{
"left":[],"right":[{"name":"Liverpool","id": 10}],
"__index": 3
}
]
}Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article