effect 3.16.13 → 3.16.14

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 (67) hide show
  1. package/dist/cjs/Predicate.js +516 -200
  2. package/dist/cjs/Predicate.js.map +1 -1
  3. package/dist/cjs/Schema.js +2 -2
  4. package/dist/cjs/Schema.js.map +1 -1
  5. package/dist/cjs/internal/channel.js +2 -2
  6. package/dist/cjs/internal/channel.js.map +1 -1
  7. package/dist/cjs/internal/core-effect.js +1 -0
  8. package/dist/cjs/internal/core-effect.js.map +1 -1
  9. package/dist/cjs/internal/dataSource.js +2 -2
  10. package/dist/cjs/internal/dataSource.js.map +1 -1
  11. package/dist/cjs/internal/fiberRuntime.js +1 -1
  12. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  13. package/dist/cjs/internal/groupBy.js +2 -2
  14. package/dist/cjs/internal/groupBy.js.map +1 -1
  15. package/dist/cjs/internal/sink.js +4 -4
  16. package/dist/cjs/internal/sink.js.map +1 -1
  17. package/dist/cjs/internal/stm/stm.js +3 -3
  18. package/dist/cjs/internal/stm/stm.js.map +1 -1
  19. package/dist/cjs/internal/stream.js +5 -5
  20. package/dist/cjs/internal/stream.js.map +1 -1
  21. package/dist/cjs/internal/version.js +1 -1
  22. package/dist/dts/Effect.d.ts +1 -1
  23. package/dist/dts/Effect.d.ts.map +1 -1
  24. package/dist/dts/Predicate.d.ts +1190 -375
  25. package/dist/dts/Predicate.d.ts.map +1 -1
  26. package/dist/dts/index.d.ts +15 -0
  27. package/dist/dts/index.d.ts.map +1 -1
  28. package/dist/dts/internal/core-effect.d.ts.map +1 -1
  29. package/dist/dts/internal/stm/stm.d.ts.map +1 -1
  30. package/dist/dts/internal/stream.d.ts.map +1 -1
  31. package/dist/esm/Predicate.js +516 -200
  32. package/dist/esm/Predicate.js.map +1 -1
  33. package/dist/esm/Schema.js +2 -2
  34. package/dist/esm/Schema.js.map +1 -1
  35. package/dist/esm/index.js +15 -0
  36. package/dist/esm/index.js.map +1 -1
  37. package/dist/esm/internal/channel.js +2 -2
  38. package/dist/esm/internal/channel.js.map +1 -1
  39. package/dist/esm/internal/core-effect.js +1 -0
  40. package/dist/esm/internal/core-effect.js.map +1 -1
  41. package/dist/esm/internal/dataSource.js +2 -2
  42. package/dist/esm/internal/dataSource.js.map +1 -1
  43. package/dist/esm/internal/fiberRuntime.js +1 -1
  44. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  45. package/dist/esm/internal/groupBy.js +2 -2
  46. package/dist/esm/internal/groupBy.js.map +1 -1
  47. package/dist/esm/internal/sink.js +4 -4
  48. package/dist/esm/internal/sink.js.map +1 -1
  49. package/dist/esm/internal/stm/stm.js +3 -3
  50. package/dist/esm/internal/stm/stm.js.map +1 -1
  51. package/dist/esm/internal/stream.js +5 -5
  52. package/dist/esm/internal/stream.js.map +1 -1
  53. package/dist/esm/internal/version.js +1 -1
  54. package/package.json +1 -1
  55. package/src/Effect.ts +1 -1
  56. package/src/Predicate.ts +1213 -377
  57. package/src/Schema.ts +2 -2
  58. package/src/index.ts +15 -0
  59. package/src/internal/channel.ts +2 -2
  60. package/src/internal/core-effect.ts +1 -0
  61. package/src/internal/dataSource.ts +12 -14
  62. package/src/internal/fiberRuntime.ts +2 -2
  63. package/src/internal/groupBy.ts +12 -14
  64. package/src/internal/sink.ts +13 -15
  65. package/src/internal/stm/stm.ts +16 -20
  66. package/src/internal/stream.ts +17 -23
  67. package/src/internal/version.ts +1 -1
package/src/Schema.ts CHANGED
@@ -7151,8 +7151,8 @@ export const lessThanOrEqualToDate = <S extends Schema.Any>(
7151
7151
  <A extends Date>(self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>): filter<S> =>
7152
7152
  self.pipe(
7153
7153
  filter((a: Date) => a <= max, {
7154
- schemaId: LessThanDateSchemaId,
7155
- [LessThanDateSchemaId]: { max },
7154
+ schemaId: LessThanOrEqualToDateSchemaId,
7155
+ [LessThanOrEqualToDateSchemaId]: { max },
7156
7156
  title: `lessThanOrEqualToDate(${util_.formatDate(max)})`,
7157
7157
  description: `a date before or equal to ${util_.formatDate(max)}`,
7158
7158
  ...annotations
package/src/index.ts CHANGED
@@ -1089,6 +1089,21 @@ export * as Pipeable from "./Pipeable.js"
1089
1089
  export * as Pool from "./Pool.js"
1090
1090
 
1091
1091
  /**
1092
+ * This module provides a collection of functions for working with predicates and refinements.
1093
+ *
1094
+ * A `Predicate<A>` is a function that takes a value of type `A` and returns a boolean.
1095
+ * It is used to check if a value satisfies a certain condition.
1096
+ *
1097
+ * A `Refinement<A, B>` is a special type of predicate that not only checks a condition
1098
+ * but also provides a type guard, allowing TypeScript to narrow the type of the input
1099
+ * value from `A` to a more specific type `B` within a conditional block.
1100
+ *
1101
+ * The module includes:
1102
+ * - Basic predicates and refinements for common types (e.g., `isString`, `isNumber`).
1103
+ * - Combinators to create new predicates from existing ones (e.g., `and`, `or`, `not`).
1104
+ * - Advanced combinators for working with data structures (e.g., `tuple`, `struct`).
1105
+ * - Type-level utilities for inspecting predicate and refinement types.
1106
+ *
1092
1107
  * @since 2.0.0
1093
1108
  */
1094
1109
  export * as Predicate from "./Predicate.js"
@@ -2300,8 +2300,8 @@ const toQueueInternal = <Err, Done, Elem>(
2300
2300
  core.fromEffect(Queue.offer(queue, Either.right(elem))),
2301
2301
  () => toQueueInternal(queue)
2302
2302
  ),
2303
- onFailure: (cause) => core.fromEffect(pipe(Queue.offer(queue, Either.left(Exit.failCause(cause))))),
2304
- onDone: (done) => core.fromEffect(pipe(Queue.offer(queue, Either.left(Exit.succeed(done)))))
2303
+ onFailure: (cause) => core.fromEffect(Queue.offer(queue, Either.left(Exit.failCause(cause)))),
2304
+ onDone: (done) => core.fromEffect(Queue.offer(queue, Either.left(Exit.succeed(done))))
2305
2305
  })
2306
2306
  }
2307
2307
 
@@ -2168,6 +2168,7 @@ export const endSpan = <A, E>(span: Tracer.Span, exit: Exit<A, E>, clock: Clock.
2168
2168
  return
2169
2169
  }
2170
2170
  if (core.exitIsFailure(exit) && internalCause.spanToTrace.has(span)) {
2171
+ // https://opentelemetry.io/docs/specs/semconv/registry/attributes/code/#code-stacktrace
2171
2172
  span.attribute("code.stacktrace", internalCause.spanToTrace.get(span)!())
2172
2173
  }
2173
2174
  span.end(timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0, exit)
@@ -190,20 +190,18 @@ export const eitherWith = dual<
190
190
  ) =>
191
191
  new core.RequestResolverImpl<C, R | R2>(
192
192
  (batch) =>
193
- pipe(
194
- core.forEachSequential(batch, (requests) => {
195
- const [as, bs] = pipe(
196
- requests,
197
- RA.partitionMap(f)
198
- )
199
- return zipWithOptions(
200
- self.runAll(Array.of(as)),
201
- that.runAll(Array.of(bs)),
202
- () => void 0,
203
- { concurrent: true }
204
- )
205
- })
206
- ),
193
+ core.forEachSequential(batch, (requests) => {
194
+ const [as, bs] = pipe(
195
+ requests,
196
+ RA.partitionMap(f)
197
+ )
198
+ return zipWithOptions(
199
+ self.runAll(Array.of(as)),
200
+ that.runAll(Array.of(bs)),
201
+ () => void 0,
202
+ { concurrent: true }
203
+ )
204
+ }),
207
205
  Chunk.make("EitherWith", self, that, f)
208
206
  ))
209
207
 
@@ -1772,10 +1772,10 @@ const existsLoop = <A, E, R>(
1772
1772
  if (next.done) {
1773
1773
  return core.succeed(false)
1774
1774
  }
1775
- return pipe(core.flatMap(
1775
+ return core.flatMap(
1776
1776
  f(next.value, index),
1777
1777
  (b) => b ? core.succeed(b) : existsLoop(iterator, index + 1, f)
1778
- ))
1778
+ )
1779
1779
  }
1780
1780
 
1781
1781
  /* @internal */
@@ -467,20 +467,18 @@ export const groupByKey = dual<
467
467
  ),
468
468
  onFailure: (cause) => core.fromEffect(Queue.offer(outerQueue, take.failCause(cause))),
469
469
  onDone: () =>
470
- pipe(
471
- core.fromEffect(
472
- pipe(
473
- Effect.forEach(map.entries(), ([_, innerQueue]) =>
474
- pipe(
475
- Queue.offer(innerQueue, take.end),
476
- Effect.catchSomeCause((cause) =>
477
- Cause.isInterruptedOnly(cause) ?
478
- Option.some(Effect.void) :
479
- Option.none()
480
- )
481
- ), { discard: true }),
482
- Effect.zipRight(Queue.offer(outerQueue, take.end))
483
- )
470
+ core.fromEffect(
471
+ pipe(
472
+ Effect.forEach(map.entries(), ([_, innerQueue]) =>
473
+ pipe(
474
+ Queue.offer(innerQueue, take.end),
475
+ Effect.catchSomeCause((cause) =>
476
+ Cause.isInterruptedOnly(cause) ?
477
+ Option.some(Effect.void) :
478
+ Option.none()
479
+ )
480
+ ), { discard: true }),
481
+ Effect.zipRight(Queue.offer(outerQueue, take.end))
484
482
  )
485
483
  )
486
484
  })
@@ -125,19 +125,17 @@ export const collectAllToMap = <In, K>(
125
125
  key: (input: In) => K,
126
126
  merge: (x: In, y: In) => In
127
127
  ): Sink.Sink<HashMap.HashMap<K, In>, In> => {
128
- return pipe(
129
- foldLeftChunks(HashMap.empty<K, In>(), (map, chunk) =>
130
- pipe(
131
- chunk,
132
- Chunk.reduce(map, (map, input) => {
133
- const k: K = key(input)
134
- const v: In = pipe(map, HashMap.has(k)) ?
135
- merge(pipe(map, HashMap.unsafeGet(k)), input) :
136
- input
137
- return pipe(map, HashMap.set(k, v))
138
- })
139
- ))
140
- )
128
+ return foldLeftChunks(HashMap.empty<K, In>(), (map, chunk) =>
129
+ pipe(
130
+ chunk,
131
+ Chunk.reduce(map, (map, input) => {
132
+ const k: K = key(input)
133
+ const v: In = pipe(map, HashMap.has(k)) ?
134
+ merge(pipe(map, HashMap.unsafeGet(k)), input) :
135
+ input
136
+ return pipe(map, HashMap.set(k, v))
137
+ })
138
+ ))
141
139
  }
142
140
 
143
141
  /** @internal */
@@ -698,7 +696,7 @@ export const contextWithEffect = <R0, A, E, R>(
698
696
  export const contextWithSink = <R0, A, In, L, E, R>(
699
697
  f: (context: Context.Context<R0>) => Sink.Sink<A, In, L, E, R>
700
698
  ): Sink.Sink<A, In, L, E, R0 | R> =>
701
- new SinkImpl(channel.unwrap(pipe(Effect.contextWith((context) => toChannel(f(context))))))
699
+ new SinkImpl(channel.unwrap(Effect.contextWith((context) => toChannel(f(context)))))
702
700
 
703
701
  /** @internal */
704
702
  export const every = <In>(predicate: Predicate<In>): Sink.Sink<boolean, In, In> =>
@@ -1487,7 +1485,7 @@ export const fromQueue = <In>(
1487
1485
  fromQueue
1488
1486
  )
1489
1487
  ) :
1490
- forEachChunk((input: Chunk.Chunk<In>) => pipe(Queue.offerAll(queue, input)))
1488
+ forEachChunk((input: Chunk.Chunk<In>) => Queue.offerAll(queue, input))
1491
1489
 
1492
1490
  /** @internal */
1493
1491
  export const head = <In>(): Sink.Sink<Option.Option<In>, In, In> =>
@@ -340,21 +340,19 @@ export const every = dual<
340
340
  iterable: Iterable<A>,
341
341
  predicate: (a: A) => STM.STM<boolean, E, R>
342
342
  ): STM.STM<boolean, E, R> =>
343
- pipe(
344
- core.flatMap(core.sync(() => iterable[Symbol.iterator]()), (iterator) => {
345
- const loop: STM.STM<boolean, E, R> = suspend(() => {
346
- const next = iterator.next()
347
- if (next.done) {
348
- return core.succeed(true)
349
- }
350
- return pipe(
351
- predicate(next.value),
352
- core.flatMap((bool) => bool ? loop : core.succeed(bool))
353
- )
354
- })
355
- return loop
343
+ core.flatMap(core.sync(() => iterable[Symbol.iterator]()), (iterator) => {
344
+ const loop: STM.STM<boolean, E, R> = suspend(() => {
345
+ const next = iterator.next()
346
+ if (next.done) {
347
+ return core.succeed(true)
348
+ }
349
+ return pipe(
350
+ predicate(next.value),
351
+ core.flatMap((bool) => bool ? loop : core.succeed(bool))
352
+ )
356
353
  })
357
- )
354
+ return loop
355
+ })
358
356
  )
359
357
 
360
358
  /** @internal */
@@ -1156,12 +1154,10 @@ export const repeatWhile = dual<
1156
1154
  >(2, (self, predicate) => repeatWhileLoop(self, predicate))
1157
1155
 
1158
1156
  const repeatWhileLoop = <A, E, R>(self: STM.STM<A, E, R>, predicate: Predicate<A>): STM.STM<A, E, R> =>
1159
- pipe(
1160
- core.flatMap(self, (a) =>
1161
- predicate(a) ?
1162
- repeatWhileLoop(self, predicate) :
1163
- core.succeed(a))
1164
- )
1157
+ core.flatMap(self, (a) =>
1158
+ predicate(a) ?
1159
+ repeatWhileLoop(self, predicate) :
1160
+ core.succeed(a))
1165
1161
 
1166
1162
  /** @internal */
1167
1163
  export const replicate = dual<
@@ -2016,7 +2016,7 @@ export const distributedWith = dual<
2016
2016
  )
2017
2017
  return pipe(
2018
2018
  Deferred.succeed(deferred, (a: A) =>
2019
- Effect.map(options.decide(a), (f) => (key: number) => pipe(f(mappings.get(key)!)))),
2019
+ Effect.map(options.decide(a), (f) => (key: number) => f(mappings.get(key)!))),
2020
2020
  Effect.as(
2021
2021
  Array.from(queues) as Types.TupleOf<N, Queue.Dequeue<Exit.Exit<A, Option.Option<E>>>>
2022
2022
  )
@@ -2143,14 +2143,12 @@ export const distributedWithDynamicCallback = dual<
2143
2143
  }),
2144
2144
  Effect.flatMap((ids) => {
2145
2145
  if (Chunk.isNonEmpty(ids)) {
2146
- return pipe(
2147
- Ref.update(queuesRef, (map) => {
2148
- for (const id of ids) {
2149
- map.delete(id)
2150
- }
2151
- return map
2152
- })
2153
- )
2146
+ return Ref.update(queuesRef, (map) => {
2147
+ for (const id of ids) {
2148
+ map.delete(id)
2149
+ }
2150
+ return map
2151
+ })
2154
2152
  }
2155
2153
  return Effect.void
2156
2154
  })
@@ -8374,21 +8372,17 @@ export const zipLatestWith: {
8374
8372
  mergeEither(repeatEffectOption(right)),
8375
8373
  mapEffectSequential(Either.match({
8376
8374
  onLeft: (leftChunk) =>
8377
- pipe(
8378
- Ref.modify(latest, ([_, rightLatest]) =>
8379
- [
8380
- pipe(leftChunk, Chunk.map((a) => f(a, rightLatest))),
8381
- [Chunk.unsafeLast(leftChunk), rightLatest] as const
8382
- ] as const)
8383
- ),
8375
+ Ref.modify(latest, ([_, rightLatest]) =>
8376
+ [
8377
+ pipe(leftChunk, Chunk.map((a) => f(a, rightLatest))),
8378
+ [Chunk.unsafeLast(leftChunk), rightLatest] as const
8379
+ ] as const),
8384
8380
  onRight: (rightChunk) =>
8385
- pipe(
8386
- Ref.modify(latest, ([leftLatest, _]) =>
8387
- [
8388
- pipe(rightChunk, Chunk.map((a2) => f(leftLatest, a2))),
8389
- [leftLatest, Chunk.unsafeLast(rightChunk)] as const
8390
- ] as const)
8391
- )
8381
+ Ref.modify(latest, ([leftLatest, _]) =>
8382
+ [
8383
+ pipe(rightChunk, Chunk.map((a2) => f(leftLatest, a2))),
8384
+ [leftLatest, Chunk.unsafeLast(rightChunk)] as const
8385
+ ] as const)
8392
8386
  })),
8393
8387
  flatMap(fromChunk)
8394
8388
  )
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.16.13"
1
+ let moduleVersion = "3.16.14"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4