"Sputnik" help  
Sputnik Help
Distinct(<array>, [<cmpType>], [<arrays>...])

Description

Creates a new array containing all distinct elements of one or more arrays. The distinct comparison is based on the specified comparison type (<cmpType>), which defaults to @CompareEquateStrict. The second parameter (<cmpType>) can be omitted, and arrays can be used in its place. If the comparison type is given as NULL, it will be ignored, and the default comparison type will be used.

Parameters

<array> The primary array to extract distinct elements from.
[<cmpType>] Optional. The comparison type used for distinct checking. Defaults to @CompareEquateStrict.
[<arrays>...] Optional. Additional arrays to include in the distinct check.

Return Value

Success: Returns a new array containing all distinct elements from the input arrays.
Failure: Returns an empty array.

Remarks

The Distinct function extracts distinct elements from one or more arrays based on the specified comparison type (<cmpType>). If no comparison type is provided, it defaults to strict equality (@CompareEquateStrict). If the comparison type is NULL or not numeric, it is ignored, and the default comparison type is used.

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

Related

Example

Example of usage:

my $a = ["Cat", "Fox", "Dog"];
my $b = ["Fox", "Cat", "Horse"];
my $c = ["Fox", "Cat", "Zebra", "Horse"];
printr Distinct($a, $b, $c);
// Array
// (
//     [0] => Cat
//     [1] => Fox
//     [2] => Dog
//     [3] => Zebra
//     [4] => Horse
// )

Using the comparison type:

my $a = array("777", 777, 777);
my $b = array("cat", "cat", "dog");
say vardump($a->>Distinct(@CompareEquate, $b));
say vardump($a->>Distinct(@CompareEquateStrict, $b));

// PRINTS
// array(3) {
//   [0]=> string(3) "777"
//   [1]=> string(3) "cat"
//   [2]=> string(3) "dog"
// }
// 
// array(4) {
//   [0]=> string(3) "777"
//   [1]=> int64(777)
//   [2]=> string(3) "cat"
//   [3]=> string(3) "dog"
// }

 


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