Count macro

Learn how to count items in a collection.

This macro counts the elements in a collection.

The count refers to the total number of elements in a given collection, which is also known as its size.

Syntax

This macro has the following syntax:

count of /*<collection>*/
Try in Playground

You can also prefix the macro with a definite article for readability:

the count of /*<collection>*/
Try in Playground

Parameters

These are the supported parameters:

collection

A collection of elements you want to count.

Examples

Here is an example of how to count the number of items in a list:

count of [1, 2, 3] // 3
Try in Playground

You can also count map entries:

count of ["a": 1, "b": 2, "c": 3] // 3
Try in Playground