The collection.filter( ) method returns a new collection containing all elements of the original collection for which methodName method result is true. This method returns a shallow copy, which means that objects or collections in both collections share the same reference. If the original collection is a shared collection, the returned collection is also a shared collection.
Note: This method does not modify the original collection.
In methodName, pass the name of the method to use to evaluate collection elements, along with its parameter(s) in param (optional). methodName can perform any test, with or without the parameter(s), and must return true in $1.result for each element fulfilling the condition and thus, to push to the new collection.
methodName receives the following parameters:
- in $1.value: element value to be filtered
- in $2: param
- in $N...: param2...paramN
methodName sets the following parameter(s):
- $1.result (boolean): true if the element value matches the filter condition and must be kept.
- $1.stop (boolean, optional): true to stop the method callback. The returned value is the last calculated.
You want to get the collection of text elements whose length is smaller than 6:
The code for LengthLessThan method is:
C_OBJECT($1)
C_LONGINT($2)
If(Value type($1.value)=Is text)
$1.result:=(Length($1.value))<$2
End if
You want to filter elements according to their value type:
The code for TypeLookUp is:
C_OBJECT($1)
C_LONGINT($2)
If(OB Get type($1;"value")=$2)
$1.result:=True
End if