effect 4.0.0-beta.17 → 4.0.0-beta.19

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 (164) hide show
  1. package/dist/Array.d.ts +127 -299
  2. package/dist/Array.d.ts.map +1 -1
  3. package/dist/Array.js +102 -62
  4. package/dist/Array.js.map +1 -1
  5. package/dist/Cache.d.ts.map +1 -1
  6. package/dist/Cache.js +5 -4
  7. package/dist/Cache.js.map +1 -1
  8. package/dist/Channel.d.ts +97 -11
  9. package/dist/Channel.d.ts.map +1 -1
  10. package/dist/Channel.js +72 -29
  11. package/dist/Channel.js.map +1 -1
  12. package/dist/Chunk.d.ts +54 -247
  13. package/dist/Chunk.d.ts.map +1 -1
  14. package/dist/Chunk.js +36 -67
  15. package/dist/Chunk.js.map +1 -1
  16. package/dist/Effect.d.ts +337 -437
  17. package/dist/Effect.d.ts.map +1 -1
  18. package/dist/Effect.js +118 -134
  19. package/dist/Effect.js.map +1 -1
  20. package/dist/Filter.d.ts +0 -33
  21. package/dist/Filter.d.ts.map +1 -1
  22. package/dist/Filter.js +0 -13
  23. package/dist/Filter.js.map +1 -1
  24. package/dist/HashMap.d.ts +15 -14
  25. package/dist/HashMap.d.ts.map +1 -1
  26. package/dist/HashMap.js +4 -4
  27. package/dist/HashMap.js.map +1 -1
  28. package/dist/Iterable.d.ts +40 -39
  29. package/dist/Iterable.d.ts.map +1 -1
  30. package/dist/Iterable.js +94 -22
  31. package/dist/Iterable.js.map +1 -1
  32. package/dist/Option.d.ts +22 -15
  33. package/dist/Option.d.ts.map +1 -1
  34. package/dist/Option.js +14 -7
  35. package/dist/Option.js.map +1 -1
  36. package/dist/Pull.d.ts.map +1 -1
  37. package/dist/Pull.js +1 -1
  38. package/dist/Pull.js.map +1 -1
  39. package/dist/Record.d.ts +24 -120
  40. package/dist/Record.d.ts.map +1 -1
  41. package/dist/Record.js +21 -41
  42. package/dist/Record.js.map +1 -1
  43. package/dist/Sink.d.ts +11 -11
  44. package/dist/Sink.d.ts.map +1 -1
  45. package/dist/Sink.js +53 -6
  46. package/dist/Sink.js.map +1 -1
  47. package/dist/Stream.d.ts +198 -386
  48. package/dist/Stream.d.ts.map +1 -1
  49. package/dist/Stream.js +103 -59
  50. package/dist/Stream.js.map +1 -1
  51. package/dist/Trie.d.ts +18 -17
  52. package/dist/Trie.d.ts.map +1 -1
  53. package/dist/Trie.js +5 -5
  54. package/dist/Trie.js.map +1 -1
  55. package/dist/TxChunk.d.ts +37 -37
  56. package/dist/TxChunk.d.ts.map +1 -1
  57. package/dist/TxChunk.js +3 -3
  58. package/dist/TxChunk.js.map +1 -1
  59. package/dist/TxDeferred.d.ts +328 -0
  60. package/dist/TxDeferred.d.ts.map +1 -0
  61. package/dist/TxDeferred.js +196 -0
  62. package/dist/TxDeferred.js.map +1 -0
  63. package/dist/TxHashMap.d.ts +84 -83
  64. package/dist/TxHashMap.d.ts.map +1 -1
  65. package/dist/TxHashMap.js +24 -24
  66. package/dist/TxHashMap.js.map +1 -1
  67. package/dist/TxHashSet.d.ts +35 -35
  68. package/dist/TxHashSet.d.ts.map +1 -1
  69. package/dist/TxHashSet.js +14 -14
  70. package/dist/TxHashSet.js.map +1 -1
  71. package/dist/TxPriorityQueue.d.ts +609 -0
  72. package/dist/TxPriorityQueue.d.ts.map +1 -0
  73. package/dist/TxPriorityQueue.js +415 -0
  74. package/dist/TxPriorityQueue.js.map +1 -0
  75. package/dist/TxPubSub.d.ts +585 -0
  76. package/dist/TxPubSub.d.ts.map +1 -0
  77. package/dist/TxPubSub.js +521 -0
  78. package/dist/TxPubSub.js.map +1 -0
  79. package/dist/TxQueue.d.ts +32 -32
  80. package/dist/TxQueue.d.ts.map +1 -1
  81. package/dist/TxQueue.js +26 -26
  82. package/dist/TxQueue.js.map +1 -1
  83. package/dist/TxReentrantLock.d.ts +523 -0
  84. package/dist/TxReentrantLock.d.ts.map +1 -0
  85. package/dist/TxReentrantLock.js +504 -0
  86. package/dist/TxReentrantLock.js.map +1 -0
  87. package/dist/TxRef.d.ts +34 -34
  88. package/dist/TxRef.d.ts.map +1 -1
  89. package/dist/TxRef.js +21 -14
  90. package/dist/TxRef.js.map +1 -1
  91. package/dist/TxSemaphore.d.ts +8 -8
  92. package/dist/TxSemaphore.d.ts.map +1 -1
  93. package/dist/TxSemaphore.js +7 -7
  94. package/dist/TxSemaphore.js.map +1 -1
  95. package/dist/TxSubscriptionRef.d.ts +508 -0
  96. package/dist/TxSubscriptionRef.d.ts.map +1 -0
  97. package/dist/TxSubscriptionRef.js +293 -0
  98. package/dist/TxSubscriptionRef.js.map +1 -0
  99. package/dist/index.d.ts +40 -0
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +40 -0
  102. package/dist/index.js.map +1 -1
  103. package/dist/internal/effect.js +99 -42
  104. package/dist/internal/effect.js.map +1 -1
  105. package/dist/internal/hashMap.js +3 -2
  106. package/dist/internal/hashMap.js.map +1 -1
  107. package/dist/internal/trie.js +5 -4
  108. package/dist/internal/trie.js.map +1 -1
  109. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  110. package/dist/unstable/ai/Tool.js +0 -9
  111. package/dist/unstable/ai/Tool.js.map +1 -1
  112. package/dist/unstable/cli/Command.d.ts +1 -1
  113. package/dist/unstable/cli/Command.d.ts.map +1 -1
  114. package/dist/unstable/cli/Command.js +1 -1
  115. package/dist/unstable/cli/Command.js.map +1 -1
  116. package/dist/unstable/cluster/K8sHttpClient.js +4 -4
  117. package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
  118. package/dist/unstable/cluster/Sharding.js +1 -1
  119. package/dist/unstable/cluster/Sharding.js.map +1 -1
  120. package/dist/unstable/encoding/Sse.js +1 -1
  121. package/dist/unstable/encoding/Sse.js.map +1 -1
  122. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  123. package/dist/unstable/rpc/RpcServer.js +1 -2
  124. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  125. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  126. package/dist/unstable/socket/Socket.js +3 -3
  127. package/dist/unstable/socket/Socket.js.map +1 -1
  128. package/package.json +1 -1
  129. package/src/Array.ts +190 -342
  130. package/src/Cache.ts +6 -5
  131. package/src/Channel.ts +506 -102
  132. package/src/Chunk.ts +81 -268
  133. package/src/Effect.ts +437 -518
  134. package/src/Filter.ts +0 -57
  135. package/src/HashMap.ts +15 -14
  136. package/src/Iterable.ts +105 -50
  137. package/src/Option.ts +30 -20
  138. package/src/Pull.ts +1 -1
  139. package/src/Record.ts +43 -152
  140. package/src/Sink.ts +75 -23
  141. package/src/Stream.ts +442 -502
  142. package/src/Trie.ts +18 -17
  143. package/src/TxChunk.ts +72 -53
  144. package/src/TxDeferred.ts +394 -0
  145. package/src/TxHashMap.ts +332 -285
  146. package/src/TxHashSet.ts +111 -116
  147. package/src/TxPriorityQueue.ts +767 -0
  148. package/src/TxPubSub.ts +789 -0
  149. package/src/TxQueue.ts +241 -251
  150. package/src/TxReentrantLock.ts +753 -0
  151. package/src/TxRef.ts +50 -38
  152. package/src/TxSemaphore.ts +29 -32
  153. package/src/TxSubscriptionRef.ts +639 -0
  154. package/src/index.ts +45 -0
  155. package/src/internal/effect.ts +368 -163
  156. package/src/internal/hashMap.ts +7 -5
  157. package/src/internal/trie.ts +16 -9
  158. package/src/unstable/ai/Tool.ts +0 -9
  159. package/src/unstable/cli/Command.ts +6 -4
  160. package/src/unstable/cluster/K8sHttpClient.ts +4 -4
  161. package/src/unstable/cluster/Sharding.ts +1 -1
  162. package/src/unstable/encoding/Sse.ts +1 -1
  163. package/src/unstable/rpc/RpcServer.ts +1 -7
  164. package/src/unstable/socket/Socket.ts +9 -11
@@ -0,0 +1,415 @@
1
+ /**
2
+ * A transactional priority queue. Elements are dequeued in order determined by the
3
+ * provided `Order` instance. All operations participate in the STM transaction system.
4
+ *
5
+ * @since 4.0.0
6
+ */
7
+ import * as C from "./Chunk.js";
8
+ import * as Effect from "./Effect.js";
9
+ import { dual } from "./Function.js";
10
+ import { NodeInspectSymbol, toJson } from "./Inspectable.js";
11
+ import * as O from "./Option.js";
12
+ import { pipeArguments } from "./Pipeable.js";
13
+ import * as TxRef from "./TxRef.js";
14
+ const TypeId = "~effect/transactions/TxPriorityQueue";
15
+ const TxPriorityQueueProto = {
16
+ [NodeInspectSymbol]() {
17
+ return toJson(this);
18
+ },
19
+ toJSON() {
20
+ return {
21
+ _id: "TxPriorityQueue"
22
+ };
23
+ },
24
+ pipe() {
25
+ return pipeArguments(this, arguments);
26
+ }
27
+ };
28
+ const makeTxPriorityQueue = (ref, ord) => {
29
+ const self = Object.create(TxPriorityQueueProto);
30
+ self[TypeId] = TypeId;
31
+ self.ref = ref;
32
+ self.ord = ord;
33
+ return self;
34
+ };
35
+ const insertSorted = (chunk, value, ord) => {
36
+ const arr = C.toArray(chunk);
37
+ let lo = 0;
38
+ let hi = arr.length;
39
+ while (lo < hi) {
40
+ const mid = lo + hi >>> 1;
41
+ if (ord(arr[mid], value) <= 0) {
42
+ lo = mid + 1;
43
+ } else {
44
+ hi = mid;
45
+ }
46
+ }
47
+ const out = Array(arr.length + 1);
48
+ for (let i = 0; i < lo; i++) out[i] = arr[i];
49
+ out[lo] = value;
50
+ for (let i = lo; i < arr.length; i++) out[i + 1] = arr[i];
51
+ return C.fromIterable(out);
52
+ };
53
+ /**
54
+ * Creates an empty `TxPriorityQueue` with the given ordering.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { Effect, Order, TxPriorityQueue } from "effect"
59
+ *
60
+ * const program = Effect.gen(function*() {
61
+ * const pq = yield* TxPriorityQueue.empty<number>(Order.Number)
62
+ * const empty = yield* TxPriorityQueue.isEmpty(pq)
63
+ * console.log(empty) // true
64
+ * })
65
+ * ```
66
+ *
67
+ * @since 4.0.0
68
+ * @category constructors
69
+ */
70
+ export const empty = order => Effect.map(TxRef.make(C.empty()), ref => makeTxPriorityQueue(ref, order));
71
+ /**
72
+ * Creates a `TxPriorityQueue` from an iterable of elements.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * import { Effect, Order, TxPriorityQueue } from "effect"
77
+ *
78
+ * const program = Effect.gen(function*() {
79
+ * const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [3, 1, 2])
80
+ * const first = yield* TxPriorityQueue.take(pq)
81
+ * console.log(first) // 1
82
+ * })
83
+ * ```
84
+ *
85
+ * @since 4.0.0
86
+ * @category constructors
87
+ */
88
+ export const fromIterable = /*#__PURE__*/dual(2, (order, iterable) => {
89
+ const arr = Array.from(iterable).sort((a, b) => order(a, b));
90
+ return Effect.map(TxRef.make(C.fromIterable(arr)), ref => makeTxPriorityQueue(ref, order));
91
+ });
92
+ /**
93
+ * Creates a `TxPriorityQueue` from variadic elements.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import { Effect, Order, TxPriorityQueue } from "effect"
98
+ *
99
+ * const program = Effect.gen(function*() {
100
+ * const pq = yield* TxPriorityQueue.make(Order.Number)(3, 1, 2)
101
+ * const first = yield* TxPriorityQueue.take(pq)
102
+ * console.log(first) // 1
103
+ * })
104
+ * ```
105
+ *
106
+ * @since 4.0.0
107
+ * @category constructors
108
+ */
109
+ export const make = order => (...elements) => fromIterable(order, elements);
110
+ /**
111
+ * Returns the number of elements in the queue.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * import { Effect, Order, TxPriorityQueue } from "effect"
116
+ *
117
+ * const program = Effect.gen(function*() {
118
+ * const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [1, 2, 3])
119
+ * const s = yield* TxPriorityQueue.size(pq)
120
+ * console.log(s) // 3
121
+ * })
122
+ * ```
123
+ *
124
+ * @since 4.0.0
125
+ * @category getters
126
+ */
127
+ export const size = self => Effect.map(TxRef.get(self.ref), C.size);
128
+ /**
129
+ * Returns `true` if the queue is empty.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * import { Effect, Order, TxPriorityQueue } from "effect"
134
+ *
135
+ * const program = Effect.gen(function*() {
136
+ * const pq = yield* TxPriorityQueue.empty<number>(Order.Number)
137
+ * const empty = yield* TxPriorityQueue.isEmpty(pq)
138
+ * console.log(empty) // true
139
+ * })
140
+ * ```
141
+ *
142
+ * @since 4.0.0
143
+ * @category getters
144
+ */
145
+ export const isEmpty = self => Effect.map(size(self), n => n === 0);
146
+ /**
147
+ * Returns `true` if the queue has at least one element.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * import { Effect, Order, TxPriorityQueue } from "effect"
152
+ *
153
+ * const program = Effect.gen(function*() {
154
+ * const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [1])
155
+ * const nonEmpty = yield* TxPriorityQueue.isNonEmpty(pq)
156
+ * console.log(nonEmpty) // true
157
+ * })
158
+ * ```
159
+ *
160
+ * @since 4.0.0
161
+ * @category getters
162
+ */
163
+ export const isNonEmpty = self => Effect.map(size(self), n => n > 0);
164
+ /**
165
+ * Observes the smallest element without removing it. Retries if the queue is
166
+ * empty.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * import { Effect, Order, TxPriorityQueue } from "effect"
171
+ *
172
+ * const program = Effect.gen(function*() {
173
+ * const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [3, 1, 2])
174
+ * const top = yield* TxPriorityQueue.peek(pq)
175
+ * console.log(top) // 1
176
+ * })
177
+ * ```
178
+ *
179
+ * @since 4.0.0
180
+ * @category getters
181
+ */
182
+ export const peek = self => Effect.gen(function* () {
183
+ const chunk = yield* TxRef.get(self.ref);
184
+ const head = C.head(chunk);
185
+ if (O.isNone(head)) {
186
+ return yield* Effect.retryTransaction;
187
+ }
188
+ return head.value;
189
+ });
190
+ /**
191
+ * Observes the smallest element without removing it. Returns `None` if the
192
+ * queue is empty.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * import { Effect, Option, Order, TxPriorityQueue } from "effect"
197
+ *
198
+ * const program = Effect.gen(function*() {
199
+ * const pq = yield* TxPriorityQueue.empty<number>(Order.Number)
200
+ * const result = yield* TxPriorityQueue.peekOption(pq)
201
+ * console.log(Option.isNone(result)) // true
202
+ * })
203
+ * ```
204
+ *
205
+ * @since 4.0.0
206
+ * @category getters
207
+ */
208
+ export const peekOption = self => Effect.map(TxRef.get(self.ref), C.head);
209
+ /**
210
+ * Inserts an element into the queue in sorted position.
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * import { Effect, Order, TxPriorityQueue } from "effect"
215
+ *
216
+ * const program = Effect.gen(function*() {
217
+ * const pq = yield* TxPriorityQueue.empty<number>(Order.Number)
218
+ * yield* TxPriorityQueue.offer(pq, 2)
219
+ * yield* TxPriorityQueue.offer(pq, 1)
220
+ * const first = yield* TxPriorityQueue.take(pq)
221
+ * console.log(first) // 1
222
+ * })
223
+ * ```
224
+ *
225
+ * @since 4.0.0
226
+ * @category mutations
227
+ */
228
+ export const offer = /*#__PURE__*/dual(2, (self, value) => TxRef.update(self.ref, chunk => insertSorted(chunk, value, self.ord)));
229
+ /**
230
+ * Inserts all elements from an iterable into the queue.
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * import { Effect, Order, TxPriorityQueue } from "effect"
235
+ *
236
+ * const program = Effect.gen(function*() {
237
+ * const pq = yield* TxPriorityQueue.empty<number>(Order.Number)
238
+ * yield* TxPriorityQueue.offerAll(pq, [3, 1, 2])
239
+ * const first = yield* TxPriorityQueue.take(pq)
240
+ * console.log(first) // 1
241
+ * })
242
+ * ```
243
+ *
244
+ * @since 4.0.0
245
+ * @category mutations
246
+ */
247
+ export const offerAll = /*#__PURE__*/dual(2, (self, values) => TxRef.update(self.ref, chunk => {
248
+ const arr = [...C.toArray(chunk), ...values].sort((a, b) => self.ord(a, b));
249
+ return C.fromIterable(arr);
250
+ }));
251
+ /**
252
+ * Takes the smallest element from the queue. Retries if the queue is empty.
253
+ *
254
+ * @example
255
+ * ```ts
256
+ * import { Effect, Order, TxPriorityQueue } from "effect"
257
+ *
258
+ * const program = Effect.gen(function*() {
259
+ * const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [3, 1, 2])
260
+ * const first = yield* TxPriorityQueue.take(pq)
261
+ * console.log(first) // 1
262
+ * })
263
+ * ```
264
+ *
265
+ * @since 4.0.0
266
+ * @category mutations
267
+ */
268
+ export const take = self => Effect.gen(function* () {
269
+ const chunk = yield* TxRef.get(self.ref);
270
+ const head = C.head(chunk);
271
+ if (O.isNone(head)) {
272
+ return yield* Effect.retryTransaction;
273
+ }
274
+ yield* TxRef.set(self.ref, C.drop(chunk, 1));
275
+ return head.value;
276
+ });
277
+ /**
278
+ * Takes all elements from the queue, returning them in priority order.
279
+ *
280
+ * @example
281
+ * ```ts
282
+ * import { Effect, Order, TxPriorityQueue } from "effect"
283
+ *
284
+ * const program = Effect.gen(function*() {
285
+ * const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [3, 1, 2])
286
+ * const all = yield* TxPriorityQueue.takeAll(pq)
287
+ * console.log(all) // [1, 2, 3]
288
+ * })
289
+ * ```
290
+ *
291
+ * @since 4.0.0
292
+ * @category mutations
293
+ */
294
+ export const takeAll = self => Effect.map(TxRef.modify(self.ref, chunk => [chunk, C.empty()]), C.toArray);
295
+ /**
296
+ * Tries to take the smallest element. Returns `None` if the queue is empty.
297
+ *
298
+ * @example
299
+ * ```ts
300
+ * import { Effect, Option, Order, TxPriorityQueue } from "effect"
301
+ *
302
+ * const program = Effect.gen(function*() {
303
+ * const pq = yield* TxPriorityQueue.empty<number>(Order.Number)
304
+ * const result = yield* TxPriorityQueue.takeOption(pq)
305
+ * console.log(Option.isNone(result)) // true
306
+ * })
307
+ * ```
308
+ *
309
+ * @since 4.0.0
310
+ * @category mutations
311
+ */
312
+ export const takeOption = self => TxRef.modify(self.ref, chunk => {
313
+ const head = C.head(chunk);
314
+ if (O.isNone(head)) {
315
+ return [O.none(), chunk];
316
+ }
317
+ return [O.some(head.value), C.drop(chunk, 1)];
318
+ });
319
+ /**
320
+ * Takes up to `n` elements from the queue in priority order.
321
+ *
322
+ * @example
323
+ * ```ts
324
+ * import { Effect, Order, TxPriorityQueue } from "effect"
325
+ *
326
+ * const program = Effect.gen(function*() {
327
+ * const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [5, 3, 1, 4, 2])
328
+ * const top2 = yield* TxPriorityQueue.takeUpTo(pq, 2)
329
+ * console.log(top2) // [1, 2]
330
+ * })
331
+ * ```
332
+ *
333
+ * @since 4.0.0
334
+ * @category mutations
335
+ */
336
+ export const takeUpTo = /*#__PURE__*/dual(2, (self, n) => Effect.map(TxRef.modify(self.ref, chunk => {
337
+ const taken = C.take(chunk, n);
338
+ const rest = C.drop(chunk, n);
339
+ return [taken, rest];
340
+ }), C.toArray));
341
+ /**
342
+ * Removes elements matching the predicate.
343
+ *
344
+ * @example
345
+ * ```ts
346
+ * import { Effect, Order, TxPriorityQueue } from "effect"
347
+ *
348
+ * const program = Effect.gen(function*() {
349
+ * const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [1, 2, 3, 4, 5])
350
+ * yield* TxPriorityQueue.removeIf(pq, (n) => n % 2 === 0)
351
+ * const all = yield* TxPriorityQueue.takeAll(pq)
352
+ * console.log(all) // [1, 3, 5]
353
+ * })
354
+ * ```
355
+ *
356
+ * @since 4.0.0
357
+ * @category filtering
358
+ */
359
+ export const removeIf = /*#__PURE__*/dual(2, (self, predicate) => TxRef.update(self.ref, chunk => C.filter(chunk, a => !predicate(a))));
360
+ /**
361
+ * Retains only elements matching the predicate.
362
+ *
363
+ * @example
364
+ * ```ts
365
+ * import { Effect, Order, TxPriorityQueue } from "effect"
366
+ *
367
+ * const program = Effect.gen(function*() {
368
+ * const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [1, 2, 3, 4, 5])
369
+ * yield* TxPriorityQueue.retainIf(pq, (n) => n % 2 === 0)
370
+ * const all = yield* TxPriorityQueue.takeAll(pq)
371
+ * console.log(all) // [2, 4]
372
+ * })
373
+ * ```
374
+ *
375
+ * @since 4.0.0
376
+ * @category filtering
377
+ */
378
+ export const retainIf = /*#__PURE__*/dual(2, (self, predicate) => TxRef.update(self.ref, chunk => C.filter(chunk, predicate)));
379
+ /**
380
+ * Returns all elements in priority order without removing them.
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * import { Effect, Order, TxPriorityQueue } from "effect"
385
+ *
386
+ * const program = Effect.gen(function*() {
387
+ * const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [3, 1, 2])
388
+ * const all = yield* TxPriorityQueue.toArray(pq)
389
+ * console.log(all) // [1, 2, 3]
390
+ * })
391
+ * ```
392
+ *
393
+ * @since 4.0.0
394
+ * @category conversions
395
+ */
396
+ export const toArray = self => Effect.map(TxRef.get(self.ref), C.toArray);
397
+ /**
398
+ * Determines if the provided value is a `TxPriorityQueue`.
399
+ *
400
+ * @example
401
+ * ```ts
402
+ * import { Effect, Order, TxPriorityQueue } from "effect"
403
+ *
404
+ * const program = Effect.gen(function*() {
405
+ * const pq = yield* TxPriorityQueue.empty<number>(Order.Number)
406
+ * console.log(TxPriorityQueue.isTxPriorityQueue(pq)) // true
407
+ * console.log(TxPriorityQueue.isTxPriorityQueue("nope")) // false
408
+ * })
409
+ * ```
410
+ *
411
+ * @since 4.0.0
412
+ * @category guards
413
+ */
414
+ export const isTxPriorityQueue = u => typeof u === "object" && u !== null && TypeId in u;
415
+ //# sourceMappingURL=TxPriorityQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TxPriorityQueue.js","names":["C","Effect","dual","NodeInspectSymbol","toJson","O","pipeArguments","TxRef","TypeId","TxPriorityQueueProto","toJSON","_id","pipe","arguments","makeTxPriorityQueue","ref","ord","self","Object","create","insertSorted","chunk","value","arr","toArray","lo","hi","length","mid","out","Array","i","fromIterable","empty","order","map","make","iterable","from","sort","a","b","elements","size","get","isEmpty","n","isNonEmpty","peek","gen","head","isNone","retryTransaction","peekOption","offer","update","offerAll","values","take","set","drop","takeAll","modify","takeOption","none","some","takeUpTo","taken","rest","removeIf","predicate","filter","retainIf","isTxPriorityQueue","u"],"sources":["../src/TxPriorityQueue.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AA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