Another great use of evaluateItem
(from my experience) is that it helps evaluate strings containing arbitrary code into proper output behind-the-scenes before modifying them with other properties or functions. For example, running ["[conjugate(verb).gerund] [adjective.pluralForm]"]
outputs as expected, a phrase consisting of a gerund verb and a pluralized adjective word. The Perchance engine evaluates the unevaluated string right away after any modifications (for example, through titleCase
) were made. And so, running ["[conjugate(verb).gerund] [adjective.pluralForm]".titleCase]
will result in a mixed undefined
or (syntax error)
output (e.g. intending undefined
) because it converted the unevaluated string (which is the Perchance code) into title case before it was evaluated, and results in an unwanted output.
But prepending evaluateItem
right before any modification would do the opposite - it evaluates the string before any modifications was made. Using that, running ["[conjugate(verb).gerund] [adjective.pluralForm]".evaluateItem.titleCase]
would output a properly title cased phrase in that same format because the Perchance code inside the string is evaluated before the final output was eventually made title cased.