@noldova/context.collections 0.0.10 → 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.
- package/README.md +42 -14
- package/api/index.d.ts +1479 -0
- package/api/index.js +17 -0
- package/api/index.js.map +1 -1
- package/extensions/enumerable.extensions.js +36 -0
- package/extensions/enumerable.extensions.js.map +1 -0
- package/interfaces/i-equality-comparer.js +9 -0
- package/interfaces/i-equality-comparer.js.map +1 -0
- package/interfaces/i-read-only-dictionary.js +9 -0
- package/interfaces/i-read-only-dictionary.js.map +1 -0
- package/interfaces/i-read-only-list.js +9 -0
- package/interfaces/i-read-only-list.js.map +1 -0
- package/interfaces/i-read-only-set.js +9 -0
- package/interfaces/i-read-only-set.js.map +1 -0
- package/models/change-counter.js +23 -0
- package/models/change-counter.js.map +1 -0
- package/models/default-equality-comparer.js +35 -0
- package/models/default-equality-comparer.js.map +1 -0
- package/models/dictionary.js +74 -0
- package/models/dictionary.js.map +1 -0
- package/models/enumerable.js +399 -0
- package/models/enumerable.js.map +1 -0
- package/models/grouping.js +21 -0
- package/models/grouping.js.map +1 -0
- package/models/hash-set.js +87 -0
- package/models/hash-set.js.map +1 -0
- package/models/hash-table.js +122 -0
- package/models/hash-table.js.map +1 -0
- package/models/key-equality-comparer.js +22 -0
- package/models/key-equality-comparer.js.map +1 -0
- package/models/key-value-pair.js +16 -0
- package/models/key-value-pair.js.map +1 -0
- package/models/list.js +121 -0
- package/models/list.js.map +1 -0
- package/models/ordered-enumerable.js +35 -0
- package/models/ordered-enumerable.js.map +1 -0
- package/models/queue.js +80 -0
- package/models/queue.js.map +1 -0
- package/models/read-only-dictionary.js +37 -0
- package/models/read-only-dictionary.js.map +1 -0
- package/models/read-only-list.js +31 -0
- package/models/read-only-list.js.map +1 -0
- package/models/read-only-set.js +37 -0
- package/models/read-only-set.js.map +1 -0
- package/models/sort-entry.js +16 -0
- package/models/sort-entry.js.map +1 -0
- package/models/stack.js +57 -0
- package/models/stack.js.map +1 -0
- package/package.json +6 -2
- package/resources.js +26 -0
- package/resources.js.map +1 -0
- package/services/binary-search.service.js +5 -3
- package/services/binary-search.service.js.map +1 -1
- package/services/comparer.js +48 -0
- package/services/comparer.js.map +1 -0
- package/services/equality-comparers.js +16 -0
- package/services/equality-comparers.js.map +1 -0
- package/types/comparison.js +9 -0
- package/types/comparison.js.map +1 -0
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# noldova.context.collections
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
`
|
|
5
|
-
|
|
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 {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|