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

Description

Checks if one of the elements in an array satisfy 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 one of the elements satisfy the query statement.
Failure: Returns false.

Remarks

The One function is useful for validating whether one element in an array meet 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", 25),
                new Person("Steve", 25)
                );
                
say $people->>One($p => $p->$Age == 25);
say $people->>One($p => $p->$Age == 17);

// PRINTS
// false
// 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