@noldova/context.collections 0.0.9 → 0.0.11

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.
Files changed (59) hide show
  1. package/README.md +42 -14
  2. package/api/index.d.ts +1479 -0
  3. package/api/index.js +17 -0
  4. package/api/index.js.map +1 -1
  5. package/extensions/enumerable.extensions.js +36 -0
  6. package/extensions/enumerable.extensions.js.map +1 -0
  7. package/interfaces/i-equality-comparer.js +9 -0
  8. package/interfaces/i-equality-comparer.js.map +1 -0
  9. package/interfaces/i-read-only-dictionary.js +9 -0
  10. package/interfaces/i-read-only-dictionary.js.map +1 -0
  11. package/interfaces/i-read-only-list.js +9 -0
  12. package/interfaces/i-read-only-list.js.map +1 -0
  13. package/interfaces/i-read-only-set.js +9 -0
  14. package/interfaces/i-read-only-set.js.map +1 -0
  15. package/models/change-counter.js +23 -0
  16. package/models/change-counter.js.map +1 -0
  17. package/models/default-equality-comparer.js +35 -0
  18. package/models/default-equality-comparer.js.map +1 -0
  19. package/models/dictionary.js +74 -0
  20. package/models/dictionary.js.map +1 -0
  21. package/models/enumerable.js +399 -0
  22. package/models/enumerable.js.map +1 -0
  23. package/models/grouping.js +21 -0
  24. package/models/grouping.js.map +1 -0
  25. package/models/hash-set.js +87 -0
  26. package/models/hash-set.js.map +1 -0
  27. package/models/hash-table.js +122 -0
  28. package/models/hash-table.js.map +1 -0
  29. package/models/key-equality-comparer.js +22 -0
  30. package/models/key-equality-comparer.js.map +1 -0
  31. package/models/key-value-pair.js +16 -0
  32. package/models/key-value-pair.js.map +1 -0
  33. package/models/list.js +121 -0
  34. package/models/list.js.map +1 -0
  35. package/models/ordered-enumerable.js +35 -0
  36. package/models/ordered-enumerable.js.map +1 -0
  37. package/models/queue.js +80 -0
  38. package/models/queue.js.map +1 -0
  39. package/models/read-only-dictionary.js +37 -0
  40. package/models/read-only-dictionary.js.map +1 -0
  41. package/models/read-only-list.js +31 -0
  42. package/models/read-only-list.js.map +1 -0
  43. package/models/read-only-set.js +37 -0
  44. package/models/read-only-set.js.map +1 -0
  45. package/models/sort-entry.js +16 -0
  46. package/models/sort-entry.js.map +1 -0
  47. package/models/stack.js +57 -0
  48. package/models/stack.js.map +1 -0
  49. package/package.json +6 -2
  50. package/resources.js +26 -0
  51. package/resources.js.map +1 -0
  52. package/services/binary-search.service.js +5 -3
  53. package/services/binary-search.service.js.map +1 -1
  54. package/services/comparer.js +48 -0
  55. package/services/comparer.js.map +1 -0
  56. package/services/equality-comparers.js +16 -0
  57. package/services/equality-comparers.js.map +1 -0
  58. package/types/comparison.js +9 -0
  59. package/types/comparison.js.map +1 -0
package/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # noldova.context.collections
2
2
 
3
- Collection algorithms for CONTEXT libraries. Today it holds
4
- `BinarySearchService`, which finds positions in ascending numeric arrays, such
5
- as the line that holds a character offset.
3
+ Collections for CONTEXT libraries and apps, with queries over them:
4
+ `List`, `Dictionary`, `HashSet`, `Queue` and `Stack`, each an `Enumerable` with
5
+ the query operators; read-only views; equality and ordering comparers; and
6
+ `BinarySearchService`, which finds positions in ascending numeric arrays.
6
7
 
7
8
  ## Install
8
9
 
@@ -13,19 +14,46 @@ npm install @noldova/context.collections
13
14
  ## Use
14
15
 
15
16
  ```ts
16
- import { BinarySearchService } from "@noldova/context.collections";
17
-
18
- const lineStarts = [0, 12, 30, 41];
19
-
20
- BinarySearchService.floorIndex(lineStarts, 30); // 2: an exact match.
21
- BinarySearchService.floorIndex(lineStarts, 35); // 2: the nearest lower value is 30.
22
- BinarySearchService.floorIndex(lineStarts, 0); // 0
23
- BinarySearchService.floorIndex([], 5); // -1: no value qualifies.
17
+ import { Enumerable, List } from "@noldova/context.collections";
18
+
19
+ class Account {
20
+ public readonly id: number;
21
+ public readonly name: string;
22
+ public readonly age: number;
23
+ public readonly active: boolean;
24
+
25
+ public constructor(id: number, name: string, age: number, active: boolean) {
26
+ this.id = id;
27
+ this.name = name;
28
+ this.age = age;
29
+ this.active = active;
30
+ }
31
+ }
32
+
33
+ const accounts = new List([
34
+ new Account(1, "Ana", 31, true),
35
+ new Account(2, "Leo", 42, false),
36
+ new Account(3, "Mia", 27, true)
37
+ ]);
38
+
39
+ accounts.where(t => t.active).orderBy(t => t.age).select(t => t.name).toArray(); // ["Mia", "Ana"]
40
+ accounts.firstOrDefault(t => t.age > 50); // undefined
41
+ accounts.first(t => t.age > 50); // throws InvalidOperationException
42
+
43
+ const byId = accounts.toDictionary(t => t.id, t => t);
44
+ byId.get(2).name; // "Leo"
45
+ byId.tryGet(9); // undefined
46
+
47
+ Enumerable.from([3, 1, 2]).orderByDescending(t => t).take(2).toArray(); // [3, 2]
24
48
  ```
25
49
 
26
- The array must be sorted from smallest to greatest; the search does not check
27
- or change it. The declaration file `api/index.d.ts` documents every member with
28
- its contract and examples.
50
+ Arrays stay native: `Enumerable.from` gives any iterable the operators, and
51
+ `new List(array)` copies one into a list. Operators that return a sequence are
52
+ deferred and run again on each enumeration. A method that needs an element
53
+ throws when there is none; its `…OrDefault` or `try…` form returns `undefined`,
54
+ since `undefined` means there is no value and `null` is a value someone set.
55
+ The declaration file `api/index.d.ts` documents every member with its contract
56
+ and examples.
29
57
 
30
58
  ## License
31
59