list.filter ( )

Function stats

Average user rating
29
86
9999
Support
FileMaker 7.0 +
Date posted
27 November 2008
Last updated
01 February 2009
Version
Recursive function
Yes

Author Info
 Genx

18 functions

Average Rating 4.1

author_avatar



 

Function overview

Prototype

list.filter  ( listValues;   test;   dataType )


Parameters

listValues  A list of values to be processed


test  A test to be evaluated. All strings should be quoted


dataType  Your value data type (one of number, text or date)


Description

Tags:  Recursive   List   Filter  

Iterates over each value in the input list passing them to the test to be evaluated - the value is available as the keyword "value". If the evaluated test returns true, the current value from is returned to the result list.

Examples

Sample input

list.filter( "Bob¶Jane¶Martha¶Brian¶Jose" ; "Left( value ; 1 ) = \"B\" OR Left( value ; 1 ) = \"J\"" ; "text" )


Sample output

Bob¶Jane¶Brian¶Jose

 

Function code

Let([
    valCount = ValueCount(listValues);
    plainVal = LeftValues(listValues;1);
    plainVal = Left( plainVal ; Length(plainVal) - 1 );
    value =    If( not IsEmpty(plainVal) ;
            Case(
             dataType = "int" or dataType = "number" ; GetAsNumber(plainVal) ;
             dataType = "date" or dataType = "time" or dataType = "timestamp" ; GetAsTimestamp(plainVal);
             dataType = "string" or dataType = "text" or dataType = "" ; Quote(plainVal)
            )
        );
    curTest = Substitute( test ; "value" ; value );
    result =    If( IsEmpty(value) ; 0 ; Evaluate(curTest) )
];
    If( result ; plainVal & If( valCount > 0 ; ¶ ) )
    & If( valCount > 0 ; list.filter( MiddleValues( listValues ; 2 ; valCount - 1 ) ; test ; dataType ) )
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/86

    Prototype: list.filter( listValues; test; dataType )
    Function Author: Genx (http://www.fmfunctions.com/mid/29)
    Last updated: 01 February 2009
    Version: 1.4

*/
// ===================================