hugo/content/en/functions/collections/Apply.md
Bjørn Erik Pedersen 9b0050e9aa Squashed 'docs/' content from commit 5c085a37b
git-subtree-dir: docs
git-subtree-split: 5c085a37b297bf12f59efeaae591418ec025c10d
2024-01-27 10:48:33 +01:00

841 B

title description categories keywords action aliases
collections.Apply Returns a new collection with each element transformed by the given function.
aliases related returnType signatures
apply
[]any
collections.Apply COLLECTION FUNCTION PARAM...
/functions/apply

The apply function takes three or more arguments, depending on the function being applied to the collection elements.

The first argument is the collection itself, the second argument is the function name, and the remaining arguments are passed to the function, with the string "." representing the collection element.

{{ $s := slice "hello" "world" }}

{{ $s = apply $s "strings.FirstUpper" "." }}
{{ $s }} → [Hello World]

{{ $s = apply $s "strings.Replace" "." "l" "_" }}
{{ $s }} →  [He__o Wor_d]