Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



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

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

ApplyToList ( function ; listOfValues ; separator )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 3.7  (50 votes)
  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.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

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(
add_30 = "GetAsDate([n])+30";
ApplyToList( add_30; "Date(1;1;2000)¶Date(1;15;2000)"; ¶)
)
// --> "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.

LAST MODIFIED: 13-AUG-2008 by Debi Fuchs of Aptworks Consulting

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

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 6 + 7 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)
2. MonthYearList ( startmonth ; startyear ; numbermonth ; short )
  (Mon, Oct 16, 3:38am)
3. ErrorDescription ( errorNumber )
  (Wed, Sep 27, 2:51am)
4. decodeEntities (text)
  (Wed, Sep 27, 1:22am)
5. HexidecimalToNumber ( HexidecimalValue ; counter )
  (Mon, Sep 25, 12:39pm)
6. FixedFieldConverter ( Fieldname ; f1 ; f2 ; f3 ; f4 ; f5 ; f6 ; f7 ; f8 ; f9 ; f10 ; f11 ; f12 ; f13 ; f14 ; f15 ; f16 ; f17 ; f18 ; f1
  (Fri, Sep 15, 12:34pm)
7. ShannonEntropy ( text )
  (Thu, Sep 07, 5:59am)
8. LetterCount ( text ; summary )
  (Thu, Sep 07, 5:53am)

RSS Feed of Custom Functions