@okikio/observables 1.0.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.
Files changed (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +578 -0
  3. package/esm/_dnt.polyfills.d.ts +20 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +12 -0
  6. package/esm/_spec.d.ts +260 -0
  7. package/esm/_spec.d.ts.map +1 -0
  8. package/esm/_spec.js +1 -0
  9. package/esm/_types.d.ts +141 -0
  10. package/esm/_types.d.ts.map +1 -0
  11. package/esm/_types.js +20 -0
  12. package/esm/error.d.ts +331 -0
  13. package/esm/error.d.ts.map +1 -0
  14. package/esm/error.js +408 -0
  15. package/esm/events.d.ts +320 -0
  16. package/esm/events.d.ts.map +1 -0
  17. package/esm/events.js +451 -0
  18. package/esm/helpers/_types.d.ts +188 -0
  19. package/esm/helpers/_types.d.ts.map +1 -0
  20. package/esm/helpers/_types.js +1 -0
  21. package/esm/helpers/mod.d.ts +90 -0
  22. package/esm/helpers/mod.d.ts.map +1 -0
  23. package/esm/helpers/mod.js +90 -0
  24. package/esm/helpers/operations/batch.d.ts +109 -0
  25. package/esm/helpers/operations/batch.d.ts.map +1 -0
  26. package/esm/helpers/operations/batch.js +140 -0
  27. package/esm/helpers/operations/combination.d.ts +162 -0
  28. package/esm/helpers/operations/combination.d.ts.map +1 -0
  29. package/esm/helpers/operations/combination.js +350 -0
  30. package/esm/helpers/operations/conditional.d.ts +211 -0
  31. package/esm/helpers/operations/conditional.d.ts.map +1 -0
  32. package/esm/helpers/operations/conditional.js +280 -0
  33. package/esm/helpers/operations/core.d.ts +198 -0
  34. package/esm/helpers/operations/core.d.ts.map +1 -0
  35. package/esm/helpers/operations/core.js +264 -0
  36. package/esm/helpers/operations/errors.d.ts +277 -0
  37. package/esm/helpers/operations/errors.d.ts.map +1 -0
  38. package/esm/helpers/operations/errors.js +378 -0
  39. package/esm/helpers/operations/mod.d.ts +26 -0
  40. package/esm/helpers/operations/mod.d.ts.map +1 -0
  41. package/esm/helpers/operations/mod.js +25 -0
  42. package/esm/helpers/operations/timing.d.ts +206 -0
  43. package/esm/helpers/operations/timing.d.ts.map +1 -0
  44. package/esm/helpers/operations/timing.js +457 -0
  45. package/esm/helpers/operators.d.ts +520 -0
  46. package/esm/helpers/operators.d.ts.map +1 -0
  47. package/esm/helpers/operators.js +563 -0
  48. package/esm/helpers/pipe.d.ts +118 -0
  49. package/esm/helpers/pipe.d.ts.map +1 -0
  50. package/esm/helpers/pipe.js +129 -0
  51. package/esm/helpers/utils.d.ts +142 -0
  52. package/esm/helpers/utils.d.ts.map +1 -0
  53. package/esm/helpers/utils.js +193 -0
  54. package/esm/mod.d.ts +863 -0
  55. package/esm/mod.d.ts.map +1 -0
  56. package/esm/mod.js +861 -0
  57. package/esm/observable.d.ts +1610 -0
  58. package/esm/observable.d.ts.map +1 -0
  59. package/esm/observable.js +1970 -0
  60. package/esm/package.json +3 -0
  61. package/esm/queue.d.ts +201 -0
  62. package/esm/queue.d.ts.map +1 -0
  63. package/esm/queue.js +273 -0
  64. package/esm/symbol.d.ts +60 -0
  65. package/esm/symbol.d.ts.map +1 -0
  66. package/esm/symbol.js +132 -0
  67. package/package.json +96 -0
  68. package/script/_dnt.polyfills.d.ts +20 -0
  69. package/script/_dnt.polyfills.d.ts.map +1 -0
  70. package/script/_dnt.polyfills.js +13 -0
  71. package/script/_spec.d.ts +260 -0
  72. package/script/_spec.d.ts.map +1 -0
  73. package/script/_spec.js +2 -0
  74. package/script/_types.d.ts +141 -0
  75. package/script/_types.d.ts.map +1 -0
  76. package/script/_types.js +22 -0
  77. package/script/error.d.ts +331 -0
  78. package/script/error.d.ts.map +1 -0
  79. package/script/error.js +414 -0
  80. package/script/events.d.ts +320 -0
  81. package/script/events.d.ts.map +1 -0
  82. package/script/events.js +458 -0
  83. package/script/helpers/_types.d.ts +188 -0
  84. package/script/helpers/_types.d.ts.map +1 -0
  85. package/script/helpers/_types.js +2 -0
  86. package/script/helpers/mod.d.ts +90 -0
  87. package/script/helpers/mod.d.ts.map +1 -0
  88. package/script/helpers/mod.js +106 -0
  89. package/script/helpers/operations/batch.d.ts +109 -0
  90. package/script/helpers/operations/batch.d.ts.map +1 -0
  91. package/script/helpers/operations/batch.js +144 -0
  92. package/script/helpers/operations/combination.d.ts +162 -0
  93. package/script/helpers/operations/combination.d.ts.map +1 -0
  94. package/script/helpers/operations/combination.js +355 -0
  95. package/script/helpers/operations/conditional.d.ts +211 -0
  96. package/script/helpers/operations/conditional.d.ts.map +1 -0
  97. package/script/helpers/operations/conditional.js +286 -0
  98. package/script/helpers/operations/core.d.ts +198 -0
  99. package/script/helpers/operations/core.d.ts.map +1 -0
  100. package/script/helpers/operations/core.js +272 -0
  101. package/script/helpers/operations/errors.d.ts +277 -0
  102. package/script/helpers/operations/errors.d.ts.map +1 -0
  103. package/script/helpers/operations/errors.js +387 -0
  104. package/script/helpers/operations/mod.d.ts +26 -0
  105. package/script/helpers/operations/mod.d.ts.map +1 -0
  106. package/script/helpers/operations/mod.js +41 -0
  107. package/script/helpers/operations/timing.d.ts +206 -0
  108. package/script/helpers/operations/timing.d.ts.map +1 -0
  109. package/script/helpers/operations/timing.js +464 -0
  110. package/script/helpers/operators.d.ts +520 -0
  111. package/script/helpers/operators.d.ts.map +1 -0
  112. package/script/helpers/operators.js +570 -0
  113. package/script/helpers/pipe.d.ts +118 -0
  114. package/script/helpers/pipe.d.ts.map +1 -0
  115. package/script/helpers/pipe.js +132 -0
  116. package/script/helpers/utils.d.ts +142 -0
  117. package/script/helpers/utils.d.ts.map +1 -0
  118. package/script/helpers/utils.js +200 -0
  119. package/script/mod.d.ts +863 -0
  120. package/script/mod.d.ts.map +1 -0
  121. package/script/mod.js +877 -0
  122. package/script/observable.d.ts +1610 -0
  123. package/script/observable.d.ts.map +1 -0
  124. package/script/observable.js +1984 -0
  125. package/script/package.json +3 -0
  126. package/script/queue.d.ts +201 -0
  127. package/script/queue.d.ts.map +1 -0
  128. package/script/queue.js +286 -0
  129. package/script/symbol.d.ts +60 -0
  130. package/script/symbol.d.ts.map +1 -0
  131. package/script/symbol.js +135 -0
@@ -0,0 +1,280 @@
1
+ /**
2
+ * Predicate and decision-oriented operators for Observable streams.
3
+ *
4
+ * This entrypoint exports the operators that answer questions about a stream or
5
+ * gate values based on a condition. These are the Observable equivalents of
6
+ * array helpers such as `every()`, `some()`, and `find()`, plus utilities that
7
+ * stop early once a decision has been reached.
8
+ *
9
+ * Reach for this module when you care about whether a stream contains a match,
10
+ * whether every value passes a rule, or when processing should stop as soon as
11
+ * the answer is known.
12
+ *
13
+ * @module
14
+ */
15
+ import "../../_dnt.polyfills.js";
16
+ import { createStatefulOperator } from "../operators.js";
17
+ /**
18
+ * Checks if every item in the stream passes a test.
19
+ *
20
+ * Like `Array.prototype.every()`, it stops and returns `false` on the first
21
+ * failure. If the stream completes without any failures, it returns `true`.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { pipe, every, from } from "./helpers/mod.ts";
26
+ *
27
+ * // Array behavior
28
+ * const allEven = [2, 4, 6].every(n => n % 2 === 0); // true
29
+ * const someOdd = [2, 4, 5].every(n => n % 2 === 0); // false
30
+ *
31
+ * // Stream behavior
32
+ * const allEvenStream = from([2, 4, 6]);
33
+ * const result1 = await pipe(allEvenStream, every(n => n % 2 === 0)).toPromise(); // true
34
+ *
35
+ * const someOddStream = from([2, 4, 5]);
36
+ * const result2 = await pipe(someOddStream, every(n => n % 2 === 0)).toPromise(); // false
37
+ * ```
38
+ *
39
+ * ## Practical Use Case
40
+ *
41
+ * Use `every` to verify that all items in a stream meet a certain condition,
42
+ * such as ensuring all uploaded files are of the correct type or that all
43
+ * API responses were successful.
44
+ *
45
+ * ## Key Insight
46
+ *
47
+ * `every` provides a definitive boolean answer for the entire stream, making
48
+ * it a final, summary operation.
49
+ *
50
+ * @typeParam T - Type of values from the source stream
51
+ * @param predicate - Function to test each value
52
+ * @returns A stream operator that tests all values
53
+ */
54
+ export function every(predicate) {
55
+ return createStatefulOperator({
56
+ name: "every",
57
+ createState: () => ({ index: 0, finished: false }),
58
+ transform(chunk, state, controller) {
59
+ if (state.finished)
60
+ return;
61
+ const result = predicate(chunk, state.index++);
62
+ // If the predicate fails, emit false and complete
63
+ if (!result) {
64
+ state.finished = true;
65
+ controller.enqueue(false);
66
+ controller.terminate();
67
+ }
68
+ },
69
+ // If the stream completes and we haven't emitted yet, emit true
70
+ flush(state, controller) {
71
+ if (!state.finished) {
72
+ controller.enqueue(true);
73
+ }
74
+ },
75
+ });
76
+ }
77
+ /**
78
+ * Checks if at least one item in the stream passes a test.
79
+ *
80
+ * Like `Array.prototype.some()`, it stops and returns `true` on the first
81
+ * success. If the stream completes without any successes, it returns `false`.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import { pipe, some, from } from "./helpers/mod.ts";
86
+ *
87
+ * // Array behavior
88
+ * const hasEven = [1, 3, 4].some(n => n % 2 === 0); // true
89
+ * const noEven = [1, 3, 5].some(n => n % 2 === 0); // false
90
+ *
91
+ * // Stream behavior
92
+ * const hasEvenStream = from([1, 3, 4]);
93
+ * const result1 = await pipe(hasEvenStream, some(n => n % 2 === 0)).toPromise(); // true
94
+ *
95
+ * const noEvenStream = from([1, 3, 5]);
96
+ * const result2 = await pipe(noEvenStream, some(n => n % 2 === 0)).toPromise(); // false
97
+ * ```
98
+ *
99
+ * ## Practical Use Case
100
+ *
101
+ * Use `some` to quickly determine if a condition is met by any item in a
102
+ * stream, such as checking for the existence of a specific user permission or
103
+ * detecting if any item in a batch has an error.
104
+ *
105
+ * ## Key Insight
106
+ *
107
+ * `some` is an efficient way to get a "yes" or "no" answer from a stream
108
+ * without processing all the items.
109
+ *
110
+ * @typeParam T - Type of values from the source stream
111
+ * @param predicate - Function to test each value
112
+ * @returns A stream operator that tests for any matching value
113
+ */
114
+ export function some(predicate) {
115
+ return createStatefulOperator({
116
+ name: "some",
117
+ createState: () => ({ index: 0, finished: false }),
118
+ transform(chunk, state, controller) {
119
+ if (state.finished)
120
+ return;
121
+ const result = predicate(chunk, state.index++);
122
+ // If the predicate passes, emit true and complete
123
+ if (result) {
124
+ state.finished = true;
125
+ controller.enqueue(true);
126
+ controller.terminate();
127
+ }
128
+ },
129
+ // If the stream completes and we haven't emitted yet, emit false
130
+ flush(state, controller) {
131
+ if (!state.finished) {
132
+ controller.enqueue(false);
133
+ }
134
+ },
135
+ });
136
+ }
137
+ /**
138
+ * Finds the first item in the stream that passes a test.
139
+ *
140
+ * Like `Array.prototype.find()`, it stops and emits the first matching item,
141
+ * then immediately completes the stream.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * import { pipe, find, from } from "./helpers/mod.ts";
146
+ *
147
+ * // Array behavior
148
+ * const firstEven = [1, 3, 4, 6].find(n => n % 2 === 0); // 4
149
+ *
150
+ * // Stream behavior
151
+ * const numberStream = from([1, 3, 4, 6]);
152
+ * const result = await pipe(numberStream, find(n => n % 2 === 0)).toPromise(); // 4
153
+ * ```
154
+ *
155
+ * ## Practical Use Case
156
+ *
157
+ * Use `find` to locate a specific record or event in a stream without needing
158
+ * to process the entire dataset, such as finding the first available time slot
159
+ * or the first user to log in.
160
+ *
161
+ * ## Key Insight
162
+ *
163
+ * `find` is an efficient shortcut to get the first item you care about from a
164
+ * potentially long stream.
165
+ *
166
+ * @typeParam T - Type of values from the source stream
167
+ * @param predicate - Function to test each value
168
+ * @returns A stream operator that finds the first matching value
169
+ */
170
+ export function find(predicate) {
171
+ return createStatefulOperator({
172
+ name: "find",
173
+ createState: () => ({ index: 0 }),
174
+ transform(chunk, state, controller) {
175
+ const result = predicate(chunk, state.index++);
176
+ // If the predicate passes, emit the value and complete
177
+ if (result) {
178
+ controller.enqueue(chunk);
179
+ controller.terminate();
180
+ }
181
+ },
182
+ });
183
+ }
184
+ /**
185
+ * Removes duplicate values from the stream, keeping only the first occurrence.
186
+ *
187
+ * Like creating a `new Set()` from an array, but for async streams. You can
188
+ * provide a `keySelector` to determine uniqueness based on an object property.
189
+ *
190
+ * @example
191
+ * ```ts
192
+ * import { pipe, unique, from } from "./helpers/mod.ts";
193
+ *
194
+ * // Array behavior
195
+ * const uniqueNumbers = [...new Set([1, 2, 2, 3, 1])]; // [1, 2, 3]
196
+ *
197
+ * // Stream behavior
198
+ * const numberStream = from([1, 2, 2, 3, 1]);
199
+ * const uniqueStream = pipe(numberStream, unique()); // Emits 1, 2, 3
200
+ *
201
+ * // With a key selector
202
+ * const users = [{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }];
203
+ * const userStream = from(users);
204
+ * const uniqueUserStream = pipe(userStream, unique(user => user.id)); // Emits { id: 1, name: 'A' }, { id: 2, name: 'B' }
205
+ * ```
206
+ *
207
+ * ## Practical Use Case
208
+ *
209
+ * Use `unique` to de-duplicate a stream of events or data, such as processing
210
+ * a list of user IDs where some may appear multiple times, or handling event
211
+ * streams that might emit the same event more than once.
212
+ *
213
+ * ## Key Insight
214
+ *
215
+ * `unique` simplifies de-duplication in asynchronous pipelines, ensuring that
216
+ * downstream operations only run once for each unique item.
217
+ *
218
+ * @typeParam T The type of items in the stream.
219
+ * @typeParam K The type of the key used for uniqueness checks.
220
+ * @param keySelector An optional function to extract a key for uniqueness comparison.
221
+ * @returns An operator that filters out duplicate values.
222
+ */
223
+ export function unique(keySelector) {
224
+ return createStatefulOperator({
225
+ name: "unique",
226
+ createState: () => ({ seen: new Set() }),
227
+ transform(chunk, state, controller) {
228
+ const key = keySelector
229
+ ? keySelector(chunk)
230
+ : chunk;
231
+ if (!state.seen.has(key)) {
232
+ state.seen.add(key);
233
+ controller.enqueue(chunk);
234
+ }
235
+ },
236
+ });
237
+ }
238
+ /**
239
+ * Emits an item only if it is different from the previous one.
240
+ *
241
+ * This is useful for streams where values can be emitted repeatedly, but you
242
+ * only care about the changes.
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * import { pipe, changed, from } from "./helpers/mod.ts";
247
+ *
248
+ * // No direct Array equivalent, as it depends on sequence.
249
+ *
250
+ * // Stream behavior
251
+ * const valueStream = from([1, 1, 2, 2, 2, 1, 3]);
252
+ * const changedStream = pipe(valueStream, changed()); // Emits 1, 2, 1, 3
253
+ *
254
+ * // With a key selector
255
+ * const userStream = from([
256
+ * { id: 1, status: 'active' },
257
+ * { id: 1, status: 'active' },
258
+ * { id: 1, status: 'inactive' }
259
+ * ]);
260
+ * const statusChangeStream = pipe(userStream, changed(user => user.status));
261
+ * // Emits { id: 1, status: 'active' }, { id: 1, status: 'inactive' }
262
+ * ```
263
+ *
264
+ * ## Practical Use Case
265
+ *
266
+ * Use `changed` to monitor a stream of state updates and only react when the
267
+ * state actually changes. This is common in UI programming for tracking user
268
+ * input or state management.
269
+ *
270
+ * ## Key Insight
271
+ *
272
+ * `changed` filters out noise from repetitive values, allowing you to focus
273
+ * on the moments when something actually changes.
274
+ *
275
+ * @typeParam T The type of items in the stream.
276
+ * @typeParam K The type of the key used for comparison.
277
+ * @param keySelector An optional function to extract a key for comparison.
278
+ * @param compare An optional function to compare two keys for equality.
279
+ * @returns An operator that filters out consecutive duplicate values.
280
+ */
@@ -0,0 +1,198 @@
1
+ import "../../_dnt.polyfills.js";
2
+ import type { ExcludeError, Operator } from "../_types.js";
3
+ import type { ObservableError } from "../../error.js";
4
+ /**
5
+ * Core transformation and terminal operators for everyday stream work.
6
+ *
7
+ * This module is the closest match to familiar array helpers. It exports the
8
+ * operators you reach for first when you want to transform values, filter them,
9
+ * accumulate state, or stop after a condition has been met. In practice, this
10
+ * is where most pipelines start before you add timing or concurrency behavior.
11
+ *
12
+ * The important difference from arrays is error handling. These operators are
13
+ * designed to work with the library's pass-through model, so your callbacks see
14
+ * clean data values while `ObservableError` instances continue downstream
15
+ * unchanged until a dedicated error-handling step decides what to do with them.
16
+ *
17
+ * @module
18
+ */
19
+ /**
20
+ * Transforms each data item, automatically skipping errors.
21
+ *
22
+ * Like `Array.map()`, but errors flow through unchanged:
23
+ *
24
+ * ```ts
25
+ * // Array.map() transforms everything
26
+ * [1, 2, 3].map(n => n * 2) // [2, 4, 6]
27
+ *
28
+ * // Stream map() transforms only data
29
+ * pipe([1, Error, 3], map(n => n * 2)) // [2, Error, 6]
30
+ * ```
31
+ *
32
+ * Your function only receives clean data, never errors:
33
+ *
34
+ * ```ts
35
+ * pipe(
36
+ * userIds,
37
+ * map(id => fetchUser(id)), // Some API calls fail
38
+ * map(user => user.name), // Only runs on real users
39
+ * map(name => name.toUpperCase()) // Only runs on real names
40
+ * );
41
+ * // Result: [Name, Error, Name] - clean transformations, errors preserved
42
+ * ```
43
+ *
44
+ * @param project - Function that transforms each data item
45
+ */
46
+ export declare function map<T, R>(project: (value: ExcludeError<T>, index: number) => R): Operator<T | ObservableError, R | ObservableError>;
47
+ /**
48
+ * Keeps data items that pass your test, always preserves errors.
49
+ *
50
+ * Like `Array.filter()`, but errors automatically pass through:
51
+ *
52
+ * ```ts
53
+ * // Array.filter() tests everything
54
+ * [1, 2, 3, 4].filter(n => n > 2) // [3, 4]
55
+ *
56
+ * // Stream filter() tests only data
57
+ * pipe([1, Error, 3, 4], filter(n => n > 2)) // [Error, 3, 4]
58
+ * ```
59
+ *
60
+ * Your test function only receives clean data:
61
+ *
62
+ * ```ts
63
+ * pipe(
64
+ * users,
65
+ * filter(user => user.isActive), // Only tests real users
66
+ * filter(user => user.age >= 18) // Chain multiple filters
67
+ * );
68
+ * // Result: filtered users + all errors preserved
69
+ * ```
70
+ *
71
+ * @param predicate - Test function that decides which data items to keep
72
+ */
73
+ export declare function filter<T>(predicate: (value: ExcludeError<T>, index: number) => boolean): Operator<T | ObservableError, ExcludeError<T> | ObservableError>;
74
+ /**
75
+ * Takes the first N data items, errors don't count toward the limit.
76
+ *
77
+ * Like `Array.slice(0, N)`, but counts only successful data:
78
+ *
79
+ * ```ts
80
+ * // Array.slice() counts everything
81
+ * [1, "error", 2, 3].slice(0, 2) // [1, "error"] - 2 items total
82
+ *
83
+ * // Stream take() counts only data
84
+ * pipe([1, Error, 2, 3], take(2)) // [1, Error, 2] - 2 data items
85
+ * ```
86
+ *
87
+ * Perfect for pagination and "top N" scenarios:
88
+ *
89
+ * ```ts
90
+ * pipe(
91
+ * productIds,
92
+ * map(id => fetchProduct(id)), // Some API calls fail
93
+ * filter(p => p.rating > 4), // Only high-rated products
94
+ * take(10) // Exactly 10 products + any errors
95
+ * );
96
+ * // Guarantees 10 actual products for your UI
97
+ * ```
98
+ *
99
+ * Stream stops immediately after collecting N data items.
100
+ *
101
+ * @param count - How many data items to take
102
+ */
103
+ export declare function take<T>(count: number): Operator<T | ObservableError, ExcludeError<T> | ObservableError>;
104
+ /**
105
+ * Skips the first N data items, errors don't count toward the skip count.
106
+ *
107
+ * Like `Array.slice(N)`, but counts only successful data:
108
+ *
109
+ * ```ts
110
+ * // Array.slice() counts everything
111
+ * [1, "error", 2, 3].slice(2) // [2, 3] - skipped first 2 items
112
+ *
113
+ * // Stream drop() counts only data
114
+ * pipe([1, Error, 2, 3], drop(2)) // [Error, 3] - skipped first 2 data items
115
+ * ```
116
+ *
117
+ * Perfect for pagination - skip to the right page regardless of errors:
118
+ *
119
+ * ```ts
120
+ * // Page 2: skip first 20 successful products
121
+ * pipe(
122
+ * productIds,
123
+ * map(id => fetchProduct(id)), // Some API calls fail
124
+ * drop(20), // Skip first 20 real products
125
+ * take(20) // Next 20 products
126
+ * );
127
+ * // Errors flow through immediately, don't affect page positioning
128
+ * ```
129
+ *
130
+ * @param count - How many data items to skip
131
+ */
132
+ export declare function drop<T>(count: number): Operator<T | ObservableError, ExcludeError<T> | ObservableError>;
133
+ /**
134
+ * Runs side effects on data items, automatically skipping errors.
135
+ *
136
+ * Like adding `console.log()` to debug, but only logs clean data:
137
+ *
138
+ * ```ts
139
+ * // Regular debugging sees everything (messy)
140
+ * data.map(x => { console.log('Item:', x); return transform(x); })
141
+ *
142
+ * // Stream tap() sees only data (clean)
143
+ * pipe(
144
+ * data,
145
+ * map(x => transform(x)),
146
+ * tap(x => console.log('Processed:', x)) // Only logs real data
147
+ * )
148
+ * ```
149
+ *
150
+ * Perfect for logging, analytics, caching, progress tracking:
151
+ *
152
+ * ```ts
153
+ * pipe(
154
+ * userIds,
155
+ * map(id => fetchUser(id)), // Some API calls fail
156
+ * tap(user => console.log('Loaded:', user.name)), // Clean logs
157
+ * tap(user => analytics.track('user_loaded')), // Business events only
158
+ * filter(user => user.isActive)
159
+ * );
160
+ * // Logs show only successful operations, errors flow silently
161
+ * ```
162
+ *
163
+ * Data flows through unchanged - `tap` just observes.
164
+ *
165
+ * @param fn - Function to run on each data item (for side effects)
166
+ */
167
+ export declare function tap<T>(fn: (value: ExcludeError<T>) => void): Operator<T | ObservableError, T | ObservableError>;
168
+ /**
169
+ * Builds running totals from data, automatically skipping errors.
170
+ *
171
+ * Like `Array.reduce()`, but shows each step and handles errors:
172
+ *
173
+ * ```ts
174
+ * // Array.reduce() gives final result only
175
+ * [1, 2, 3].reduce((sum, n) => sum + n, 0) // 6
176
+ *
177
+ * // Stream scan() shows progressive results
178
+ * pipe([1, Error, 3], scan((sum, n) => sum + n, 0)) // [0, 1, Error, 4]
179
+ * ```
180
+ *
181
+ * Perfect for running totals, counters, building objects:
182
+ *
183
+ * ```ts
184
+ * pipe(
185
+ * productIds,
186
+ * map(id => fetchPrice(id)), // Some API calls fail
187
+ * scan((total, price) => total + price, 0) // Running cart total
188
+ * );
189
+ * // Result: [0, 10, Error, 35, 40] - total ignores errors
190
+ * ```
191
+ *
192
+ * Always starts by emitting your initial value immediately.
193
+ *
194
+ * @param accumulator - Function that combines current total with new data
195
+ * @param seed - Starting value (emitted first)
196
+ */
197
+ export declare function scan<T, R>(accumulator: (acc: R, value: ExcludeError<T>, index: number) => R, seed: R): Operator<T | ObservableError, R | ObservableError>;
198
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../src/helpers/operations/core.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,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