NETSquirrel - guidelines/Low complexity
Working with base types
editYou are capable to read values of all over base types and accomplish some extra useful operations with them via NETSquirrel.Utils.BaseTypesUtils and NETSquirrel.Extensions.BaseTypesExtensions classes. Let's consider the provided functionality.
Reading base types values from the keyboard
editMethod's signature | Brief description |
---|---|
bool ReadBool(string) | Reads the bool value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
byte ReadByte(string) | Reads the byte value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
sbyte ReadSByte(string) | Reads the sbyte value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
char ReadChar(string) | Reads the char value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
decimal ReadDecimal(string) | Reads the decimal value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
double ReadDouble(string) | Reads the double value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
float ReadFloat(string) | Reads the float value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
int ReadInt(string) | Reads the int value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
uint ReadUInt(string) | Reads the uint value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
long ReadLong(string) | Reads the long value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
ulong ReadULong(string) | Reads the ulong value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
short ReadShort(string) | Reads the short value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
ushort ReadUShort(string) | Reads the ushort value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
string ReadString(string) | Reads the string value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
The general idea used in methods names is: ReadTypeName, where TypeName - is the base type's name.
ReadBool usage example:
using NETSquirrel.Extensions;
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
BaseTypesUtils.ReadBool("Bool:").PrintLine();
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
begin
BaseTypesUtils.ReadBool('Bool:').PrintLine();
end.
Values swapping
editMethod's signature | Brief description |
---|---|
void Swap<T>(ref T, ref T) | Swapped two variables values.
Parameters:
|
Swap usage example:
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
var x = 1;
var y = 2;
BaseTypesUtils.Swap(ref x, ref y); // x == 2, y == 1
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
begin
var x := 1;
var y := 2;
BaseTypesUtils.Swap(x, y); // x = 2, y = 1
end.
Sequences generation from particular ranges
editMethod's signature | Brief description |
---|---|
bool IsBetween(this int, int, int) | Evaluates whether the value passed as this parameter is between two other ones and returns the according bool value.
Parameters:
Notes:
|
IEnumerable<int> To(this int, int) | Generates the sequence from the value passed as this parameter to higher one and returns it.
Parameters:
Notes:
|
IEnumerable<int> DownTo(this int, int) | Generates the sequence from the value passed as this parameter to lower one and returns it.
Parameters:
Notes:
|
IEnumerable<int> ToThis(this int) | Generates the sequences from 0 up to/down to (dependent on the second value) to the value passed as this parameter and returns it.
Parameters:
Notes:
|
IEnumerable<int> Stepped(this int, int) | Generates the endless sequence from the value passed as this parameter with the specified step and returns it.
Parameters:
Notes:
|
bool Print() | Outputs bool typed value.
Parameters:
|
bool PrintLine() | Outputs bool typed value and jumps onto the new line.
Parameters:
|
byte Print() | Outputs byte typed value.
Parameters:
|
byte PrintLine() | Outputs byte typed value and jumps onto the new line.
Parameters:
|
sbyte Print() | Outputs sbyte typed value.
Parameters:
|
sbyte PrintLine() | Outputs sbyte typed value and jumps onto the new line.
Parameters:
|
char Print() | Outputs char typed value.
Parameters:
|
char PrintLine() | Outputs char typed value and jumps onto the new line.
Parameters:
|
decimal Print() | Outputs decimal typed value.
Parameters:
|
decimal PrintLine() | Outputs decimal typed value and jumps onto the new line.
Parameters:
|
double Print() | Outputs double typed value.
Parameters:
|
double PrintLine() | Outputs double typed value and jumps onto the new line.
Parameters:
|
float Print() | Outputs float typed value.
Parameters:
|
float PrintLine() | Outputs float typed value and jumps onto the new line.
Parameters:
|
int Print() | Outputs int typed value.
Parameters:
|
int PrintLine() | Outputs int typed value and jumps onto the new line.
Parameters:
|
uint Print() | Outputs uint typed value.
Parameters:
|
uint PrintLine() | Outputs uint typed value and jumps onto the new line.
Parameters:
|
long Print() | Outputs long typed value.
Parameters:
|
long PrintLine() | Outputs long typed value and jumps onto the new line.
Parameters:
|
ulong Print() | Outputs ulong typed value.
Parameters:
|
ulong PrintLine() | Outputs ulong typed value and jumps onto the new line.
Parameters:
|
short Print() | Outputs short typed value.
Parameters:
|
short PrintLine() | Outputs short typed value and jumps onto the new line.
Parameters:
|
ushort Print() | Outputs ushort typed value.
Parameters:
|
ushort PrintLine() | Outputs ushort typed value and jumps onto the new line.
Parameters:
|
To, DownTo and ToThis usage example:
using NETSquirrel.Extensions;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
1.To(10).PrintLine(); // 1, 2, ..., 10
10.DownTo(1).PrintLine(); // 10, 9, ..., 1
10.ToThis().PrintLine(); // 0, 1, ..., 10
}
}
}
{$reference NETSquirrel.dll}
begin
1.To(10).PrintLine(); // 1, 2, ..., 10
10.DownTo(1).PrintLine(); // 1, 2, ..., 10
10.ToThis().PrintLine(); // 1, 2, ..., 10
end.
Working with arrays
editYou are capable to read arrays of all over base types and accomplish some extra useful operations with them via NETSquirrel.Utils.ArrayUtils class. Let's consider the provided functionality.
Arrays generators
editMethod's signature | Brief description |
---|---|
T[] GenerateArray<T>(int, Func<int, T>, int) | Generates the array with specified length via particular selector and returns it.
Parameters:
Exceptions:
Notes:
|
T[] GenerateArray<T>(int, T, Func<T, T>) | Generates the array with specified length via particular selector and returns it.
Parameters:
Exceptions:
|
T[] GenerateArray<T>(int, Func<T[], int, T>) | Generates the array with specified length via particular selector and returns it.
Parameters:
Exceptions:
Notes:
|
int[] CreateRandomIntArray(int, int, int) | Creates the randomly filled array with values taken from the particular range.
Parameters:
Exceptions:
|
float[] CreateRandomFloatArray(int, float, float) | Creates the randomly filled array with values taken from the particular range.
Parameters:
Exceptions:
|
GenerateArray usage example:
using NETSquirrel.Extensions;
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
ArraysUtils.GenerateArray(10, i => i).PrintLine(); // 0, 1, ..., 10
ArraysUtils.GenerateArray(10, 0, x => x + 1).PrintLine(); // 0, 1, ..., 10
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
begin
ArraysUtils.GenerateArray(10, i -> i).PrintLine(); // 0, 1, ..., 10
ArraysUtils.GenerateArray(10, 0, x -> x + 1).PrintLine(); // 0, 1, ..., 10
end.
GenerateArray usage example 2:
using NETSquirrel.Extensions;
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
ArraysUtils.GenerateArray<int>(10, (array, i) => {
switch (i)
{
case 0:
case 1:
return 1;
default:
return array[i - 1] + array[i - 2];
}
}).PrintLine(); // 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
begin
ArraysUtils.GenerateArray&<integer>(10, (a, i) -> begin
case i of
0, 1: Result := 1;
else Result := a[i - 1] + a[i - 2];
end;
end).PrintLine(); // 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
end.
Arrays reading from the keyboard
editMethod's name | Brief description |
---|---|
bool[] ReadBoolArray(int, string) | Reads the array of bool[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
bool[] ReadBoolArray(int, Func<int, string>) | Reads the array of bool[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
bool[] ReadBoolArray(int, ExceptionHandler, string) | Reads the array of bool[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
bool[] ReadBoolArray(int, ExceptionHandler, Func<int, string>) | Reads the array of bool[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
byte[] ReadByteArray(int, string) | Reads the array of byte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
byte[] ReadByteArray(int, Func<int, string>) | Reads the array of byte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
byte[] ReadByteArray(int, ExceptionHandler, string) | Reads the array of byte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
byte[] ReadByteArray(int, ExceptionHandler, Func<int, string>) | Reads the array of byte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
sbyte[] ReadSByteArray(int, string) | Reads the array of sbyte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
sbyte[] ReadSByteArray(int, Func<int, string>) | Reads the array of sbyte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
sbyte[] ReadSByteArray(int, ExceptionHandler, string) | Reads the array of sbyte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
sbyte[] ReadSByteArray(int, ExceptionHandler, Func<int, string>) | Reads the array of sbyte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
char[] ReadCharArray(int, string) | Reads the array of char[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
char[] ReadCharArray(int, Func<int, string>) | Reads the array of char[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
decimal[] ReadDecimalArray(int, string) | Reads the array of decimal[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
decimal[] ReadDecimalArray(int, Func<int, string>) | Reads the array of decimal[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
decimal[] ReadDecimalArray(int, ExceptionHandler, string) | Reads the array of decimal[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
decimal[] ReadDecimalArray(int, ExceptionHandler, Func<int, string>) | Reads the array of decimal[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
double[] ReadDooubleArray(int, string) | Reads the array of double[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
double[] ReadDooubleArray(int, Func<int, string>) | Reads the array of double[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
double[] ReadDooubleArray(int, ExceptionHandler, string) | Reads the array of double[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
double[] ReadDooubleArray(int, ExceptionHandler, Func<int, string>) | Reads the array of double[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
float[] ReadFloatArray(int, string) | Reads the array of float[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
float[] ReadFloatArray(int, Func<int, string>) | Reads the array of float[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
float[] ReadFloatArray(int, ExceptionHandler, string) | Reads the array of float[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
float[] ReadFloatArray(int, ExceptionHandler, Func<int, string>) | Reads the array of float[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
int[] ReadIntArray(int, string) | Reads the array of int[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
int[] ReadIntArray(int, Func<int, string>) | Reads the array of int[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
int[] ReadIntArray(int, ExceptionHandler, string) | Reads the array of int[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
int[] ReadIntArray(int, ExceptionHandler, Func<int, string>) | Reads the array of int[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
uint[] ReadUIntArray(int, string) | Reads the array of uint[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
uint[] ReadUIntArray(int, Func<int, string>) | Reads the array of uint[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
uint[] ReadUIntArray(int, ExceptionHandler, string) | Reads the array of uint[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
uint[] ReadUIntArray(int, ExceptionHandler, Func<int, string>) | Reads the array of uint[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
long[] ReadLongArray(int, string) | Reads the array of long[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
long[] ReadLongArray(int, Func<int, string>) | Reads the array of long[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
long[] ReadLongArray(int, ExceptionHandler, string) | Reads the array of long[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
long[] ReadLongArray(int, ExceptionHandler, Func<int, string>) | Reads the array of long[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ulong[] ReadULongArray(int, string) | Reads the array of ulong[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ulong[] ReadULongArray(int, Func<int, string>) | Reads the array of ulong[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ulong[] ReadULongArray(int, ExceptionHandler, string) | Reads the array of ulong[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ulong[] ReadULongArray(int, ExceptionHandler, Func<int, string>) | Reads the array of ulong[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
short[] ReadShortArray(int, string) | Reads the array of short[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
short[] ReadShortArray(int, Func<int, string>) | Reads the array of short[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
short[] ReadShortArray(int, ExceptionHandler, string) | Reads the array of short[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
short[] ReadShortArray(int, ExceptionHandler, Func<int, string>) | Reads the array of short[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ushort[] ReadUShortArray(int, string) | Reads the array of ushort[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ushort[] ReadUShortArray(int, Func<int, string>) | Reads the array of ushort[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ushort[] ReadUShortArray(int, ExceptionHandler, string) | Reads the array of ushort[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ushort[] ReadUShortArray(int, ExceptionHandler, Func<int, string>) | Reads the array of ushort[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
string[] ReadStringArray(int, string) | Reads the array of string[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
string[] ReadStringArray(int, Func<int, string>) | Reads the array of string[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ReadBoolArray usage example:
using NETSquirrel.Extensions;
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
ArraysUtils.ReadBoolArray(10, "item {0} = ").PrintLine();
ArraysUtils.ReadBoolArray(10, i => $"{new[] { "even", "odd" }[i % 2]} item = ").PrintLine();
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
begin
ArraysUtils.ReadBoolArray(10, 'item {0} = ').PrintLine();
var lambda: integer -> string := i -> string.Format('{0} item = ', (new string[] ('even', 'odd'))[i mod 2]);
ArraysUtils.ReadBoolArray(10, lambda).PrintLine();
end.
ReadBoolArray usage example 2:
using NETSquirrel.Extensions;
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
ArraysUtils.ReadBoolArray(10, e => e.Message.PrintLine(), "item {0} = ").PrintLine();
ArraysUtils.ReadBoolArray(10, e => e.Message.PrintLine(),
i => $"{new[] { "even", "odd" }[i % 2]} item = ").PrintLine();
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
uses NETSquirrel;
begin
ArraysUtils.ReadBoolArray(10, procedure(e) -> e.Message.PrintLine(), 'item {0} = ').PrintLine();
ArraysUtils.ReadBoolArray(10, procedure(e) -> e.Message.PrintLine(),
i -> string.Format('{0} item = ', (new string[] ('even', 'odd'))[i mod 2])).PrintLine();
end.