An example of a fold function
✓ Published0🌍 Public
CCliffordAnderson
Last edited May 20, 2016
Created on May 20, 2016
This example demonstrates how the XQuery `fold-left` function reverses the letters of each word in a sequence, then joins the results into a single phrase. The code defines a list of words, an initial empty phrase, and an anonymous function that reverses each word using `fn:string-to-codepoints` and `fn:reverse` before converting back with `fn:codepoints-to-string`. The `fold-left` call iterates over the words, applying the function to accumulate the final string. The source is a gist by CliffordAnderson, and the output would be "tset a si siht" if the words were processed, though the phrase starts empty.
AI-generated description