FunVec1T(T) |
1-dimensional vector, length and values of which are determined by the underlying array.
var array = new char[] { 'a', 'b', 'c' };
FunVec1<char> vec = new(array);
Assert(vec.Length1 == 3);
Assert(vec[2] == 'c');
Assert(vec.Get(0) == Some('a'));
Assert(vec.Get(3).IsNone);
|
FunVec1T(ListT) |
1-dimensional vector, length and values of which are determined by the underlying list.
var list = new List<char> { 'a', 'b', 'c' };
FunVec1<char> vec = new(list);
Assert(vec.Length1 == 3);
Assert(vec[2] == 'c');
Assert(vec.Get(0) == Some('a'));
Assert(vec.Get(3).IsNone);
|
FunVec1T(FuncInt32, T, OptInt32) |
1-dimensional vector with optional length, values of which are determined by the getValueByIndex function.
static int Factorial(int number) { .. }
FunVec1<int> factorials = new(Factorial);
Assert(factorials.Length1 == int.MaxValue); // since length1 is omitted
Assert(factorials[3] == 6);
Assert(factorials[5] == 120);
FunVec1<int> factorialsUpTo4 = new(Factorial, Some(4));
Assert(factorialsUpTo4.Length1 == 4);
Assert(factorialsUpTo4[3] == 6);
// Assert(factorialsUpTo4[5] == 120); // out-of-bounds, throws!
Assert(factorialsUpTo4.Get(5).IsNone);
|
FunVec1T(T, OptInt32) |
1-dimensional vector with optional length, which always yields the same constant value.
var agentSmith = GetSmith();
FunVec1<Agent> vec = new(agentSmith);
Assert(vec.Length1 == int.MaxValue); // since length1 is omitted
Assert(vec[0] == agentSmith);
Assert(vec[42] == agentSmith);
Assert(vec.Get(100) == Some(agentSmith));
FunVec1<Agent> vec = new(agentSmith, Some(50));
Assert(vec.Length1 == 50);
Assert(vec[0] == agentSmith);
Assert(vec[42] == agentSmith);
Assert(vec.Get(100).IsNone);
|