This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
collection.some( )

collection.some( ) 


 

collection.some ( {startFrom ;} methodName {; param {; param2 ; ... ; paramN}} ) -> Function result 
Parameter Type   Description
startFrom  Longint in Index to start the test at
methodName  Text in Name of the method to call for the test
param  Expression in Parameter(s) to pass to methodName
Function result  Boolean in True if at least one element successfully passed the test

The collection.some( ) method returns true if at least one element in the collection successfully passed a test implemented in the provided methodName method.

By default, collection.some( ) tests the whole collection. Optionally, you can pass the index of element from which to start the test in startFrom.

  • 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.
  • 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 any case, at the point where collection.some( ) method encounters the first collection element returning true in $1.result, it stops calling methodName and returns true.

Example  

 C_COLLECTION($c)
 C_BOOLEAN($b)
 $c:=New collection
 $c.push(-5;-3;-1;-4;-6;-2)
 $b:=$c.some("NumberGreaterThan0") // returns false
 $c.push(1)
 $b:=$c.some("NumberGreaterThan0") // returns true
 
 $c:=New collection
 $c.push(1;-5;-3;-1;-4;-6;-2)
 $b:=$c.some("NumberGreaterThan0") //$b=true
 $b:=$c.some(1;"NumberGreaterThan0") //$b=false

With the following NumberGreaterThan0 method:

 $1.result:=$1.value>0



See also 

collection.every( )

 
PROPERTIES 

Product: 4D
Theme: Collections
Number: 705245

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v16 R6

 
ARTICLE USAGE

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)