effect 3.10.13 → 3.10.15

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.
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.10.13";
1
+ let moduleVersion = "3.10.15";
2
2
  export const getCurrentVersion = () => moduleVersion;
3
3
  export const setCurrentVersion = version => {
4
4
  moduleVersion = version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect",
3
- "version": "3.10.13",
3
+ "version": "3.10.15",
4
4
  "description": "The missing standard library for TypeScript, for writing production-grade software.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/DateTime.ts CHANGED
@@ -480,15 +480,21 @@ export const unsafeMake = <A extends DateTime.Input>(input: A): DateTime.Preserv
480
480
  *
481
481
  * DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" })
482
482
  */
483
- export const unsafeMakeZoned = (input: DateTime.Input, options: {
484
- readonly timeZone: number | string | TimeZone
483
+ export const unsafeMakeZoned = (input: DateTime.Input, options?: {
484
+ readonly timeZone?: number | string | TimeZone | undefined
485
485
  readonly adjustForTimeZone?: boolean | undefined
486
486
  }): Zoned => {
487
+ if (options?.timeZone === undefined && isDateTime(input) && isZoned(input)) {
488
+ return input
489
+ }
487
490
  const self = unsafeMake(input)
488
491
  let zone: TimeZone
489
- if (isTimeZone(options.timeZone)) {
492
+ if (options?.timeZone === undefined) {
493
+ const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000
494
+ zone = zoneMakeOffset(offset)
495
+ } else if (isTimeZone(options?.timeZone)) {
490
496
  zone = options.timeZone
491
- } else if (typeof options.timeZone === "number") {
497
+ } else if (typeof options?.timeZone === "number") {
492
498
  zone = zoneMakeOffset(options.timeZone)
493
499
  } else {
494
500
  const parsedZone = zoneFromString(options.timeZone)
@@ -497,7 +503,7 @@ export const unsafeMakeZoned = (input: DateTime.Input, options: {
497
503
  }
498
504
  zone = parsedZone.value
499
505
  }
500
- if (options.adjustForTimeZone !== true) {
506
+ if (options?.adjustForTimeZone !== true) {
501
507
  return makeZonedProto(self.epochMillis, zone, self.partsUtc)
502
508
  }
503
509
  return makeZonedFromAdjusted(self.epochMillis, zone)
@@ -519,12 +525,11 @@ export const unsafeMakeZoned = (input: DateTime.Input, options: {
519
525
  */
520
526
  export const makeZoned: (
521
527
  input: DateTime.Input,
522
- options: {
523
- readonly timeZone: number | string | TimeZone
528
+ options?: {
529
+ readonly timeZone?: number | string | TimeZone | undefined
524
530
  readonly adjustForTimeZone?: boolean | undefined
525
531
  }
526
- ) => Option.Option<Zoned> = Option
527
- .liftThrowable(unsafeMakeZoned)
532
+ ) => Option.Option<Zoned> = Option.liftThrowable(unsafeMakeZoned)
528
533
 
529
534
  /**
530
535
  * Create a `DateTime` from one of the following:
package/src/Schema.ts CHANGED
@@ -5443,7 +5443,7 @@ export const JsonNumberSchemaId: unique symbol = Symbol.for("effect/SchemaId/Jso
5443
5443
  * @since 3.10.0
5444
5444
  */
5445
5445
  export class JsonNumber extends Number$.pipe(
5446
- filter((n) => !Number.isNaN(n) && Number.isFinite(n), {
5446
+ filter(Number.isFinite, {
5447
5447
  schemaId: JsonNumberSchemaId,
5448
5448
  identifier: "JsonNumber",
5449
5449
  title: "JSON-compatible number",
package/src/Stream.ts CHANGED
@@ -8224,7 +8224,7 @@ export const someOrFail: {
8224
8224
  } = internal.someOrFail
8225
8225
 
8226
8226
  /**
8227
- * Splits elements based on a predicate.
8227
+ * Splits elements based on a predicate or refinement.
8228
8228
  *
8229
8229
  * ```ts
8230
8230
  * import * as Stream from "./Stream"
@@ -8243,7 +8243,28 @@ export const someOrFail: {
8243
8243
  */
8244
8244
  export const split: {
8245
8245
  /**
8246
- * Splits elements based on a predicate.
8246
+ * Splits elements based on a predicate or refinement.
8247
+ *
8248
+ * ```ts
8249
+ * import * as Stream from "./Stream"
8250
+ * import { pipe } from "./Function"
8251
+ *
8252
+ * pipe(
8253
+ * Stream.range(1, 10),
8254
+ * Stream.split((n) => n % 4 === 0),
8255
+ * Stream.runCollect
8256
+ * )
8257
+ * // => Chunk(Chunk(1, 2, 3), Chunk(5, 6, 7), Chunk(9))
8258
+ * ```
8259
+ *
8260
+ * @since 2.0.0
8261
+ * @category utils
8262
+ */
8263
+ <A, B extends A>(
8264
+ refinement: Refinement<NoInfer<A>, B>
8265
+ ): <E, R>(self: Stream<A, E, R>) => Stream<Chunk.Chunk<Exclude<A, B>>, E, R>
8266
+ /**
8267
+ * Splits elements based on a predicate or refinement.
8247
8268
  *
8248
8269
  * ```ts
8249
8270
  * import * as Stream from "./Stream"
@@ -8262,7 +8283,26 @@ export const split: {
8262
8283
  */
8263
8284
  <A>(predicate: Predicate<NoInfer<A>>): <E, R>(self: Stream<A, E, R>) => Stream<Chunk.Chunk<A>, E, R>
8264
8285
  /**
8265
- * Splits elements based on a predicate.
8286
+ * Splits elements based on a predicate or refinement.
8287
+ *
8288
+ * ```ts
8289
+ * import * as Stream from "./Stream"
8290
+ * import { pipe } from "./Function"
8291
+ *
8292
+ * pipe(
8293
+ * Stream.range(1, 10),
8294
+ * Stream.split((n) => n % 4 === 0),
8295
+ * Stream.runCollect
8296
+ * )
8297
+ * // => Chunk(Chunk(1, 2, 3), Chunk(5, 6, 7), Chunk(9))
8298
+ * ```
8299
+ *
8300
+ * @since 2.0.0
8301
+ * @category utils
8302
+ */
8303
+ <A, E, R, B extends A>(self: Stream<A, E, R>, refinement: Refinement<A, B>): Stream<Chunk.Chunk<Exclude<A, B>>, E, R>
8304
+ /**
8305
+ * Splits elements based on a predicate or refinement.
8266
8306
  *
8267
8307
  * ```ts
8268
8308
  * import * as Stream from "./Stream"
@@ -1,4 +1,3 @@
1
- import type { Mutable } from "effect/Types"
2
1
  import type * as Effect from "../Effect.js"
3
2
  import * as Effectable from "../Effectable.js"
4
3
  import type { Exit } from "../Exit.js"
@@ -9,6 +8,7 @@ import { pipeArguments } from "../Pipeable.js"
9
8
  import { hasProperty } from "../Predicate.js"
10
9
  import type * as Runtime from "../Runtime.js"
11
10
  import * as Scope from "../Scope.js"
11
+ import type { Mutable } from "../Types.js"
12
12
  import * as core from "./core.js"
13
13
  import * as fiberRuntime from "./fiberRuntime.js"
14
14
  import * as internalLayer from "./layer.js"
@@ -57,19 +57,21 @@ export const make = <R, ER>(
57
57
  memoMap = memoMap ?? internalLayer.unsafeMakeMemoMap()
58
58
  const scope = internalRuntime.unsafeRunSyncEffect(fiberRuntime.scopeMake())
59
59
  let buildFiber: Fiber.RuntimeFiber<Runtime.Runtime<R>, ER> | undefined
60
- const runtimeEffect = core.suspend(() => {
61
- buildFiber ??= internalRuntime.unsafeForkEffect(
62
- core.tap(
63
- Scope.extend(
64
- internalLayer.toRuntimeWithMemoMap(layer, memoMap),
65
- scope
60
+ const runtimeEffect = core.withFiberRuntime<Runtime.Runtime<R>, ER>((fiber) => {
61
+ if (!buildFiber) {
62
+ buildFiber = internalRuntime.unsafeForkEffect(
63
+ core.tap(
64
+ Scope.extend(
65
+ internalLayer.toRuntimeWithMemoMap(layer, memoMap),
66
+ scope
67
+ ),
68
+ (rt) => {
69
+ self.cachedRuntime = rt
70
+ }
66
71
  ),
67
- (rt) => {
68
- self.cachedRuntime = rt
69
- }
70
- ),
71
- { scope }
72
- )
72
+ { scope, scheduler: fiber.currentScheduler }
73
+ )
74
+ }
73
75
  return core.flatten(buildFiber.await)
74
76
  })
75
77
  const self: ManagedRuntimeImpl<R, ER> = Object.assign(Object.create(ManagedRuntimeProto), {
@@ -6189,44 +6189,59 @@ export const slidingSize = dual<
6189
6189
  )
6190
6190
 
6191
6191
  /** @internal */
6192
- export const split = dual<
6193
- <A>(predicate: Predicate<NoInfer<A>>) => <E, R>(self: Stream.Stream<A, E, R>) => Stream.Stream<Chunk.Chunk<A>, E, R>,
6194
- <A, E, R>(self: Stream.Stream<A, E, R>, predicate: Predicate<A>) => Stream.Stream<Chunk.Chunk<A>, E, R>
6195
- >(2, <A, E, R>(self: Stream.Stream<A, E, R>, predicate: Predicate<A>): Stream.Stream<Chunk.Chunk<A>, E, R> => {
6196
- const split = (
6197
- leftovers: Chunk.Chunk<A>,
6198
- input: Chunk.Chunk<A>
6199
- ): Channel.Channel<Chunk.Chunk<Chunk.Chunk<A>>, Chunk.Chunk<A>, E, E, unknown, unknown, R> => {
6200
- const [chunk, remaining] = pipe(leftovers, Chunk.appendAll(input), Chunk.splitWhere(predicate))
6201
- if (Chunk.isEmpty(chunk) || Chunk.isEmpty(remaining)) {
6202
- return loop(pipe(chunk, Chunk.appendAll(pipe(remaining, Chunk.drop(1)))))
6192
+ export const split: {
6193
+ <A, B extends A>(
6194
+ refinement: Refinement<NoInfer<A>, B>
6195
+ ): <E, R>(self: Stream.Stream<A, E, R>) => Stream.Stream<Chunk.Chunk<Exclude<A, B>>, E, R>
6196
+ <A>(
6197
+ predicate: Predicate<NoInfer<A>>
6198
+ ): <E, R>(self: Stream.Stream<A, E, R>) => Stream.Stream<Chunk.Chunk<A>, E, R>
6199
+ <A, E, R, B extends A>(
6200
+ self: Stream.Stream<A, E, R>,
6201
+ refinement: Refinement<A, B>
6202
+ ): Stream.Stream<Chunk.Chunk<Exclude<A, B>>, E, R>
6203
+ <A, E, R>(self: Stream.Stream<A, E, R>, predicate: Predicate<A>): Stream.Stream<Chunk.Chunk<A>, E, R>
6204
+ } = dual(
6205
+ 2,
6206
+ <A, E, R>(
6207
+ self: Stream.Stream<A, E, R>,
6208
+ predicate: Predicate<A>
6209
+ ): Stream.Stream<Chunk.Chunk<A>, E, R> => {
6210
+ const split = (
6211
+ leftovers: Chunk.Chunk<A>,
6212
+ input: Chunk.Chunk<A>
6213
+ ): Channel.Channel<Chunk.Chunk<Chunk.Chunk<A>>, Chunk.Chunk<A>, E, E, unknown, unknown, R> => {
6214
+ const [chunk, remaining] = pipe(leftovers, Chunk.appendAll(input), Chunk.splitWhere(predicate))
6215
+ if (Chunk.isEmpty(chunk) || Chunk.isEmpty(remaining)) {
6216
+ return loop(pipe(chunk, Chunk.appendAll(pipe(remaining, Chunk.drop(1)))))
6217
+ }
6218
+ return pipe(
6219
+ core.write(Chunk.of(chunk)),
6220
+ core.flatMap(() => split(Chunk.empty(), pipe(remaining, Chunk.drop(1))))
6221
+ )
6203
6222
  }
6204
- return pipe(
6205
- core.write(Chunk.of(chunk)),
6206
- core.flatMap(() => split(Chunk.empty(), pipe(remaining, Chunk.drop(1))))
6207
- )
6208
- }
6209
- const loop = (
6210
- leftovers: Chunk.Chunk<A>
6211
- ): Channel.Channel<Chunk.Chunk<Chunk.Chunk<A>>, Chunk.Chunk<A>, E, E, unknown, unknown, R> =>
6212
- core.readWith({
6213
- onInput: (input: Chunk.Chunk<A>) => split(leftovers, input),
6214
- onFailure: core.fail,
6215
- onDone: () => {
6216
- if (Chunk.isEmpty(leftovers)) {
6217
- return core.void
6218
- }
6219
- if (Option.isNone(pipe(leftovers, Chunk.findFirst(predicate)))) {
6220
- return channel.zipRight(core.write(Chunk.of(leftovers)), core.void)
6223
+ const loop = (
6224
+ leftovers: Chunk.Chunk<A>
6225
+ ): Channel.Channel<Chunk.Chunk<Chunk.Chunk<A>>, Chunk.Chunk<A>, E, E, unknown, unknown, R> =>
6226
+ core.readWith({
6227
+ onInput: (input: Chunk.Chunk<A>) => split(leftovers, input),
6228
+ onFailure: core.fail,
6229
+ onDone: () => {
6230
+ if (Chunk.isEmpty(leftovers)) {
6231
+ return core.void
6232
+ }
6233
+ if (Option.isNone(pipe(leftovers, Chunk.findFirst(predicate)))) {
6234
+ return channel.zipRight(core.write(Chunk.of(leftovers)), core.void)
6235
+ }
6236
+ return channel.zipRight(
6237
+ split(Chunk.empty(), leftovers),
6238
+ core.void
6239
+ )
6221
6240
  }
6222
- return channel.zipRight(
6223
- split(Chunk.empty(), leftovers),
6224
- core.void
6225
- )
6226
- }
6227
- })
6228
- return new StreamImpl(pipe(toChannel(self), core.pipeTo(loop(Chunk.empty()))))
6229
- })
6241
+ })
6242
+ return new StreamImpl(pipe(toChannel(self), core.pipeTo(loop(Chunk.empty()))))
6243
+ }
6244
+ )
6230
6245
 
6231
6246
  /** @internal */
6232
6247
  export const splitOnChunk = dual<
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.10.13"
1
+ let moduleVersion = "3.10.15"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4