This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
collection.every( )
|
collection.every ( {startFrom ;} methodName {; param {; param2 ; ... ; paramN}} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
startFrom | Longint |
![]() |
Index to start the test at | |||||
methodName | Text |
![]() |
Name of the method to call for the test | |||||
param | Expression |
![]() |
Parameter(s) to pass to methodName | |||||
Function result | Boolean |
![]() |
True if all elements successfully passed the test | |||||
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.
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:
methodName sets the following parameter(s):
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") //returns true
$c.push(-1)
$b:=$c.every("NumberGreaterThan0") //returns false
With the following NumberGreaterThan0 method:
$1.result:=$1.value>0
This example tests that all elements of a collection are of the real type:
C_COLLECTION($c)
$c:=New collection
$c.push(5;3;1;4;6;2)
$b:=$c.every("TypeLookUp";Is real) //$b=true
$c:=$c.push(New object("name";"Cleveland";"zc";35049))
$c:=$c.push(New object("name";"Blountsville";"zc";35031))
$b:=$c.every("TypeLookUp";Is real) //$b=false
With the following TypeLookUp method:
C_OBJECT($1)
C_LONGINT($2)
If(Value type($1.value)=$2)
$1.result:=True
End if
Product: 4D
Theme: Collections
Number:
705246
Created: 4D v16 R6
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)