time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

SqTableChart.js (1687B)


      1 import * as Result from "../../utility/result.js";
      2 import { SqOtherError } from "../SqError.js";
      3 import { SqLambda } from "./SqLambda.js";
      4 import { wrapValue } from "./index.js";
      5 const wrapFn = ({ fn }) => {
      6     return new SqLambda(fn, undefined);
      7 };
      8 const getItem = (row, column, element, fn, env, context) => {
      9     const response = fn.call([element], env);
     10     const newContext = context && context.extend({ type: "cellAddress", value: { row, column } });
     11     if (response.ok && context) {
     12         return Result.Ok(wrapValue(response.value._value, newContext));
     13     }
     14     else if (response.ok) {
     15         return Result.Err(new SqOtherError("Context creation for table failed."));
     16     }
     17     else {
     18         return response;
     19     }
     20 };
     21 export class SqTableChart {
     22     constructor(_value, context) {
     23         this._value = _value;
     24         this.context = context;
     25     }
     26     item(rowI, columnI, env) {
     27         return getItem(rowI, columnI, wrapValue(this._value.data[rowI], this.context), wrapFn(this._value.columns[columnI]), env, this.context);
     28     }
     29     items(env) {
     30         const wrappedDataItems = this._value.data.map((r) => wrapValue(r, this.context));
     31         const wrappedFns = this._value.columns.map(wrapFn);
     32         return wrappedDataItems.map((item, rowI) => wrappedFns.map((fn, columnI) => getItem(rowI, columnI, item, fn, env, this.context)));
     33     }
     34     get rowCount() {
     35         return this._value.data.length;
     36     }
     37     get columnCount() {
     38         return this._value.columns.length;
     39     }
     40     get columnNames() {
     41         return this._value.columns.map(({ name }) => name);
     42     }
     43     get title() {
     44         return this._value.title;
     45     }
     46 }
     47 //# sourceMappingURL=SqTableChart.js.map