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

List.countBy

countBy($callbackFunction) -> map

Description

Apply $callbackFunction to every item in the list.

This callback function should return a string key specifying the count key.

Returns a map of count keys that point to the number of times they appear in the list.

$nums = [
    1, 2, 3, 4, 5, 6, 7, 99
]

$nums.countBy(fun ($n) {
    return $n % 2 == 0 ? 'even' : 'odd'
})

// {
//     even: 3
//     odd: 5
// }

See Also