iterflow 0.2.2

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/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org/>
package/README.md ADDED
@@ -0,0 +1,228 @@
1
+ # iterflow
2
+
3
+ Iterator utilities for ES2022+ with statistical operations, windowing, and lazy evaluation.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/iterflow.svg)](https://www.npmjs.com/package/iterflow)
6
+ [![License: Unlicense](https://img.shields.io/badge/License-Unlicense-blue.svg)](https://unlicense.org/)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install iterflow
12
+ ```
13
+
14
+ ## Quick Start
15
+
16
+ ```typescript
17
+ import { iter } from 'iterflow';
18
+
19
+ // Statistical operations
20
+ iter([1, 2, 3, 4, 5]).mean(); // 3
21
+ iter([1, 2, 3, 4, 5]).median(); // 3
22
+
23
+ // Windowing
24
+ iter([1, 2, 3, 4, 5])
25
+ .window(2)
26
+ .toArray();
27
+ // [[1,2], [2,3], [3,4], [4,5]]
28
+
29
+ // Method chaining
30
+ iter([1, 2, 3, 4, 5, 6])
31
+ .filter(x => x % 2 === 0)
32
+ .map(x => x * 2)
33
+ .chunk(2)
34
+ .toArray();
35
+ // [[4, 8], [12]]
36
+ ```
37
+
38
+ ## API
39
+
40
+ ### Wrapper API
41
+
42
+ ```typescript
43
+ import { iter } from 'iterflow';
44
+
45
+ iter([1, 2, 3, 4, 5])
46
+ .filter(x => x > 2) // Native iterator method
47
+ .map(x => x * 2) // Native iterator method
48
+ .sum(); // iterflow extension - 18
49
+ ```
50
+
51
+ ### Functional API
52
+
53
+ ```typescript
54
+ import { sum, filter, map } from 'iterflow/fn';
55
+
56
+ const data = [1, 2, 3, 4, 5];
57
+ sum(map(x => x * 2)(filter(x => x > 2)(data))); // 18
58
+ ```
59
+
60
+ ## Operations
61
+
62
+ ### Statistical
63
+
64
+ ```typescript
65
+ const numbers = iter([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
66
+
67
+ numbers.sum(); // 55
68
+ numbers.mean(); // 5.5
69
+ numbers.median(); // 5.5
70
+ numbers.variance(); // 8.25
71
+ numbers.percentile(75); // 7.75
72
+ ```
73
+
74
+ ### Windowing
75
+
76
+ ```typescript
77
+ // Sliding window
78
+ iter([1, 2, 3, 4, 5]).window(3).toArray();
79
+ // [[1,2,3], [2,3,4], [3,4,5]]
80
+
81
+ // Non-overlapping chunks
82
+ iter([1, 2, 3, 4, 5]).chunk(2).toArray();
83
+ // [[1,2], [3,4], [5]]
84
+
85
+ // Consecutive pairs
86
+ iter([1, 2, 3, 4]).pairwise().toArray();
87
+ // [[1,2], [2,3], [3,4]]
88
+ ```
89
+
90
+ ### Grouping
91
+
92
+ ```typescript
93
+ // Partition by predicate
94
+ const [evens, odds] = iter([1, 2, 3, 4, 5, 6])
95
+ .partition(x => x % 2 === 0);
96
+
97
+ // Group by key function
98
+ const items = [
99
+ { category: 'fruit', name: 'apple' },
100
+ { category: 'vegetable', name: 'carrot' },
101
+ { category: 'fruit', name: 'banana' }
102
+ ];
103
+
104
+ const groups = iter(items).groupBy(item => item.category);
105
+ ```
106
+
107
+ ### Set Operations
108
+
109
+ ```typescript
110
+ // Remove duplicates
111
+ iter([1, 2, 2, 3, 3, 3, 4]).distinct().toArray();
112
+ // [1, 2, 3, 4]
113
+
114
+ // Remove duplicates by key
115
+ iter(people).distinctBy(person => person.id).toArray();
116
+ ```
117
+
118
+ ### Combining
119
+
120
+ ```typescript
121
+ // Zip iterators
122
+ iter.zip([1, 2, 3], ['a', 'b', 'c']).toArray();
123
+ // [[1,'a'], [2,'b'], [3,'c']]
124
+
125
+ // Interleave round-robin
126
+ iter.interleave([1, 2, 3], [4, 5, 6]).toArray();
127
+ // [1, 4, 2, 5, 3, 6]
128
+
129
+ // Merge sorted iterators
130
+ iter.merge([1, 3, 5], [2, 4, 6]).toArray();
131
+ // [1, 2, 3, 4, 5, 6]
132
+ ```
133
+
134
+ ### Utilities
135
+
136
+ ```typescript
137
+ // Side effects
138
+ iter([1, 2, 3])
139
+ .tap(x => console.log(`Processing: ${x}`))
140
+ .map(x => x * 2)
141
+ .toArray();
142
+
143
+ // Conditional take/drop
144
+ iter([1, 2, 3, 4, 3, 2, 1]).takeWhile(x => x < 4).toArray();
145
+ // [1, 2, 3]
146
+
147
+ iter([1, 2, 3, 4, 5]).dropWhile(x => x < 3).toArray();
148
+ // [3, 4, 5]
149
+ ```
150
+
151
+ ### Generators
152
+
153
+ ```typescript
154
+ // Numeric ranges
155
+ iter.range(5).toArray(); // [0, 1, 2, 3, 4]
156
+ iter.range(2, 8).toArray(); // [2, 3, 4, 5, 6, 7]
157
+ iter.range(0, 10, 2).toArray(); // [0, 2, 4, 6, 8]
158
+
159
+ // Repeat values
160
+ iter.repeat('hello', 3).toArray(); // ['hello', 'hello', 'hello']
161
+ iter.repeat(0).take(5).toArray(); // [0, 0, 0, 0, 0]
162
+ ```
163
+
164
+ ## Examples
165
+
166
+ ### Processing Pipeline
167
+
168
+ ```typescript
169
+ interface Sale {
170
+ product: string;
171
+ amount: number;
172
+ category: string;
173
+ }
174
+
175
+ const sales: Sale[] = [
176
+ { product: 'Laptop', amount: 1200, category: 'Electronics' },
177
+ { product: 'Mouse', amount: 25, category: 'Electronics' },
178
+ { product: 'Book', amount: 15, category: 'Books' },
179
+ ];
180
+
181
+ // Average electronics sale amount
182
+ const electronicsAvg = iter(sales)
183
+ .filter(sale => sale.category === 'Electronics')
184
+ .map(sale => sale.amount)
185
+ .mean();
186
+
187
+ // Total sales by category
188
+ const salesByCategory = iter(sales)
189
+ .groupBy(sale => sale.category)
190
+ .entries()
191
+ .map(([category, sales]) => ({
192
+ category,
193
+ total: iter(sales).map(sale => sale.amount).sum()
194
+ }));
195
+ ```
196
+
197
+ ### Infinite Sequences
198
+
199
+ ```typescript
200
+ function* fibonacci() {
201
+ let a = 0, b = 1;
202
+ while (true) {
203
+ yield a;
204
+ [a, b] = [b, a + b];
205
+ }
206
+ }
207
+
208
+ // First 10 even fibonacci numbers
209
+ const evenFibs = iter(fibonacci())
210
+ .filter(x => x % 2 === 0)
211
+ .take(10)
212
+ .toArray();
213
+ ```
214
+
215
+ ### Moving Averages
216
+
217
+ ```typescript
218
+ const temperatures = [20, 22, 25, 23, 21, 19, 18, 20, 22, 24];
219
+
220
+ const movingAverages = iter(temperatures)
221
+ .window(3)
222
+ .map(window => iter(window).mean())
223
+ .toArray();
224
+ ```
225
+
226
+ ## License
227
+
228
+ The Unlicense - See [LICENSE](LICENSE) for details.