"Sputnik" help  
Sputnik Help
Where(<array>, <queryStm>)

Description

Filters elements in an array based on a specified query statement, similar to the functionality expected from a "Where" clause in LINQ.

Parameters

<array> The array to apply the filter.
<queryStm> The query statement to evaluate for each array element.

Return Value

Success: Returns a new array containing the elements that satisfy the query statement.
Failure: Returns an empty array if the input array is empty or if no elements meet the specified criteria.

Remarks

The Where function is designed to filter elements in an array based on a specified query statement.

Make sure to read about the ->> and the =>> operators which are very often used in Linq statements.

Related

Example

Example of usage:

Class Person
{
    my $Name;
    my $Age;
    Function __Construct($Name, $Age)
    {
        @this->$Name = $Name;
        @this->$Age = $Age;
    }
}
my $people = array(
                new Person("Eddy", 25),
                new Person("Tom", 23),
                new Person("James", 17),
                new Person("Charles", 19),
                new Person("Mike", 27),
                new Person("Steve", 25),
                new Person("Steve", 35),
                new Person("James", 42),
                );
                
printr $people->>Where($p => $p->$Age > 20);
printr $people->>Where($p => $p->$Age > 20 && $p->$Name == "Steve");

// PRINTS
// Array
// (
//     [0] => person Class
//         (
//             [name] => Eddy
//             [age] => 25
//         )
//     [1] => person Class
//         (
//             [name] => Tom
//             [age] => 23
//         )
//     [2] => person Class
//         (
//             [name] => Mike
//             [age] => 27
//         )
//     [3] => person Class
//         (
//             [name] => Steve
//             [age] => 25
//         )
//     [4] => person Class
//         (
//             [name] => Steve
//             [age] => 35
//         )
//     [5] => person Class
//         (
//             [name] => James
//             [age] => 42
//         )
// )
// Array
// (
//     [0] => person Class
//         (
//             [name] => Steve
//             [age] => 25
//         )
//     [1] => person Class
//         (
//             [name] => Steve
//             [age] => 35
//         )
// )

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org