This is the second weird project of mine attempting to code in Squirrel an existing successful library. This time, I kinda made LINQ in an engine-independent Squirrel.
-
Download Linq.nut from the latest release and place it under
csgo/scripts/vscripts
. -
Reference it in a script. Referencing it multiple time will not impact performance. Example:
IncludeScript("Linq")
-
You can start
thinking about how stupid this idea isusing Linq (sorta) in your amazing Squirrel projects!
This is very simple. Instantiate a Linq
object providing an array like so:
local myArray = [1, 2, 3];
local linqBadBoy = Linq(myArray);
Now, you can access any of the amazing functions provided by the library. Note that you can chain those who return a Linq
object.
Linq Where(function predicate);
object First(function? predicate = null);
object Last(function? predicate = null);
object Single(function predicate);
bool Any(function? predicate = null);
bool All(function predicate);
bool Contains(object value);
Linq OrderBy(string propertyName);
Linq OrderByDescending(string propertyName);
Linq Skip(int count);
Linq Take(int count);
object Max(string? propertyName = null);
object Min(string? propertyName = null);
object Sum(string? propertyName = null);
object Average(string? propertyName = null);
int Count(function? predicate = null);
Table ToTable(string keyPropertyName, string? valuePropertyName = null);
Array ToArray();
Keep in mind that predicate
parameter functions must follow this signature:
bool predicate(Object element);