"Sputnik" help  
Sputnik Help
Any(<array>, [<queryStm>])

Description

Checks if any element in an array satisfies a given query statement.

Parameters

<array> The array to be checked.
[<queryStm>] Optional; The query statement to evaluate for each array element. If the queryStm is not provided then check will be on the array itself where elements checked using an IsTrue check.

Return Value

Success: Returns true if at least one element satisfies the query statement.
Failure: Returns false.

Remarks

The Any function is useful for determining whether there is at least one element in the array that meets a certain condition specified by the provided 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("Tom", 23),
                new Person("James", 17),
                new Person("Charles", 19),
                new Person("Mike", 27),
                new Person("Steve", 25)
                );
                
say $people->>Any($p => $p->$Name == "James");
say $people->>Any($p => $p->$Age == 25);

// PRINTS
// true
// true

Checking array elements:

my $array = [1, 5, 10];
my $a = 5;
my $b = 1;
my $c = 10;
my $d = 0;

if ($array->>Any($p => $p == $a))
    say "True (Any)";
else
    say "False (Any)";

if ($array->>All($p => $p >= $b))
    say "True (All)";
else
    say "False (All)";

if ($array->>One($p => $p == $c))
    say "True (One)";
else
    say "False (One)";

if ($array->>None($p => $p == $d))
    say "True (None)";
else
    say "False (None)";

// PRINTS
// True (Any)
// True (All)
// True (One)
// True (None)

A basic check only:

my $array = [1, 5, 10];
my $a = 5;
my $b = 1;
my $c = 10;
my $d = 0;

if (Any($array))
    say "True (Any)";
else
    say "False (Any)";

if (All($array))
    say "True (All)";
else
    say "False (All)";

if (One($array))
    say "True (One)";
else
    say "False (One)";

if (None($array))
    say "True (None)";
else
    say "False (None)";

// PRINTS
// True (Any)
// True (All)
// False (One)
// False (None)

This works because the queryStm is not needed if only one argument is used.


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