Shopping Cart

Search:

Signup

Contact

FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

# FileMaker Pro Custom Functions

ApplyToList ( function ; listOfValues ; separator )

Rate this function:

Discuss this Custom Function

Debi Fuchs, Aptworks Consulting
http://www.aptworks.com

Speedily (using limited recursion and avoiding GetValue) apply an "inline" function across a list of up to one million items, handling them either as numbers/expression or as text.

Sample Input:
 ApplyToList( "[n]^2"; "3¶2¶7"; ¶ )
Sample Output:
 "9¶4¶49"

Then copy & paste into FileMaker Advanced's Edit Custom Function window.

## Description:

CUSTOM FUNCTION: ApplyToList ( function ; listOfValues ; separator )
© 2008 Debi Fuchs of Aptworks Consulting, debi@aptworks.com

Speedily (using limited recursion and avoiding GetValue) apply an "inline" function across a list of up to one million items, handling them either as numbers/expression or as text.

EXAMPLES:
ApplyToList( "[n]^2"; "3¶2¶7"; ¶ )
// --> "9¶4¶49"

ApplyToList( "Length([t])"; "Robin¶Pat¶Chris"; ¶)
// --> "5¶3¶5"

Let(
number_me = "[i]&\". \"&[t]";
ApplyToList( number_me; "Robin¶Pat¶Chris"; ¶)
)
// --> "1. Robin¶2. Pat¶3. Chris"

Let(
)
// --> "1/31/2000¶2/14/2000"

CREDITS: Thanks to Agnès Barouh for the idea of the "[n]" style function call syntax, to Ray Cologon for ideas about local variables within custom functions, and to Darren Terry for inspring this function.

USAGE: ApplyToList returns the results, delimited by "separator", of repeatedly evaluating the string "function" across the list "listOfValues", each time assigning to placeholders "[t]" or "[n]" one item from the list. Use "[t]" to treat items as text; Use "[n]" to evaluate them before application. For convenience in creating numbered lists, use placeholder "[i]" to represent the position of the item within the list, starting with an index of 1. IMPORTANT: Use "[n]" over "[t]" where possible, as this is faster, and do NOT use BOTH "[n]" and "[t]" placeholders (or BOTH "[t]" and "evaluate([t])" in one function), as this slows the calculation engine to a crawl.

EXAMPLES:

ApplyToList( "[t] & 1"; "a¶b¶¶c"; ¶)
// --> ("a" & 1) & ¶ & ("b" & 1) & ¶ & ("" & 1) & ¶ & ("c" & 1)
// --> "a1¶b1¶1¶d1"

ApplyToList( "Length([t])"; "Robin¶Pat"; ¶)
// --> (Length("Robin")) & ¶ & (Length("Pat"))
// --> "5¶3"

ApplyToList( "Length([n])"; "Robin¶Pat"; ¶)
// --> (Length(Robin)) & ¶ & (Length(Pat))
// --> "[ERROR]"

ApplyToList("[n] + [n]"; "01+2¶3+2"; ¶)
// --> (01+2 + 01+2) & ¶ & (3+2 + 3+2)
// --> "6¶10"

ApplyToList("[t] + [t]"; "01+2¶3+2"; ¶)
// --> ("01+2" + "01+2") & ¶ & ("3+2" + "3+2")
// --> (12 + 12) & ¶ & (32 + 32)
// --> "24¶64"

THIS IS VERY VERY VERY (!!!!!) SLOW... (see above)
ApplyToList("[t] + [n]"; "01+2¶3+2"; ¶)
// --> ("01+2" + 01+2) & ¶ & ("3+2" + 3+2)
// --> (12 + 01+2) & ¶ & (32 + 3+2)
// --> "15¶37"

THIS IS VERY VERY VERY (!!!!!) SLOW... (see above)
ApplyToList("[t] + evaluate([t])"; "01+2¶3+2"; ¶)
// --> ("01+2" + evaluate("01+2") & ¶ & ("3+2" + evalute("3+2"))
// --> ("01+2" + 3) & ¶ & ("3+2" + 5)
// --> (12 + 3) & ¶ & (32 + 5)
// --> "15¶37"

IMPLEMENTATION: ApplyToList creates long strings of Let statements and then evaluates them. It does not recurse at all unless it is called on a list larger than 1000 items, and then it does so in binary fashion (calling itself twice not once). Thus, the CF stack grows logarithmically, reaching (for example) a depth of only 10 CF stack frames and 1000 CF calls when called on a list of one million items. This leaves room to use other custom functions (including ApplyToList) within the "function" argument of ApplyToList. ApplyToList is maximized for speed. Suggestions for further optimization welcome!

NOTE: See "ApplyToRange" to apply a function to a range of numbers. See "Apply" to apply a function to a single value.

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

## Discuss:

Like CustomList, I find in brief tests that this function does not work on FileMaker GO.

Bruce Robertson, Redmond
August 21, 2010 2:52pm