Add template function: shuffle (#37864)

* Add template function: shuffle

* Use 'reproducible' instead

* tiny tweak

---------

Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>
This commit is contained in:
Franck Nijhof 2025-03-08 07:12:10 +01:00 committed by GitHub
parent c231846cab
commit f872e128a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1185,6 +1185,28 @@ See: [Python regular expression operations](https://docs.python.org/3/library/re
- Filter `value | regex_findall(find='', ignorecase=False)` will find all regex matches of the find expression in `value` and return the array of matches. - Filter `value | regex_findall(find='', ignorecase=False)` will find all regex matches of the find expression in `value` and return the array of matches.
- Filter `value | regex_findall_index(find='', index=0, ignorecase=False)` will do the same as `regex_findall` and return the match at index. - Filter `value | regex_findall_index(find='', index=0, ignorecase=False)` will do the same as `regex_findall` and return the match at index.
### Shuffling
The template engine contains a filter and function to shuffle a list.
Shuffling can happen randomly or reproducibly using a seed. When using a seed
it will always return the same shuffled list for the same seed.
Some examples:
{% raw %}
- `{{ [1, 2, 3] | shuffle }}` - renders as `[3, 1, 2]` (_random_)
- `{{ shuffle([1, 2, 3]) }}` - renders as `[3, 1, 2]` (_random_)
- `{{ shuffle(1, 2, 3) }}` - renders as `[3, 1, 2]` (_random_)
- `{{ [1, 2, 3] | shuffle("random seed") }}` - renders as `[2, 3, 1] (_reproducible_)
- `{{ shuffle([1, 2, 3], seed="random seed") }}` - renders as `[2, 3, 1] (_reproducible_)
- `{{ shuffle([1, 2, 3], "random seed") }}`- renders as `[2, 3, 1] (_reproducible_)
- `{{ shuffle(1, 2, 3, seed="random seed") }}` - renders as `[2, 3, 1] (_reproducible_)
{% endraw %}
## Merge action responses ## Merge action responses
Using action responses we can collect information from various entities at the same time. Using action responses we can collect information from various entities at the same time.