FunVec2T(FuncInt32, Int32, T, Opt`1Int32, Opt`1FuncInt32, Int32) Constructor

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.

Definition

Namespace: Orx.Fun.FunVec
Assembly: Orx.Fun.FunVec (in Orx.Fun.FunVec.dll) Version: 1.0.0
C#
public FunVec2(
	Func<int, int, T> getValue,
	Opt<int> length1 = default,
	Opt<Func<int, int>> getLength2 = default
)

Parameters

getValue  FuncInt32, Int32, T
Function (index -> value) that returns the value of the element at the given index-th position.
length1  OptInt32  (Optional)
Optional length of the jagged array; will default to None (int.MaxValue) when omitted.
getLength2  OptFuncInt32, Int32  (Optional)
Optional function (i -> length) to get length of the i-th collection; when omitted will default to None which will yield to a length of int.MaxValue for any index.

See Also