Version: v0.8.1 - Beta.  We welcome contributors & feedback.

List.groupBy

groupBy($callbackFunction) -> map

Description

Apply $callbackFunction to every item in the list.

This callback function should return a string key specifying the group that the item belongs to.

Returns a map of lists.

$rows = [
    { id: 0, color: 'red' }
    { id: 1, color: 'green' }
    { id: 2, color: 'green' }
    { id: 3, color: 'blue' }
]

$rows.groupBy(x{ $a.color })
// {
//     red: [{ id: 0, color: 'red'}]
//     green: [
//         { id: 1, color: 'green'}
//         { id: 2, color: 'green'}
//     ]
//     blue: [{ id: 3, color: 'blue'}]
// }

See Also