Queries data from a Matrix using a selector Function to transform the objects in each cell of data in the Matrix into a result.
The Matrix may also be a Cube or Hypercube.
The following code queries a Cube, returning the average age of players in a squad by country by position:
const x = dimension(positions, property<Player>('position')); // using the built-in dimension generator matching a propertyconst y = dimension(countries, (country: string) => (player: Player) => player.country === country); // using a user-defined generatorconst cube: Cube<Player> = pivot(squad, y, x);const result: Matrix<number> = query(cube, average(age()));function age(asAt: Date = new Date()): Function<Player, number> { return player => new Date(asAt.getTime() - player.dateOfBirth.getTime()).getUTCFullYear() - 1970;} Copy
const x = dimension(positions, property<Player>('position')); // using the built-in dimension generator matching a propertyconst y = dimension(countries, (country: string) => (player: Player) => player.country === country); // using a user-defined generatorconst cube: Cube<Player> = pivot(squad, y, x);const result: Matrix<number> = query(cube, average(age()));function age(asAt: Date = new Date()): Function<Player, number> { return player => new Date(asAt.getTime() - player.dateOfBirth.getTime()).getUTCFullYear() - 1970;}
See GitHub for a complete example.
The type of the data within the Matrix.
The type of value returned by the selector.
The Matrix to query data from.
A callback Function to create a result from each cell of the Cube.
Queries data from a Matrix using a selector Function to transform the objects in each cell of data in the Matrix into a result.
Remarks
The Matrix may also be a Cube or Hypercube.
Example
The following code queries a Cube, returning the average age of players in a squad by country by position:
See GitHub for a complete example.