The collection.every( ) method returns true if all elements in the collection successfully passed a test implemented in the provided methodName method.
By default, collection.every( ) tests the whole collection. Optionally, you can pass in startFrom the index of the element from which to start the test.
- If startFrom >= the collection's length, false is returned, which means the collection is not tested.
- If startFrom < 0, it is considered as the offset from the end of the collection ( startFrom:=startFrom+length).
- If startFrom = 0, the whole collection is searched (default).
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). This method receives an Object parameter in $1 and must set $1.result to true for every element fulfilling the test.
methodName receives the following parameters:
- in $1.value: element value to be evaluated
- in $2: param
- in $N...: param2...paramN
methodName sets the following parameter(s):
- $1.result (boolean): true if the element value evaluation is successful, false otherwise.
- $1.stop (boolean, optional): true to stop the method callback. The returned value is the last calculated.
In all cases, at the point when the collection.every( ) function encounters the first collection element returning false in $1.result, it stops calling methodName and returns false.
C_COLLECTION($c)
$c:=New collection
$c.push(5;3;1;4;6;2)
$b:=$c.every("NumberGreaterThan0")
$c.push(-1)
$b:=$c.every("NumberGreaterThan0")
With the following NumberGreaterThan0 method:
$1.result:=$1.value>0
This example tests that all elements of a collection are of the real type:
With the following TypeLookUp method:
C_OBJECT($1)
C_LONGINT($2)
If(Value type($1.value)=$2)
$1.result:=True
End if