Skip to content

Commit 2066ecd

Browse files
committed
refactor: improve performance of sync iterables
1 parent 2bb2526 commit 2066ecd

21 files changed

+528
-436
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ etc/
7676
.github/
7777

7878
# Tests
79-
dist/tests/
79+
dist/mjs/tests/
80+
dist/cjs/tests/

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Changed:
1717
- Improved types of `toObject` and `toMap` methods
18-
- Add an `options` argument to `PolyAsyncIterable#complete`
19-
- Add an `options` argument to `PolyAsyncIterable#join`
18+
- Added an `options` argument to `PolyAsyncIterable#complete`
19+
- Added an `options` argument to `PolyAsyncIterable#join`
20+
- Improved performance of `PolySyncIterable#map` and `PolySyncIterable#filter`
2021

2122

2223
## [2.3.0] - 2023-03-16

docs/polyethylene.baseimpls.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [polyethylene](./polyethylene.md) &gt; [baseImpls](./polyethylene.baseimpls.md)
4+
5+
## baseImpls variable
6+
7+
**Signature:**
8+
9+
```typescript
10+
baseImpls: BaseImpls
11+
```

docs/polyethylene.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ The entry point for this library is the [Poly](./polyethylene.poly.md) namespace
1616
| --- | --- |
1717
| [AsyncIterableBuilder](./polyethylene.asynciterablebuilder.md) | <p>A class that helps with building an [AsyncIterable](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator) from a non-structured source.</p><p>In order to create the iteration, you must call the [value](./polyethylene.asynciterablebuilder.value.md)<!-- -->, [error](./polyethylene.asynciterablebuilder.error.md) and [done](./polyethylene.asynciterablebuilder.done.md) methods with appropriate arguments.</p> |
1818
| [PolyAsyncIterable](./polyethylene.polyasynciterable.md) | <p>An <code>AsyncIterable&lt;T&gt;</code> with a suite of methods for transforming the iteration into other iterations or to get a single result from it.</p><p>This class works as an async version of [PolySyncIterable](./polyethylene.polysynciterable.md)<!-- -->, but all methods accept async function where possible and will always return either <code>PolyAsyncIterables</code> or a <code>Promise</code> to a value.</p><p>\#\# Concurrency Many operations of this class accept as a final argument an [options object](./polyethylene.concurrencyoptions.md) than can specify some options for concurrent operations.</p><p>- The <code>concurrency</code> option will specify how many times whatever <code>func</code> you pass is called before waiting for its results. Effectively, this is the number of promises that can be pending at the same time. If not specified, it will default to 0, meaning no concurrency. Must be a non-negative integer. - The <code>bufferSize</code> option will specify the size of the internal buffer used to store the pending and completed promises. Effectively, this is how many results will be prefetched. If not specified, it will default to <code>concurrency</code>, meaning no extra intermediate results are stored. Must be a positive integer greater or equal to <code>concurrency</code>.</p><p>A concurrency value of 0 acts the same as a 1 concurrency-wise, but disables the concurrency completely, preventing any values to be requested before actually needed.</p><p>Specifying concurrency greater or equal to 1 will make more elements be requested of the previous iterator than actually requested of the current one, similarly to [PolyAsyncIterable.prefetch()](./polyethylene.polyasynciterable.prefetch.md)<!-- -->.</p> |
19+
20+
## Abstract Classes
21+
22+
| Abstract Class | Description |
23+
| --- | --- |
1924
| [PolySyncIterable](./polyethylene.polysynciterable.md) | <p>A <code>SyncIterable&lt;T&gt;</code> with a suite of methods for transforming the iteration into other iterations or to get a single result from it.</p><p>The methods of this class are intended to resemble those of <code>Array</code>, with added utilities where appropriate and made for any kind of iterable.</p> |
2025

2126
## Interfaces
@@ -30,6 +35,12 @@ The entry point for this library is the [Poly](./polyethylene.poly.md) namespace
3035
| --- | --- |
3136
| [Poly](./polyethylene.poly.md) | Main namespace for the creation of [PolySyncIterable](./polyethylene.polysynciterable.md) and [PolyAsyncIterable](./polyethylene.polyasynciterable.md) objects. |
3237

38+
## Variables
39+
40+
| Variable | Description |
41+
| --- | --- |
42+
| [baseImpls](./polyethylene.baseimpls.md) | |
43+
3344
## Type Aliases
3445

3546
| Type Alias | Description |

docs/polyethylene.polysynciterable._symbol.iterator_.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ Allows this class to work as a regular `Iterable<T>`
99
**Signature:**
1010

1111
```typescript
12-
[Symbol.iterator](): Iterator<T, void, undefined>;
12+
abstract [Symbol.iterator](): Iterator<T>;
1313
```
1414
**Returns:**
1515

16-
Iterator&lt;T, void, undefined&gt;
16+
Iterator&lt;T&gt;
1717

1818
an iterable that will yield the same elements as the iterable used to create this instance
1919

docs/polyethylene.polysynciterable.indexof.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/polyethylene.polysynciterable.lastindexof.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/polyethylene.polysynciterable.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@ The methods of this class are intended to resemble those of `Array`<!-- -->, wit
1111
**Signature:**
1212

1313
```typescript
14-
export default class PolySyncIterable<T> implements Iterable<T>
14+
export default abstract class PolySyncIterable<T> implements Iterable<T>
1515
```
1616
**Implements:** Iterable&lt;T&gt;
1717
18-
## Remarks
19-
20-
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `PolySyncIterable` class.
21-
2218
## Methods
2319
2420
| Method | Modifiers | Description |
2521
| --- | --- | --- |
26-
| [\[Symbol.iterator\]()](./polyethylene.polysynciterable._symbol.iterator_.md) | | Allows this class to work as a regular <code>Iterable&lt;T&gt;</code> |
22+
| [\[Symbol.iterator\]()](./polyethylene.polysynciterable._symbol.iterator_.md) | <code>abstract</code> | Allows this class to work as a regular <code>Iterable&lt;T&gt;</code> |
2723
| [append(other)](./polyethylene.polysynciterable.append.md) | | Return a new iteration that will iterate over <code>this</code>, then over <code>other</code>. |
2824
| [async()](./polyethylene.polysynciterable.async.md) | | Return an async version of this same iteration. |
2925
| [chunk(num)](./polyethylene.polysynciterable.chunk.md) | | Return an iteration of arrays of size <code>num</code> (except possibly the last) containing groupings of elements of <code>this</code> iteration. |
@@ -51,9 +47,7 @@ The constructor for this class is marked as internal. Third-party code should no
5147
| [forEach(func)](./polyethylene.polysynciterable.foreach.md) | | Call a function for each element of <code>this</code> iteration. |
5248
| [groupBy(func)](./polyethylene.polysynciterable.groupby.md) | | Return an iteration of group pairs, where the first element is a \_group key\_ and the second is an iterable of all the elements for which <code>func(element)</code> returned the key. |
5349
| [includes(obj)](./polyethylene.polysynciterable.includes.md) | | Returns whether an element is present in this iteration. |
54-
| [indexOf(func)](./polyethylene.polysynciterable.indexof.md) | | |
5550
| [join(glue)](./polyethylene.polysynciterable.join.md) | | Return the result of joining the elements of <code>this</code> with the given <code>glue</code>, or <code>','</code> if no glue is given. |
56-
| [lastIndexOf(func)](./polyethylene.polysynciterable.lastindexof.md) | | |
5751
| [map(func)](./polyethylene.polysynciterable.map.md) | | Return an iteration of the result of calling <code>func(element)</code> for every element in <code>this</code>. |
5852
| [mapKeys(this, func)](./polyethylene.polysynciterable.mapkeys.md) | | Return an iteration of the pairs resulting of calling <code>func(element)</code> for every element in <code>this</code> and using it as the first element of the pair (the \*key\*) and preserving the second (the \*value\*). |
5953
| [mapValues(this, func)](./polyethylene.polysynciterable.mapvalues.md) | | Return an iteration of the pairs resulting of calling <code>func(element)</code> for every element in <code>this</code> and using it as the second element of the pair (the \*value\*) and preserving the first (the \*key\*). |

etc/polyethylene.api.json

Lines changed: 32 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"toolPackage": "@microsoft/api-extractor",
4-
"toolVersion": "7.38.2",
4+
"toolVersion": "7.39.0",
55
"schemaVersion": 1011,
66
"oldestForwardsCompatibleVersion": 1001,
77
"tsdocConfig": {
@@ -693,6 +693,30 @@
693693
}
694694
]
695695
},
696+
{
697+
"kind": "Variable",
698+
"canonicalReference": "polyethylene!baseImpls:var",
699+
"docComment": "",
700+
"excerptTokens": [
701+
{
702+
"kind": "Content",
703+
"text": "baseImpls: "
704+
},
705+
{
706+
"kind": "Reference",
707+
"text": "BaseImpls",
708+
"canonicalReference": "polyethylene!~BaseImpls:interface"
709+
}
710+
],
711+
"fileUrlPath": "src/lib/sync/poly-sync-iterable.ts",
712+
"isReadonly": true,
713+
"releaseTag": "Public",
714+
"name": "baseImpls",
715+
"variableTypeTokenRange": {
716+
"startIndex": 1,
717+
"endIndex": 2
718+
}
719+
},
696720
{
697721
"kind": "TypeAlias",
698722
"canonicalReference": "polyethylene!ChunkingPredicate:type",
@@ -6408,11 +6432,11 @@
64086432
{
64096433
"kind": "Class",
64106434
"canonicalReference": "polyethylene!PolySyncIterable:class",
6411-
"docComment": "/**\n * A `SyncIterable<T>` with a suite of methods for transforming the iteration into other iterations or to get a single result from it.\n *\n * The methods of this class are intended to resemble those of `Array`, with added utilities where appropriate and made for any kind of iterable.\n *\n * @remarks\n *\n * The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `PolySyncIterable` class.\n *\n * @public\n */\n",
6435+
"docComment": "/**\n * A `SyncIterable<T>` with a suite of methods for transforming the iteration into other iterations or to get a single result from it.\n *\n * The methods of this class are intended to resemble those of `Array`, with added utilities where appropriate and made for any kind of iterable.\n *\n * @public\n */\n",
64126436
"excerptTokens": [
64136437
{
64146438
"kind": "Content",
6415-
"text": "export default class PolySyncIterable<T> implements "
6439+
"text": "export default abstract class PolySyncIterable<T> implements "
64166440
},
64176441
{
64186442
"kind": "Reference",
@@ -6428,7 +6452,7 @@
64286452
"text": " "
64296453
}
64306454
],
6431-
"fileUrlPath": "src/lib/sync/poly-iterable.ts",
6455+
"fileUrlPath": "src/lib/sync/poly-sync-iterable.ts",
64326456
"releaseTag": "Public",
64336457
"typeParameters": [
64346458
{
@@ -6443,7 +6467,7 @@
64436467
}
64446468
}
64456469
],
6446-
"isAbstract": false,
6470+
"isAbstract": true,
64476471
"name": "PolySyncIterable",
64486472
"preserveMemberOrder": false,
64496473
"members": [
@@ -6454,7 +6478,7 @@
64546478
"excerptTokens": [
64556479
{
64566480
"kind": "Content",
6457-
"text": "["
6481+
"text": "abstract ["
64586482
},
64596483
{
64606484
"kind": "Reference",
@@ -6472,7 +6496,7 @@
64726496
},
64736497
{
64746498
"kind": "Content",
6475-
"text": "<T, void, undefined>"
6499+
"text": "<T>"
64766500
},
64776501
{
64786502
"kind": "Content",
@@ -6489,7 +6513,7 @@
64896513
"overloadIndex": 1,
64906514
"parameters": [],
64916515
"isOptional": false,
6492-
"isAbstract": false,
6516+
"isAbstract": true,
64936517
"name": "[Symbol.iterator]"
64946518
},
64956519
{
@@ -8124,59 +8148,6 @@
81248148
"isAbstract": false,
81258149
"name": "includes"
81268150
},
8127-
{
8128-
"kind": "Method",
8129-
"canonicalReference": "polyethylene!PolySyncIterable#indexOf:member(1)",
8130-
"docComment": "",
8131-
"excerptTokens": [
8132-
{
8133-
"kind": "Content",
8134-
"text": "indexOf(func: "
8135-
},
8136-
{
8137-
"kind": "Reference",
8138-
"text": "IndexedPredicate",
8139-
"canonicalReference": "polyethylene!IndexedPredicate:type"
8140-
},
8141-
{
8142-
"kind": "Content",
8143-
"text": "<T>"
8144-
},
8145-
{
8146-
"kind": "Content",
8147-
"text": "): "
8148-
},
8149-
{
8150-
"kind": "Content",
8151-
"text": "number"
8152-
},
8153-
{
8154-
"kind": "Content",
8155-
"text": ";"
8156-
}
8157-
],
8158-
"isStatic": false,
8159-
"returnTypeTokenRange": {
8160-
"startIndex": 4,
8161-
"endIndex": 5
8162-
},
8163-
"releaseTag": "Public",
8164-
"isProtected": false,
8165-
"overloadIndex": 1,
8166-
"parameters": [
8167-
{
8168-
"parameterName": "func",
8169-
"parameterTypeTokenRange": {
8170-
"startIndex": 1,
8171-
"endIndex": 3
8172-
},
8173-
"isOptional": false
8174-
}
8175-
],
8176-
"isOptional": false,
8177-
"isAbstract": false,
8178-
"name": "indexOf"
8179-
},
81808151
{
81818152
"kind": "Method",
81828153
"canonicalReference": "polyethylene!PolySyncIterable#join:member(1)",
@@ -8225,59 +8196,6 @@
82258196
"isAbstract": false,
82268197
"name": "join"
82278198
},
8228-
{
8229-
"kind": "Method",
8230-
"canonicalReference": "polyethylene!PolySyncIterable#lastIndexOf:member(1)",
8231-
"docComment": "",
8232-
"excerptTokens": [
8233-
{
8234-
"kind": "Content",
8235-
"text": "lastIndexOf(func: "
8236-
},
8237-
{
8238-
"kind": "Reference",
8239-
"text": "IndexedPredicate",
8240-
"canonicalReference": "polyethylene!IndexedPredicate:type"
8241-
},
8242-
{
8243-
"kind": "Content",
8244-
"text": "<T>"
8245-
},
8246-
{
8247-
"kind": "Content",
8248-
"text": "): "
8249-
},
8250-
{
8251-
"kind": "Content",
8252-
"text": "number"
8253-
},
8254-
{
8255-
"kind": "Content",
8256-
"text": ";"
8257-
}
8258-
],
8259-
"isStatic": false,
8260-
"returnTypeTokenRange": {
8261-
"startIndex": 4,
8262-
"endIndex": 5
8263-
},
8264-
"releaseTag": "Public",
8265-
"isProtected": false,
8266-
"overloadIndex": 1,
8267-
"parameters": [
8268-
{
8269-
"parameterName": "func",
8270-
"parameterTypeTokenRange": {
8271-
"startIndex": 1,
8272-
"endIndex": 3
8273-
},
8274-
"isOptional": false
8275-
}
8276-
],
8277-
"isOptional": false,
8278-
"isAbstract": false,
8279-
"name": "lastIndexOf"
8280-
},
82818199
{
82828200
"kind": "Method",
82838201
"canonicalReference": "polyethylene!PolySyncIterable#map:member(1)",

0 commit comments

Comments
 (0)