@@ -17,32 +17,52 @@ A familiar set of functions that operate on JavaScript iterables (ES2015+) in a
17
17
18
18
## API
19
19
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
+
20
24
### Iterating
21
25
22
26
``` typescript
23
- for (const e of linq (source )
24
- .filter (a , b , c )) {
27
+ for (const e of linq (source ).filter (a )) {
25
28
// Iterate filtered results.
26
29
}
27
30
```
28
31
29
32
``` typescript
30
33
for (const e of linq (source )
31
- .filter (a , b , c )
34
+ .filterWith (a , b , c )
32
35
.transform (x )) {
33
36
// Iterate filtered and then transformed results.
34
37
}
35
38
```
36
39
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
+
37
49
### Resolving
38
50
39
51
``` typescript
40
52
const result = linq (source )
41
- .filter (a , b , c )
53
+ .filterWith (a , b , c )
42
54
.transform (x )
43
55
.resolve (r );
44
56
```
45
57
58
+ ``` typescript
59
+ const firstElement = linqExtended (source )
60
+ .where (predicate )
61
+ .select (mapping )
62
+ .first (r );
63
+ ```
64
+
65
+
46
66
## Examples
47
67
48
68
### ` linq<T> ` with imported filters
@@ -65,25 +85,25 @@ for(const o of filtered) {
65
85
}
66
86
```
67
87
68
- ### ` linqExtended <T>` with simplified imports
88
+ ### ` linq <T>` with simplified imports
69
89
70
90
``` typescript
71
- import { linqExtended , iterables , resolutions } from ' @tsdotnet/linq' ;
91
+ import linq , { iterables , resolutions } from ' @tsdotnet/linq' ;
72
92
73
93
const source = iterables .range (1 ,100 ); // Iterable<number>
74
- const result = linqExtended (source )
94
+ const result = linq (source )
75
95
.where (n => n % 2 === 1 ) // odd numbers only
76
96
.resolve (resolutions .sum ); // 2500
77
97
```
78
98
79
99
or
80
100
81
101
``` typescript
82
- import { linqExtended } from ' @tsdotnet/linq' ;
102
+ import linq from ' @tsdotnet/linq' ;
83
103
import {range } from ' @tsdotnet/linq/dist/iterables' ;
84
104
import {sum } from ' @tsdotnet/linq/dist/resolutions' ;
85
105
86
- const source = range (1 ,100 ); // Iterable<number>
106
+ const source = range (1 , 100 ); // Iterable<number>
87
107
const result = linqExtended (source )
88
108
.where (n => n % 2 === 1 ) // odd numbers only
89
109
.resolve (sum ); // 2500
@@ -112,6 +132,7 @@ See the [docs](https://tsdotnet.github.io/linq/) for a full list.
112
132
``` typescript
113
133
linq (source ).filter (a , b );
114
134
linq (source ).filter (a ).filter (b );
135
+ linq (source ).filter (a ).where (predicate );
115
136
```
116
137
117
138
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.
125
146
``` typescript
126
147
linq (source ).transform (x );
127
148
linq (source ).filter (a ).transform (x );
149
+ linq (source ).where (predicate ).transform (x );
150
+ linq (source ).where (predicate ).select (mapping );
128
151
```
129
152
130
153
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.
138
161
### Resolutions
139
162
140
163
``` 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 ();
144
179
```
145
180
146
181
A resolution is a transform that takes an ` Iterable<T> ` and returns ` TResult ` .
0 commit comments