@compute.ts/dictionary
TypeScript icon, indicating that this package has built-in type declarations

2.2.1 • Public • Published

Presentation

The engine is based on incremental computation algorithms. When a calculation is submitted to the engine, all the computed values are memorized. So, if you change some variable and query an evaluation, the engine is able to compute the result very fast because it recomputes only what has changed.

compute.ts

Libraries

The project provides several libraries that each comes with dozens of operators. Please note the cross-compatibility of the libraries.

Imports

Typescript

import {/* required operators */} from '@compute.ts/dictionary';

Javascript

const {/* required operators */} = require('@compute.ts/dictionary');

Operators

dictionary

dictionary.ofType({key0: y0type, key1: y1type, ..., keyn: yntype}) ➜ z{type}

The dictionary operator allows to create a dictionary expression.

import {dictionary} from "@compute.ts/dictionary";
import {boolean} from "@compute.ts/boolean";

const b = boolean();
const x = dictionary.ofBoolean({key1: true, key2: b});

const value = x.eval();

get

x{type}.get(ystring) ➜ ztype

The get operator allows to create a boolean expression which evals to the value accessed by the given key.

import {dictionary} from "@compute.ts/dictionary";  
import {string} from "@compute.ts/string"

const x = dictionary.ofNumber({key: 12});
const y = string('key');
const z = x.get(y);

const value = z.eval(); // 12

has

x{type}.has(ystring) ➜ zboolean

The has operator allows to create a boolean expression which evals to true if the given dictionary has the given key.

import {dictionary} from "@compute.ts/dictionary";  
import {string} from "@compute.ts/string"

const x = dictionary.ofString({hello: 'world'});
const y = string('hello');
const z = x.has(y);

const value = z.eval();

set

x{type}.set(y0string, y1type) ➜ z{type}

The set operator allows to create a dictionary expression which evals to the given dictionary with a new pair of key/value.

import {dictionary} from "@compute.ts/dictionary";  
import {string} from "@compute.ts/string"
import {boolean} from "@compute.ts/boolean"

const x = dictionary.ofBoolean({key1: false});  

const y1 = string('key2');  
const y2 = boolean(true);
const z = x.set(y1, y2);

const value = z.eval(); // {key1: false, key2: true}

merge

x{type}.merge(y{type}) ➜ z{type}

The merge operator allows to create a dictionary expression which evals to the given dictionary merged with an other given dictionary.

import {dictionary} from "@compute.ts/dictionary";  
import {string} from "@compute.ts/string"
import {boolean} from "@compute.ts/boolean"

const x0 = dictionary.ofBoolean({hello: true});  
const x1 = dictionary.ofBoolean({world: false});  

const y = x0.merge(x1);

const value = y.eval(); // {hello: true, world: false}

keys

x{type}.keys() ➜ y[string]

The keys operator allows to create a dictionary expression which evals to an array expression of the dictionary keys.

import {dictionary} from "@compute.ts/dictionary";  
import {string} from "@compute.ts/string"
import {boolean} from "@compute.ts/boolean"

const x = dictionary.ofBoolean({key1: true, key2: false});  

const y = x.keys();

const value = y.eval(); // ['key1', 'key2']

values

x{type}.values() ➜ y[type]

The values operator allows to create a dictionary expression which evals to an array expression of the dictionary values.

import {dictionary} from "@compute.ts/dictionary";  
import {string} from "@compute.ts/string"
import {boolean} from "@compute.ts/boolean"

const x = dictionary.ofBoolean({key1: true, key2: false});  

const y = x.values();

const value = y.eval(); // [true, false]

About the author

I am a software developer with 4 years of project specializing in the development of web solutions. Digital Nomad, I work while traveling. After 3 years into the french industry, I've started to work as a freelance software architect or fullstack developer.

Based on state-of-the-art web technologies, I offer you to architect & develop the best version of your project. My experience in the web app development assure you to build a nice looking, performant and stable product.

Minimalist, I like to travel, to meet people, learn new things and handmade stuff. Scuba & sky diving licenced. I like also hamburgers, Kinder chocolate and crepes. Karate black belt.

https://berthellemy.com/


Package Sidebar

Install

npm i @compute.ts/dictionary

Weekly Downloads

1

Version

2.2.1

License

MIT

Unpacked Size

181 kB

Total Files

35

Last publish

Collaborators

  • mberthellemy