Orx.Fun.FunVec Namespace
Unified functional collections for C# allowing access by index.
FunVec1T |
A unified functional 1-dimensional collection.
It does not hold the data, rather provides a unified view over different sources of data providing indexed access to collection elements.
|
FunVec2T |
A unified functional 2-dimensional collection.
It does not hold the data, rather provides a unified view over different sources of data providing indexed access to collection elements.
Takes a functional approach; i.e., the following closures are defined and stored on construction:
- closure to get the jagged lengths in all dimensions;
- closure to get element at the given indices (also the bounds-checked version GetOrNone, in addition to direct access by indices);
- closure to get the collection as IEnumerable.
The allocation is limited by these closures.
The data is not re-allocated, or memoized.
For instance, if a unified collection is defined to always return a contant value,
and have a length of 1000 collections in the first dimension,
and 1000 elements in the second dimension for each of the collection;
there will NOT be an underlying array storing the same value 1_000_000 times.
To clarify that the unified collection only holds a reference, consider the following example. int[][] underlyingArray = new int[] { new int[] { 0, 10 }, new int[] { 1, 11, 111, 1111 }, new int[] { 2, 22, 222 } };
FunVec2<int> jagged = new(underlyingArray);
Assert(underlyingArray[1][0] == 1 and jagged[1, 0] == 1);
underlyingArray[1][0] = 42;
Assert(underlyingArray[1][0] == 42 and jagged[1, 0] == 42);
To further illustrate, consider the following with underlying list of lists. List<List<char>> underlyingList = new() { new() { 'a', 'b', 'c', 'd' }, new() { 'u', 'v' } };
FunVec2<char> jagged = new(underlyingList);
Assert(underlyingList.Count == 2 and jagged.Length1 == 2);
underlyingList.Add(new() { 'x', 'y', 'z' });
Assert(underlyingList.Count == 3 and jagged.Length1 == 3);
Assert(underlyingList[0].Count == 4 and jagged.Length2(0) == 4);
underlyingList[0].Add('e');
Assert(underlyingList[0].Count == 5 and jagged.Length2(0) == 5);
The unified jagged collection exposes a unified interface for the following methods: - Length1: length in the first dimension (i.e., number of 1D collections).
- Length2(i): length of the i-th collection in the second dimension (i.e., number of elements in the i-th 1D collection).
- this[i]: i-th D1 collection.
- this[i,j]: element at the (i,j)-th position (i.e., j-th element of the i-th 1D collection).
- GetOrNone(i, j): returns Some of the element at the (i,j)-th position if indices are valid; None otherwise.
- AsEnumerable(): returns the collection as IEnumerable; particularly useful for linq calls over the collection.
|
FunVec3T |
A unified functional 3-dimensional collection.
It does not hold the data, rather provides a unified view over different sources of data providing indexed access to collection elements.
|
FunVec4T |
A unified functional 4-dimensional collection.
It does not hold the data, rather provides a unified view over different sources of data providing indexed access to collection elements.
|