@calcit/procs 0.7.8 → 0.7.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  // CALCIT VERSION
3
- export const calcit_version = "0.7.8";
3
+ export const calcit_version = "0.7.10";
4
4
  import { parse } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
6
6
  import { CalcitSymbol, CalcitTag, CalcitRef, CalcitRecur, newTag, refsRegistry, toString, getStringName, _$n__$e_, hashFunction, } from "./calcit-data.mjs";
@@ -441,12 +441,13 @@ export let _$n_str_$o_first = (xs) => {
441
441
  console.error(xs);
442
442
  throw new Error("Expected a string");
443
443
  };
444
- export let _$n_map_$o_first = (xs) => {
444
+ export let _$n_map_$o_destruct = (xs) => {
445
445
  if (xs instanceof CalcitMap || xs instanceof CalcitSliceMap) {
446
- // TODO order may not be stable enough
447
- let ys = xs.pairs();
448
- if (ys.length > 0) {
449
- return new CalcitSliceList(ys[0]);
446
+ // order not stable
447
+ if (xs.len() > 0) {
448
+ let pair = xs.pairs()[0];
449
+ let k0 = pair[0];
450
+ return new CalcitSliceList([new CalcitSliceList(pair), xs.dissoc(k0)]);
450
451
  }
451
452
  else {
452
453
  return null;
@@ -455,12 +456,11 @@ export let _$n_map_$o_first = (xs) => {
455
456
  console.error(xs);
456
457
  throw new Error("Expected a map");
457
458
  };
458
- export let _$n_set_$o_first = (xs) => {
459
- if (xs instanceof CalcitSet) {
460
- return xs.first();
461
- }
459
+ export let _$n_set_$o_destruct = (xs) => {
460
+ if (xs instanceof CalcitSet)
461
+ return xs.destruct();
462
462
  console.error(xs);
463
- throw new Error("Expected a set");
463
+ throw new Error("Expect a set");
464
464
  };
465
465
  export let timeout_call = (duration, f) => {
466
466
  if (typeof duration !== "number") {
@@ -488,25 +488,6 @@ export let _$n_str_$o_rest = (xs) => {
488
488
  console.error(xs);
489
489
  throw new Error("Expects a string");
490
490
  };
491
- export let _$n_set_$o_rest = (xs) => {
492
- if (xs instanceof CalcitSet)
493
- return xs.rest();
494
- console.error(xs);
495
- throw new Error("Expect a set");
496
- };
497
- export let _$n_map_$o_rest = (xs) => {
498
- if (xs instanceof CalcitMap || xs instanceof CalcitSliceMap) {
499
- if (xs.len() > 0) {
500
- let k0 = xs.pairs()[0][0];
501
- return xs.dissoc(k0);
502
- }
503
- else {
504
- return new CalcitSliceMap([]);
505
- }
506
- }
507
- console.error(xs);
508
- throw new Error("Expected map");
509
- };
510
491
  export let recur = (...xs) => {
511
492
  return new CalcitRecur(xs);
512
493
  };
package/lib/js-set.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { toString } from "./calcit-data.mjs";
2
2
  import { mapLen, assocMap, dissocMap, toPairsArray, contains, initTernaryTreeMapFromArray, initEmptyTernaryTreeMap, } from "@calcit/ternary-tree";
3
3
  import * as ternaryTree from "@calcit/ternary-tree";
4
+ import { CalcitSliceList } from "./js-list.mjs";
4
5
  /** need to compare by Calcit */
5
6
  let DATA_EQUAL = (x, y) => {
6
7
  return x === y;
@@ -67,20 +68,14 @@ export class CalcitSet {
67
68
  }
68
69
  return new CalcitSet(result);
69
70
  }
70
- first() {
71
- // rather suspicious solution since set has no logical order
71
+ destruct() {
72
72
  if (mapLen(this.value) === 0) {
73
73
  return null;
74
74
  }
75
- return toPairsArray(this.value)[0][0];
76
- }
77
- rest() {
78
- if (mapLen(this.value) === 0) {
79
- return null;
80
- }
81
- let x0 = this.first();
75
+ // rather suspicious solution since set has no logical order
76
+ let x0 = toPairsArray(this.value)[0][0];
82
77
  let result = dissocMap(this.value, x0);
83
- return new CalcitSet(result);
78
+ return new CalcitSliceList([x0, new CalcitSet(result)]);
84
79
  }
85
80
  toString(disableJsDataWarning = false) {
86
81
  let itemsCode = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.7.8",
3
+ "version": "0.7.10",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^20.4.4",
@@ -1,5 +1,5 @@
1
1
  // CALCIT VERSION
2
- export const calcit_version = "0.7.8";
2
+ export const calcit_version = "0.7.10";
3
3
 
4
4
  import { parse, ICirruNode } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
@@ -497,12 +497,14 @@ export let _$n_str_$o_first = (xs: CalcitValue): CalcitValue => {
497
497
  console.error(xs);
498
498
  throw new Error("Expected a string");
499
499
  };
500
- export let _$n_map_$o_first = (xs: CalcitValue): CalcitValue => {
500
+
501
+ export let _$n_map_$o_destruct = (xs: CalcitValue): CalcitValue => {
501
502
  if (xs instanceof CalcitMap || xs instanceof CalcitSliceMap) {
502
- // TODO order may not be stable enough
503
- let ys = xs.pairs();
504
- if (ys.length > 0) {
505
- return new CalcitSliceList(ys[0]);
503
+ // order not stable
504
+ if (xs.len() > 0) {
505
+ let pair = xs.pairs()[0];
506
+ let k0 = pair[0];
507
+ return new CalcitSliceList([new CalcitSliceList(pair), xs.dissoc(k0)]);
506
508
  } else {
507
509
  return null;
508
510
  }
@@ -510,13 +512,12 @@ export let _$n_map_$o_first = (xs: CalcitValue): CalcitValue => {
510
512
  console.error(xs);
511
513
  throw new Error("Expected a map");
512
514
  };
513
- export let _$n_set_$o_first = (xs: CalcitValue): CalcitValue => {
514
- if (xs instanceof CalcitSet) {
515
- return xs.first();
516
- }
515
+
516
+ export let _$n_set_$o_destruct = (xs: CalcitValue): CalcitValue => {
517
+ if (xs instanceof CalcitSet) return xs.destruct();
517
518
 
518
519
  console.error(xs);
519
- throw new Error("Expected a set");
520
+ throw new Error("Expect a set");
520
521
  };
521
522
 
522
523
  export let timeout_call = (duration: number, f: CalcitFn): null => {
@@ -547,24 +548,6 @@ export let _$n_str_$o_rest = (xs: CalcitValue): CalcitValue => {
547
548
  console.error(xs);
548
549
  throw new Error("Expects a string");
549
550
  };
550
- export let _$n_set_$o_rest = (xs: CalcitValue): CalcitValue => {
551
- if (xs instanceof CalcitSet) return xs.rest();
552
-
553
- console.error(xs);
554
- throw new Error("Expect a set");
555
- };
556
- export let _$n_map_$o_rest = (xs: CalcitValue): CalcitValue => {
557
- if (xs instanceof CalcitMap || xs instanceof CalcitSliceMap) {
558
- if (xs.len() > 0) {
559
- let k0 = xs.pairs()[0][0];
560
- return xs.dissoc(k0);
561
- } else {
562
- return new CalcitSliceMap([]);
563
- }
564
- }
565
- console.error(xs);
566
- throw new Error("Expected map");
567
- };
568
551
 
569
552
  export let recur = (...xs: CalcitValue[]): CalcitRecur => {
570
553
  return new CalcitRecur(xs);
package/ts-src/js-set.mts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  initEmptyTernaryTreeMap,
16
16
  } from "@calcit/ternary-tree";
17
17
  import * as ternaryTree from "@calcit/ternary-tree";
18
+ import { CalcitSliceList } from "./js-list.mjs";
18
19
 
19
20
  /** need to compare by Calcit */
20
21
  let DATA_EQUAL = (x: CalcitValue, y: CalcitValue): boolean => {
@@ -87,22 +88,15 @@ export class CalcitSet {
87
88
  return new CalcitSet(result);
88
89
  }
89
90
 
90
- first(): CalcitValue {
91
- // rather suspicious solution since set has no logical order
92
-
91
+ destruct(): CalcitSliceList {
93
92
  if (mapLen(this.value) === 0) {
94
93
  return null;
95
94
  }
95
+ // rather suspicious solution since set has no logical order
96
+ let x0 = toPairsArray(this.value)[0][0];
96
97
 
97
- return toPairsArray(this.value)[0][0];
98
- }
99
- rest(): CalcitSet {
100
- if (mapLen(this.value) === 0) {
101
- return null;
102
- }
103
- let x0 = this.first();
104
98
  let result = dissocMap(this.value, x0);
105
- return new CalcitSet(result);
99
+ return new CalcitSliceList([x0, new CalcitSet(result)]);
106
100
  }
107
101
 
108
102
  toString(disableJsDataWarning: boolean = false) {