FunVec2T   Conversion Operators

Overload List

(FuncInt32, Int32, T to FunVec2T) 2-dimensional jagged collection with optional lengths, values of which are determined by the getValue function.
C#
static int GetDistance(int from, int to) { return Math.Abs(to - from); }

FunVec2<int> distances = new(GetDistance);
Assert(distances.Length1 == int.MaxValue);    // since length1 is omitted
Assert(distances.Length2(100) == int.MaxValue); // since length2 is omitted
Assert(distances[1, 2] == 1);
Assert(distances[10, 5] == 5);

FunVec2<int> distancesUpTo4 = new(GetDistance, Some(4));
Assert(distancesUpTo4.Length1 == 4);
Assert(distancesUpTo4[3, 1] == 2);
// Assert(distancesUpTo4[5, 1] == 4); // out-of-bounds, throws!
Assert(distancesUpTo4.GetOrNone(5, 1).IsNone);

FunVec2<int> distancesUpTo4 = new(GetDistance, Some(4), Some<Func<int, int>>(i => 2*i));
Assert(distancesUpTo4.Length1 == 4);
Assert(distancesUpTo4.Length2(2) == 4);
Assert(distancesUpTo4[3, 5] == 2);
// Assert(distancesUpTo4[3, 6] == 3); // out-of-bounds, throws!
// Assert(distancesUpTo4[4, 0] == 4); // out-of-bounds, throws!
Assert(distancesUpTo4.GetOrNone(3, 6).IsNone);  // since Length2(3) is 6, index 6 is out of bounds.
Assert(distancesUpTo4.GetOrNone(4, 0).IsNone);  // since Length1 is 4, index 4 is out of bounds.
(T to FunVec2T) 2-dimensional jagged collection with optional lengths, which always yields the same constant value.
C#
var agentSmith = GetSmith();
FunVec2<Agent> jagged = new(agentSmith);
Assert(jagged.Length1 == int.MaxValue);   // since length1 is omitted
Assert(jagged.Length2(42) == int.MaxValue); // since length2 is omitted
Assert(jagged[0][0] == agentSmith);
Assert(jagged[42][42] == agentSmith);
Assert(jagged.GetOrNone(100, 42) == Some(agentSmith));

FunVec2<Agent> jagged = new(agentSmith, Some(50));
Assert(jagged.Length1 == 50);
Assert(jagged.Length2(42) == int.MaxValue); // since length2 is omitted
Assert(jagged[0][0] == agentSmith);
Assert(jagged[42][142] == agentSmith);
Assert(jagged.GetOrNone(100, 2).IsNone);

FunVec2<Agent> jagged = new(agentSmith, Some(50), Some<Func<int, int>>(_ => 2));
Assert(jagged.Length1 == 50);
Assert(jagged.Length2(42) == 2);
Assert(jagged[0][0] == agentSmith);
Assert(jagged[42][1] == agentSmith);
Assert(jagged.GetOrNone(0, 2).IsNone);
Assert(jagged.GetOrNone(50, 0).IsNone);

FunVec2<Agent> jagged = new(agentSmith, Some(50), Some<Func<int, int>>(i => i));
Assert(jagged.Length1 == 50);
Assert(jagged.Length2(0) == 0);
Assert(jagged.Length2(42) == 42);
Assert(jagged[42][1] == agentSmith);
Assert(jagged.GetOrNone(1, 0) == Some(agentSmith));
Assert(jagged.GetOrNone(0, 0).IsNone);
Assert(jagged.GetOrNone(50, 0).IsNone);
(T to FunVec2T) 2-dimensional jagged collection lengths and values of which are determined by the underlying array.
C#
var array = new char[][] { new char[] { 'a', 'b', 'c' }, new char[] { 'd' } };
FunVec2<char> jagged = new(array);
Assert(jagged.Length1 == 2);
Assert(jagged.Length2(0) == 3);
Assert(jagged.Length2(1) == 1);
Assert(jagged[0, 2] == 'c');
Assert(jagged.GetOrNone(1, 0) == Some('d'));
Assert(jagged.GetOrNone(0, 3).IsNone);
Assert(jagged.GetOrNone(2, 0).IsNone);
(ListListT to FunVec2T) 2-dimensional jagged collection lengths and values of which are determined by the underlying list.
C#
var list = new List<List<char>>() { new() { 'a', 'b', 'c' }, new() { 'd' } };
FunVec2<char> jagged = new(list);
Assert(jagged.Length1 == 2);
Assert(jagged.Length2(0) == 3);
Assert(jagged.Length2(1) == 1);
Assert(jagged[0, 2] == 'c');
Assert(jagged.GetOrNone(1, 0) == Some('d'));
Assert(jagged.GetOrNone(0, 3).IsNone);
Assert(jagged.GetOrNone(2, 0).IsNone);

See Also