scats 1.0.30 → 1.1.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 +46 -1
- package/coverage/clover.xml +786 -0
- package/coverage/coverage-final.json +10 -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 +231 -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/try.ts.html +923 -0
- package/coverage/lcov-report/util.ts.html +518 -0
- package/coverage/lcov.info +1902 -0
- package/dist/collection.d.ts +55 -17
- package/dist/collection.js +225 -59
- package/dist/hashmap.d.ts +11 -8
- package/dist/hashmap.js +24 -2
- package/dist/hashset.d.ts +7 -6
- package/dist/hashset.js +11 -2
- package/package.json +1 -1
- package/src/collection.ts +279 -71
- package/src/hashmap.ts +45 -9
- package/src/hashset.ts +18 -8
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) {
|
|
@@ -339,3 +339,48 @@ await forComprehension.promise(
|
|
|
339
339
|
).yield(({num1, num2, num3}) => num1 + num2 + num3); // throws Error('Error in task')
|
|
340
340
|
|
|
341
341
|
```
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
## ArrayBuffer
|
|
346
|
+
Represents the mutable collection of items of some type backed by array.
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
import {mutable} from "scats";
|
|
350
|
+
import ArrayBuffer = mutable.ArrayBuffer;
|
|
351
|
+
|
|
352
|
+
const empty = ArrayBuffer.empty; // []
|
|
353
|
+
const example = new ArrayBuffer([1, 2, 3]); // create instance from array
|
|
354
|
+
const example2 = ArrayBuffer.fill(3)(idx => idx + 1); // ArrayBuffer.of(1, 2, 3)
|
|
355
|
+
const c = ArrayBuffer.of(1, 2, 3);
|
|
356
|
+
for (let el of c) {
|
|
357
|
+
console.log(el); // 1, 2, 3
|
|
358
|
+
}
|
|
359
|
+
c.slice(2, 5); // ArrayBuffer.of(3)
|
|
360
|
+
c.map(e => e + 1); // ArrayBuffer.of(2, 3, 4) (new instance)
|
|
361
|
+
ArrayBuffer.of(1, 2).flatMap(x => ArrayBuffer.of(x, x + 1)); // ArrayBuffer.of(1, 2, 2, 3)
|
|
362
|
+
ArrayBuffer.of(1, ArrayBuffer.of(2, 3), 4).flatten<number>(); // ArrayBuffer.of(1, 2, 3, 4)
|
|
363
|
+
ArrayBuffer.of(1, 2, 3).get(1); // 2
|
|
364
|
+
ArrayBuffer.of(1, 2, 3).toArray; // [1, 2, 3]
|
|
365
|
+
ArrayBuffer.of(1, 2, 3).reverse; // ArrayBuffer.of(3, 2, 1)
|
|
366
|
+
ArrayBuffer.of(2, 3, 1).sort((a, b) => a - b); // ArrayBuffer.of(1, 2, 3)
|
|
367
|
+
ArrayBuffer.of({x: 2}, {x: 1}, {x: 3}).sortBy(el => el.x); // ArrayBuffer.of(1, 2, 3)
|
|
368
|
+
ArrayBuffer.of(1, 2).append(3); // ArrayBuffer.of(1, 2, 3) - same instance
|
|
369
|
+
ArrayBuffer.of(1, 2).appended(3); // ArrayBuffer.of(1, 2, 3) - new instance
|
|
370
|
+
ArrayBuffer.of(1, 2).appendAll(ArrayBuffer.of(3, 4)); // ArrayBuffer.of(1, 2, 3, 4) - same instance
|
|
371
|
+
ArrayBuffer.of(1, 2).appendAll([3, 4]); // ArrayBuffer.of(1, 2, 3, 4) - same instance
|
|
372
|
+
ArrayBuffer.of(1, 2).appendedAll(ArrayBuffer.of(3, 4)); // ArrayBuffer.of(1, 2, 3, 4) - new instance
|
|
373
|
+
ArrayBuffer.of(1, 2).prepend(0); // ArrayBuffer.of(0, 1, 2) - same instance
|
|
374
|
+
ArrayBuffer.of(1, 2).prepended(0); // ArrayBuffer.of(0, 1, 2) - new instance
|
|
375
|
+
ArrayBuffer.of(1, 2).prepended(ArrayBuffer.of(-1, 0)); // ArrayBuffer.of(-1, 0, 1, 2) - same instance
|
|
376
|
+
ArrayBuffer.of(1, 2).prependedAll(ArrayBuffer.of(-1, 0)); // ArrayBuffer.of(-1, 0, 1, 2) - new instance
|
|
377
|
+
ArrayBuffer.of(1, 2).concat(ArrayBuffer.of(3, 4)); // ArrayBuffer.of(1, 2, 3, 4)
|
|
378
|
+
ArrayBuffer.of(1, 2, 2).toSet; // HashSet.of(1, 2)
|
|
379
|
+
ArrayBuffer.of(1, 2, 2).distinct; // ArrayBuffer.of(1, 2) - new instance
|
|
380
|
+
ArrayBuffer.of({x: 2}, {x: 1}, {x: 2}).distinctBy(el => el.x); // ArrayBuffer.of({x: 2}, {x: 1}) - new instance
|
|
381
|
+
ArrayBuffer.of({id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}).toMap(el => [el.id, el.name]); // HashMap(1 -> 'Alice', 2 -> 'Bob')
|
|
382
|
+
c.sum(identity); // 6. We have to provide identity to convert element to number
|
|
383
|
+
c.take(2); // Collection.of(1, 2)
|
|
384
|
+
c.drop(1); // Collection.of(2, 3);
|
|
385
|
+
c.head; // 1
|
|
386
|
+
```
|