--- type: "fhirpath-function" title: "FHIRPath Function: repeat" function: "repeat" category: "Filtering and projection" section: "5.2.5" source: "fhirpath/functions.json" --- # FHIRPath Function: repeat > This is a [scoped function](#scoped-functions): The `projection` argument is evaluated for each item (setting `$this` before each iteration); and the results are included in the output collection. The function is then re-evaluated on the output collection, repeating until no new items are added.
Note: As the function iterates on itself, the meaning of `$index` is undefined and not set here. A version of `select` that will repeat the `projection` and add items to the output collection only if they are not already in the output collection as determined by the [equals](#equals) (`=`) operator. This can be evaluated by adding all items in the input collection to an input queue, then for each item in the input queue evaluate the repeat expression. If the result of the repeat expression is not in the output collection, add it to both the output collection and also the input queue. Processing continues until the input queue is empty. This function can be used to traverse a tree and selecting only specific children: ``` fhirpath ValueSet.expansion.repeat(contains) ``` Will repeat finding children called `contains`, until no new items are found. ``` fhirpath Questionnaire.repeat(item) ``` Will repeat finding children called `item`, until no new items are found. Note that this is slightly different from: ``` fhirpath Questionnaire.descendants().select(item) ``` which would find *any* descendants called `item`, not just the ones nested inside other `item` elements. The order of items returned by the `repeat()` function is undefined. ## Summary - **Category**: Filtering and projection - **Section**: `5.2.5` - **Return Type**: `collection` - **Empty Input Result**: `empty` - **Errors on Multiple Input**: `false` ## Description A version of `select` that will repeat the `projection` and add items to the output collection only if they are not already in the output collection as determined by the equals (`=`) operator. ## Arguments - `projection`: `expression` - Expression to repeatedly project elements ## Type Mapping - `Any-Any` ## Example ```fhirpath Questionnaire.repeat(item) ```