FunVec4T Class

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.

Definition

Namespace: Orx.Fun.FunVec
Assembly: Orx.Fun.FunVec (in Orx.Fun.FunVec.dll) Version: 1.0.0
C#
public class FunVec4<T> : IEnumerable<FunVec3<T>>, 
	IEnumerable
Inheritance
Object    FunVec4T
Implements
IEnumerableFunVec3T, IEnumerable

Type Parameters

T
Type of the innermost elements of the collection.

Constructors

FunVec4T(T) 4-dimensional jagged collection lengths and values of which are determined by the underlying array.

See FunVec2T(T) for two-dimensional examples.

FunVec4T(ListListListListT) 4-dimensional jagged collection lengths and values of which are determined by the underlying list.

See FunVec2T(ListListT) for two-dimensional examples.

FunVec4T(FuncInt32, Int32, Int32, Int32, T, OptInt32, OptFuncInt32, Int32, OptFuncInt32, Int32, Int32, OptFuncInt32, Int32, Int32, Int32) 4-dimensional jagged collection with optional lengths, values of which are determined by the getValue function.

See FunVec2T(FuncInt32, Int32, T, OptInt32, OptFuncInt32, Int32) for two-dimensional examples.

FunVec4T(T, OptInt32, OptFuncInt32, Int32, OptFuncInt32, Int32, Int32, OptFuncInt32, Int32, Int32, Int32) 4-dimensional jagged collection with optional lengths, which always yields the same constant value.

See FunVec2T(T, OptInt32, OptFuncInt32, Int32) for two-dimensional examples.

Properties

HasUnderlyingScalar The unified collection might be constructed with a constant scalar value; hence, returning the scalar for all indices. If this is the case, HasUnderlyingScalar is true; and the field UnderlyingScalar equals to Some of the underlying scalar value.

Otherwise, HasUnderlyingScalar is false and UnderlyingScalar.IsNone.

C#
// vec[i] = 10, for all i.
UniJaggedD1<int> vec = new(10);
Assert(vec[3] == 10 and vec[42] == 10);
Assert(vec.Get(12) == Some(10));

// underlying constant can be obtained by the optional UnderlyingScalar field.
Assert(vec.HasUnderlyingScalar);
Assert(vec.UnderlyingScalar.IsSome);
Assert(vec.UnderlyingScalar == Some(10));
Assert(vec.UnderlyingScalar.Unwrap() == 10);
Item Directly returns the element at the i-th position. Use Get(Int32, Int32, Int32, Int32) for the bound-checked optional version.
C#
var underlyingArray = new int[] { 10, 11, 12 };
FunVec1<int> vec = new(underlyingArray);

Assert(vec[1] == 11);

// var x = vec[-1]; => out-of-bounds, throws!
// var x = vec[3]; => out-of-bounds, throws!

Methods

Equals
(Inherited from Object)
Finalize
(Inherited from Object)
Get Safely gets the element at the i-th position; returns None if the index is invalid.
C#
var underlyingArray = new int[] { 10, 11, 12 };
FunVec1<int> vec = new(underlyingArray);

Assert(jagvecged.Get(1) == Some(11));
Assert(vec.Get(-1).IsNone);
Assert(vec.Get(2).IsNone);
For other methods on the resulting optional, see Opt.
GetEnumerator Returns the enumerator for sub-vectors in the vector.
GetHashCode
(Inherited from Object)
GetType
(Inherited from Object)
MemberwiseClone
(Inherited from Object)
ToString
(Inherited from Object)

Operators

(FuncInt32, Int32, Int32, Int32, T to FunVec4T) 4-dimensional jagged collection with optional lengths, values of which are determined by the getValue function.

See FunVec2T(FuncInt32, Int32, T, OptInt32, OptFuncInt32, Int32) for two-dimensional examples.

(T to FunVec4T) 4-dimensional jagged collection with optional lengths, which always yields the same constant value.

See FunVec2T(T, OptInt32, OptFuncInt32, Int32) for two-dimensional examples.

(T to FunVec4T) 4-dimensional jagged collection lengths and values of which are determined by the underlying array.

See FunVec2T(T) for two-dimensional examples.

(ListListListListT to FunVec4T) 4-dimensional jagged collection lengths and values of which are determined by the underlying list.

See FunVec2T(ListListT) for two-dimensional examples.

Fields

Length1 Length of the vector.
C#
var underlyingList = new List<int> { 10, 11, 12 };
FunVec1<int> vec = new(underlyingList);
Assert(vec.Length1 == 3);

Func<int, bool> underlyingFun = i => i % 2 == 0;
vec = new(underlyingFun, length1: Some(4));
Assert(vec.Length1, 4);

Func<int, bool> underlyingFun = i => i % 2 == 0;
vec = new(underlyingFun); // omitted optional argument 'length1' defaults to None -> no limit
Assert(vec.Length1 == int.MaxValue);
Length2 Length of the jagged array in the first dimension; i.e., number of 1D collections.
C#
var underlyingList = new List<List<int>> { new() { 1 }, new() { 2, 3, 4 } };
FunVec2<int> jagged = new(underlyingList);
Assert(jagged.Length1 == 2);
Assert(jagged.Length2(0) == 1);
Assert(jagged.Length2(1) == 3);

Func<int, int, bool> underlyingFun = (i, j) => (i + j) % 2 == 0;
FunVec2<bool> upperTriangular = new(underlyingFun, length1: Some(3), getLength2: Some<Func<int, int>>(i => i + 1));
Assert(jagged.Length1 == 3);
Assert(jagged.Length2(0) == 1);
Assert(jagged.Length2(1) == 2);
Assert(jagged.Length2(2) == 3);

FunVec2<Agent> bool = new(underlyingFun, length1: Some(2)); // omitted optional argument 'length2' defaults to None -> no limit
Assert(jagged.Length2(0) == jagged.Length2(1) == int.MaxValue);
Length3 Length of the jagged collection in the third dimension.
C#
var array = new int[2][][]
{
    new int[3][]
    {
        new int[2] { 0, 1 },
        new int[3] { 2, 3, 4 },
        Array.Empty<int>(),
    },
    new int[1][]
    {
        new int[4] { 0, 1, 2, 3 },
    }
};
UniJaggedD3<int> jagged = new(array);
Assert(jagged.Length3(0, 2) == 0);
Length4 Length of the jagged collection in the third dimension.
C#
var array = new int[2][][]
{
    new int[3][]
    {
        new int[2] { 0, 1 },
        new int[3] { 2, 3, 4 },
        Array.Empty<int>(),
    },
    new int[1][]
    {
        new int[4] { 0, 1, 2, 3 },
    }
};
UniJaggedD3<int> jagged = new(array);
Assert(jagged.Length3(0, 2) == 0);
UnderlyingScalar The unified collection might be constructed with a constant scalar value; hence, returning the scalar for all indices. If this is the case, HasUnderlyingScalar is true; and the field UnderlyingScalar equals to Some of the underlying scalar value.

Otherwise, HasUnderlyingScalar is false and UnderlyingScalar.IsNone.

C#
// vec[i] = 10, for all i.
UniJaggedD1<int> vec = new(10);
Assert(vec[3] == 10 and vec[42] == 10);
Assert(vec.Get(12) == Some(10));

// underlying constant can be obtained by the optional UnderlyingScalar field.
Assert(vec.HasUnderlyingScalar);
Assert(vec.UnderlyingScalar.IsSome);
Assert(vec.UnderlyingScalar == Some(10));
Assert(vec.UnderlyingScalar.Unwrap() == 10);

See Also