KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method Filter Collection for Desired Type
PRODUCT: 4D | VERSION: 19 R6 | PLATFORM: Mac & Win
Published On: December 5, 2022

Utility method Collection_type($1; $2) accepts two parameters:
$1 - Collection
$2 - Integer that represents desired type
A collection is returned based on the desired type parameter and stored in the result local variables displayed below

Collection_type($1;$2)

#DECLARE($col : Collection; $type : Integer)->$result : Collection
If (Count parameters=2)
   $f:=Formula(OB Get type($1; "value")=$2)
   $result:=$col.filter($f; $type)
End If

Example:
$c:=New collection(1;2;3;4;5)
$test_col:=New collection(9;8;7;6;5)
$c.push(New object("name"; “name1”; “number”; 12345))
$c.push(New object("name"; “name2”; “number”; 67890))
$c.push("text")
$c.push($test_col)
$c.push(False)

$result1:=Collection_type($c;Is object) //[{name:name1,number:12345},{name:name2,number:67890}]
$result2:=Collection_type($c; Is real) // [1,2,3,4,5]
$result3:=Collection_type($c; Is boolean) // [false]
$result4:=Collection_type($c; Is collection) // [[9,8,7,6,5]]
$result5:=Collection_type($c; Is text) // ["text"]