scats 1.0.32 → 1.2.0
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 +82 -3
- package/coverage/clover.xml +937 -0
- package/coverage/coverage-final.json +15 -0
- package/coverage/lcov-report/array-iterable.ts.html +1709 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/collection.ts.html +1475 -0
- package/coverage/lcov-report/either.ts.html +1934 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/hashmap.ts.html +527 -0
- package/coverage/lcov-report/hashset.ts.html +392 -0
- package/coverage/lcov-report/index.html +126 -0
- package/coverage/lcov-report/index.ts.html +101 -0
- package/coverage/lcov-report/option.ts.html +758 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov-report/src/abstract-map.ts.html +317 -0
- package/coverage/lcov-report/src/abstract-set.ts.html +200 -0
- package/coverage/lcov-report/src/array-iterable.ts.html +1751 -0
- package/coverage/lcov-report/src/collection.ts.html +1778 -0
- package/coverage/lcov-report/src/either.ts.html +1934 -0
- package/coverage/lcov-report/src/hashmap.ts.html +428 -0
- package/coverage/lcov-report/src/hashset.ts.html +482 -0
- package/coverage/lcov-report/src/index.html +276 -0
- package/coverage/lcov-report/src/index.ts.html +110 -0
- package/coverage/lcov-report/src/mutable/hashmap.ts.html +821 -0
- package/coverage/lcov-report/src/mutable/hashset.ts.html +611 -0
- package/coverage/lcov-report/src/mutable/index.html +126 -0
- package/coverage/lcov-report/src/mutable.ts.html +89 -0
- package/coverage/lcov-report/src/option.ts.html +758 -0
- package/coverage/lcov-report/src/try.ts.html +923 -0
- package/coverage/lcov-report/src/util.ts.html +518 -0
- package/coverage/lcov-report/try.ts.html +923 -0
- package/coverage/lcov-report/util.ts.html +518 -0
- package/coverage/lcov.info +2223 -0
- package/dist/abstract-map.d.ts +25 -0
- package/dist/abstract-map.js +62 -0
- package/dist/abstract-set.d.ts +13 -0
- package/dist/abstract-set.js +33 -0
- package/dist/array-iterable.d.ts +1 -3
- package/dist/array-iterable.js +21 -23
- package/dist/collection.d.ts +59 -20
- package/dist/collection.js +254 -62
- package/dist/hashmap.d.ts +12 -26
- package/dist/hashmap.js +39 -58
- package/dist/hashset.d.ts +12 -17
- package/dist/hashset.js +25 -35
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/mutable/hashmap.d.ts +24 -0
- package/dist/mutable/hashmap.js +118 -0
- package/dist/mutable/hashset.d.ts +20 -0
- package/dist/mutable/hashset.js +88 -0
- package/dist/mutable.d.ts +3 -0
- package/dist/mutable.js +9 -0
- package/dist/option.js +1 -1
- package/package.json +12 -12
- package/src/abstract-map.ts +79 -0
- package/src/abstract-set.ts +40 -0
- package/src/array-iterable.ts +26 -12
- package/src/collection.ts +394 -85
- package/src/either.ts +2 -2
- package/src/hashmap.ts +74 -73
- package/src/hashset.ts +82 -42
- package/src/index.ts +3 -0
- package/src/mutable/hashmap.ts +247 -0
- package/src/mutable/hashset.ts +177 -0
- package/src/mutable.ts +3 -0
- package/src/option.ts +2 -2
- package/src/try.ts +9 -9
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ import {Collection, Nil} from "scats";
|
|
|
16
16
|
|
|
17
17
|
const empty = Collection.empty; // empty collection
|
|
18
18
|
const empty2 = Nil; // empty collection
|
|
19
|
-
const example = new Collection([1, 2, 3]); // create instance from
|
|
19
|
+
const example = new Collection([1, 2, 3]); // create instance from array
|
|
20
20
|
const example2 = Collection.fill(3)(idx => idx + 1); // Collection.of(1, 2, 3)
|
|
21
21
|
const c = Collection.of(1, 2, 3);
|
|
22
22
|
for (let el of c) {
|
|
@@ -218,7 +218,6 @@ map.size; // 1
|
|
|
218
218
|
map.isEmpty; // false
|
|
219
219
|
HashMap.empty.isEmpty; // true
|
|
220
220
|
map.nonEmpty; // true
|
|
221
|
-
map.nonEmpty; // true
|
|
222
221
|
map.get('1'); // some(1)
|
|
223
222
|
map.get('5'); // none
|
|
224
223
|
map.getOrElse('1', () => 5); // 1
|
|
@@ -229,7 +228,7 @@ map.values; // Collection.of(1, 2)
|
|
|
229
228
|
map.entries; // Collection.of(['1', 1], ['2', 2])
|
|
230
229
|
map.appendedAll(HashMap.of(['3', 3])); // HashMap.of(['1', 1], ['2', 2], ['3', 3])
|
|
231
230
|
map.set('2', 3); // HashMap.of(['1', 1], ['2', 3])
|
|
232
|
-
map.
|
|
231
|
+
map.removed('2'); // HashMap.of(['1', 1])
|
|
233
232
|
map.updated('2', 4); // HashMap.of(['1', 1], ['2', 4])
|
|
234
233
|
```
|
|
235
234
|
|
|
@@ -339,3 +338,83 @@ await forComprehension.promise(
|
|
|
339
338
|
).yield(({num1, num2, num3}) => num1 + num2 + num3); // throws Error('Error in task')
|
|
340
339
|
|
|
341
340
|
```
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
## ArrayBuffer
|
|
345
|
+
Represents the mutable collection of items of some type backed by array.
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
import {mutable} from "scats";
|
|
349
|
+
import ArrayBuffer = mutable.ArrayBuffer;
|
|
350
|
+
|
|
351
|
+
const empty = ArrayBuffer.empty; // []
|
|
352
|
+
const example = new ArrayBuffer([1, 2, 3]); // create instance from array
|
|
353
|
+
const example2 = ArrayBuffer.fill(3)(idx => idx + 1); // ArrayBuffer.of(1, 2, 3)
|
|
354
|
+
const c = ArrayBuffer.of(1, 2, 3);
|
|
355
|
+
for (let el of c) {
|
|
356
|
+
console.log(el); // 1, 2, 3
|
|
357
|
+
}
|
|
358
|
+
c.slice(2, 5); // ArrayBuffer.of(3)
|
|
359
|
+
c.map(e => e + 1); // ArrayBuffer.of(2, 3, 4) (new instance)
|
|
360
|
+
ArrayBuffer.of(1, 2).flatMap(x => ArrayBuffer.of(x, x + 1)); // ArrayBuffer.of(1, 2, 2, 3)
|
|
361
|
+
ArrayBuffer.of(1, ArrayBuffer.of(2, 3), 4).flatten<number>(); // ArrayBuffer.of(1, 2, 3, 4)
|
|
362
|
+
ArrayBuffer.of(1, 2, 3).get(1); // 2
|
|
363
|
+
ArrayBuffer.of(1, 2, 3).toArray; // [1, 2, 3]
|
|
364
|
+
ArrayBuffer.of(1, 2, 3).reverse; // ArrayBuffer.of(3, 2, 1)
|
|
365
|
+
ArrayBuffer.of(2, 3, 1).sort((a, b) => a - b); // ArrayBuffer.of(1, 2, 3)
|
|
366
|
+
ArrayBuffer.of({x: 2}, {x: 1}, {x: 3}).sortBy(el => el.x); // ArrayBuffer.of(1, 2, 3)
|
|
367
|
+
ArrayBuffer.of(1, 2).append(3); // ArrayBuffer.of(1, 2, 3) - same instance
|
|
368
|
+
ArrayBuffer.of(1, 2).appended(3); // ArrayBuffer.of(1, 2, 3) - new instance
|
|
369
|
+
ArrayBuffer.of(1, 2).appendAll(ArrayBuffer.of(3, 4)); // ArrayBuffer.of(1, 2, 3, 4) - same instance
|
|
370
|
+
ArrayBuffer.of(1, 2).appendAll([3, 4]); // ArrayBuffer.of(1, 2, 3, 4) - same instance
|
|
371
|
+
ArrayBuffer.of(1, 2).appendedAll(ArrayBuffer.of(3, 4)); // ArrayBuffer.of(1, 2, 3, 4) - new instance
|
|
372
|
+
ArrayBuffer.of(1, 2).prepend(0); // ArrayBuffer.of(0, 1, 2) - same instance
|
|
373
|
+
ArrayBuffer.of(1, 2).prepended(0); // ArrayBuffer.of(0, 1, 2) - new instance
|
|
374
|
+
ArrayBuffer.of(1, 2).prepended(ArrayBuffer.of(-1, 0)); // ArrayBuffer.of(-1, 0, 1, 2) - same instance
|
|
375
|
+
ArrayBuffer.of(1, 2).prependedAll(ArrayBuffer.of(-1, 0)); // ArrayBuffer.of(-1, 0, 1, 2) - new instance
|
|
376
|
+
ArrayBuffer.of(1, 2).concat(ArrayBuffer.of(3, 4)); // ArrayBuffer.of(1, 2, 3, 4)
|
|
377
|
+
ArrayBuffer.of(1, 2, 2).toSet; // HashSet.of(1, 2)
|
|
378
|
+
ArrayBuffer.of(1, 2, 2).distinct; // ArrayBuffer.of(1, 2) - new instance
|
|
379
|
+
ArrayBuffer.of({x: 2}, {x: 1}, {x: 2}).distinctBy(el => el.x); // ArrayBuffer.of({x: 2}, {x: 1}) - new instance
|
|
380
|
+
ArrayBuffer.of({id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}).toMap(el => [el.id, el.name]); // HashMap(1 -> 'Alice', 2 -> 'Bob')
|
|
381
|
+
c.sum(identity); // 6. We have to provide identity to convert element to number
|
|
382
|
+
c.take(2); // Collection.of(1, 2)
|
|
383
|
+
c.drop(1); // Collection.of(2, 3);
|
|
384
|
+
c.head; // 1
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
## mutable.HashMap
|
|
389
|
+
```typescript
|
|
390
|
+
import {mutable} from "scats";
|
|
391
|
+
|
|
392
|
+
const map = new mutable.HashMap<string, number>()
|
|
393
|
+
map.set('Alice', 11); // ('Alice' -> 11)
|
|
394
|
+
map.set('Bob', 12); // ('Alice' -> 11, 'Bob' -> 12)
|
|
395
|
+
map.clear(); // ()
|
|
396
|
+
map.put('Steve', 14); // returns some(14), map: ('Steve' -> 14)
|
|
397
|
+
map.update('Alice', 11); // ('Steve' -> 14, 'Alice' -> 11)
|
|
398
|
+
map.remove('Alice'); // ('Steve' -> 14)
|
|
399
|
+
map.addOne(['Bob', 12]); // ('Steve' -> 14, 'Bob' -> 12)
|
|
400
|
+
map.subtractOne('Bob'); // ('Steve' -> 14)
|
|
401
|
+
map.addAll([['Alice', 11], ['Bob', 12]]); // ('Steve' -> 14, 'Alice' -> 11, 'Bob' -> 12)
|
|
402
|
+
map.mapValuesInPlace(([name, age]) => age + 1); // ('Steve' -> 15, 'Alice' -> 12, 'Bob' -> 13)
|
|
403
|
+
map.filterInPlace(([name, age]) => age > 13); // ('Steve' -> 15)
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
## mutable.HashSet
|
|
408
|
+
```typescript
|
|
409
|
+
import {mutable} from "scats";
|
|
410
|
+
|
|
411
|
+
const set = new mutable.HashSet<string, number>()
|
|
412
|
+
set.add(1); // true. set = [1]
|
|
413
|
+
set.add(1); // false. set = [1]
|
|
414
|
+
set.clear(); // []]
|
|
415
|
+
set.add(1); // true. set = [1]
|
|
416
|
+
set.remove(2); false. set = [1]
|
|
417
|
+
set.remove(1); true. set = []
|
|
418
|
+
set.addAll([2, 3]); set = [1, 2, 3]
|
|
419
|
+
set.filterInPlace(x => x > 2); // [3]
|
|
420
|
+
```
|