Skip to content

Commit 4fd3016

Browse files
Improved features and flexibility.
1 parent 45a5e5d commit 4fd3016

32 files changed

+2237
-2051
lines changed

.vscode/settings.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
{
22
"cSpell.words": [
33
"camelcase",
4+
"copyfiles",
45
"electricessence",
6+
"Enumerables",
57
"Linq",
6-
"tsdotnet"
8+
"pnpm",
9+
"postversion",
10+
"precommit",
11+
"preversion",
12+
"tsdotnet",
13+
"typedoc",
14+
"xyxyxy",
15+
"xyzxyzxyz"
716
]
817
}

README.md

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,52 @@ A familiar set of functions that operate on JavaScript iterables (ES2015+) in a
1717

1818
## API
1919

20+
### `linq<T>` vs `linqExtended<T>`
21+
22+
It is possible to do everything with just `linq` but `linqExtended` offers more functionality for those expecting to use common resolutions like `.count`, `.first`, `.last`, etc. Using `linq` will save you some bytes when your common use cases do not need resolutions.
23+
2024
### Iterating
2125

2226
```typescript
23-
for(const e of linq(source)
24-
.filter(a, b, c)) {
27+
for(const e of linq(source).filter(a)) {
2528
// Iterate filtered results.
2629
}
2730
```
2831

2932
```typescript
3033
for(const e of linq(source)
31-
.filter(a, b, c)
34+
.filterWith(a, b, c)
3235
.transform(x)) {
3336
// Iterate filtered and then transformed results.
3437
}
3538
```
3639

40+
```typescript
41+
for(const e of linq(source)
42+
.where(predicate)
43+
.skip(10).take(10)
44+
.select(mapping)) {
45+
// Iterate filtered and mapped results.
46+
}
47+
```
48+
3749
### Resolving
3850

3951
```typescript
4052
const result = linq(source)
41-
.filter(a, b, c)
53+
.filterWith(a, b, c)
4254
.transform(x)
4355
.resolve(r);
4456
```
4557

58+
```typescript
59+
const firstElement = linqExtended(source)
60+
.where(predicate)
61+
.select(mapping)
62+
.first(r);
63+
```
64+
65+
4666
## Examples
4767

4868
### `linq<T>` with imported filters
@@ -65,25 +85,25 @@ for(const o of filtered) {
6585
}
6686
```
6787

68-
### `linqExtended<T>` with simplified imports
88+
### `linq<T>` with simplified imports
6989

7090
```typescript
71-
import {linqExtended, iterables, resolutions} from '@tsdotnet/linq';
91+
import linq, {iterables, resolutions} from '@tsdotnet/linq';
7292

7393
const source = iterables.range(1,100); // Iterable<number>
74-
const result = linqExtended(source)
94+
const result = linq(source)
7595
.where(n => n%2===1) // odd numbers only
7696
.resolve(resolutions.sum); // 2500
7797
```
7898

7999
or
80100

81101
```typescript
82-
import {linqExtended} from '@tsdotnet/linq';
102+
import linq from '@tsdotnet/linq';
83103
import {range} from '@tsdotnet/linq/dist/iterables';
84104
import {sum} from '@tsdotnet/linq/dist/resolutions';
85105

86-
const source = range(1,100); // Iterable<number>
106+
const source = range(1, 100); // Iterable<number>
87107
const result = linqExtended(source)
88108
.where(n => n%2===1) // odd numbers only
89109
.resolve(sum); // 2500
@@ -112,6 +132,7 @@ See the [docs](https://tsdotnet.github.io/linq/) for a full list.
112132
```typescript
113133
linq(source).filter(a, b);
114134
linq(source).filter(a).filter(b);
135+
linq(source).filter(a).where(predicate);
115136
```
116137

117138
Any function that receives an `Iterable<T>` and returns an `Iterable<T>` is considered an
@@ -125,6 +146,8 @@ See the [docs](https://tsdotnet.github.io/linq/) for a full list.
125146
```typescript
126147
linq(source).transform(x);
127148
linq(source).filter(a).transform(x);
149+
linq(source).where(predicate).transform(x);
150+
linq(source).where(predicate).select(mapping);
128151
```
129152

130153
Any function that receives an `Iterable<T>` and returns an `Iterable<TResult>` is considered an
@@ -138,9 +161,21 @@ See the [docs](https://tsdotnet.github.io/linq/) for a full list.
138161
### Resolutions
139162

140163
```typescript
141-
linq(source).resolve(r);
142-
linq(source).transform(x).resolve(r);
143-
linq(source).filter(a, b).transform(x).resolve(r);
164+
sequence = linq(source);
165+
166+
sequence.resolve(r);
167+
sequence.transform(x).resolve(r);
168+
sequence.filter(a).transform(x).resolve(r);
169+
sequence.where(predicate).resolve(r);
170+
sequence.filterWith(a, b).transform(x).resolve(r);
171+
```
172+
173+
```typescript
174+
sequence = linqExtended(source);
175+
176+
sequence.any();
177+
sequence.first();
178+
sequence.singleOrDefault();
144179
```
145180

146181
A resolution is a transform that takes an `Iterable<T>` and returns `TResult`.

dist-esm/LinqBase.js

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist-esm/LinqBase.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist-esm/LinqResolverBase.js

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist-esm/LinqResolverBase.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist-esm/filters/memoize.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist-esm/filters/memoize.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)