From c2b6229c94386cbf440a7a445aa5d1bfef5e04ec Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 18 Jul 2025 22:39:10 +1200 Subject: [PATCH] categorize effect modules (#315) --- .specs/CLAUDE-lite.md | 360 +++ .specs/categorization/examples-plan.md | 103 + .specs/categorization/plan.md | 246 +++ bundle/batching.ts | 2 +- bundle/metric.ts | 2 +- bundle/pubsub.ts | 2 +- bundle/queue.ts | 2 +- bundle/schedule.ts | 2 +- bundle/schema-string-async.ts | 2 +- bundle/stm.ts | 2 +- bundle/stream.ts | 2 +- deno.json | 9 +- packages/effect/SCHEMA.md | 30 +- .../effect/benchmark/schema/tagged-union.ts | 2 +- packages/effect/dtslint/Option.tst.ts | 5 +- packages/effect/dtslint/Struct.tst.ts | 4 +- packages/effect/dtslint/Tuple.tst.ts | 3 +- packages/effect/dtslint/schema/Check.tst.ts | 2 +- packages/effect/dtslint/schema/Schema.tst.ts | 22 +- packages/effect/package.json | 36 + packages/effect/src/Cause.ts | 22 +- packages/effect/src/Effect.ts | 353 ++- packages/effect/src/Exit.ts | 4 +- packages/effect/src/Function.ts | 17 +- packages/effect/src/Utils.ts | 24 +- packages/effect/src/batching/Request.ts | 14 +- .../effect/src/batching/RequestResolver.ts | 100 +- packages/effect/src/caching/Cache.ts | 161 +- .../effect/src/{ => collections}/Array.ts | 338 +-- .../effect/src/{ => collections}/Chunk.ts | 244 ++- .../effect/src/{ => collections}/Graph.ts | 133 +- .../effect/src/{ => collections}/HashMap.ts | 118 +- .../effect/src/{ => collections}/HashSet.ts | 62 +- .../effect/src/{ => collections}/Iterable.ts | 128 +- .../src/{ => collections}/MutableHashMap.ts | 48 +- .../src/{ => collections}/MutableHashSet.ts | 30 +- .../src/{ => collections}/MutableList.ts | 38 +- .../src/{ => collections}/NonEmptyIterable.ts | 22 +- .../effect/src/{ => collections}/Symbol.ts | 8 +- packages/effect/src/{ => collections}/Trie.ts | 89 +- packages/effect/src/collections/index.ts | 373 ++++ packages/effect/src/collections/index.ts.tpl | 3 + .../effect/src/{ => concurrency}/Deferred.ts | 88 +- .../src/{ => concurrency}/FiberHandle.ts | 87 +- .../effect/src/{ => concurrency}/FiberMap.ts | 113 +- .../effect/src/{ => concurrency}/FiberSet.ts | 75 +- .../src/{ => concurrency}/MutableRef.ts | 46 +- .../effect/src/{ => concurrency}/PubSub.ts | 142 +- .../effect/src/{ => concurrency}/Queue.ts | 132 +- packages/effect/src/{ => concurrency}/Ref.ts | 82 +- packages/effect/src/concurrency/index.ts | 228 ++ packages/effect/src/concurrency/index.ts.tpl | 3 + packages/effect/src/config/Config.ts | 63 +- packages/effect/src/config/ConfigError.ts | 6 +- packages/effect/src/config/ConfigProvider.ts | 16 +- packages/effect/src/{ => data}/Brand.ts | 50 +- packages/effect/src/{ => data}/Data.ts | 76 +- packages/effect/src/{ => data}/Equivalence.ts | 51 +- packages/effect/src/{ => data}/Filter.ts | 40 +- packages/effect/src/{ => data}/Option.ts | 189 +- packages/effect/src/{ => data}/Order.ts | 63 +- packages/effect/src/{ => data}/Ordering.ts | 16 +- packages/effect/src/{ => data}/Predicate.ts | 135 +- packages/effect/src/{ => data}/Record.ts | 200 +- packages/effect/src/{ => data}/Redacted.ts | 39 +- packages/effect/src/{ => data}/Result.ts | 155 +- packages/effect/src/{ => data}/Struct.ts | 66 +- packages/effect/src/{ => data}/Tuple.ts | 62 +- packages/effect/src/data/index.ts | 212 ++ packages/effect/src/data/index.ts.tpl | 3 + .../effect/src/{ => encoding}/Encoding.ts | 45 +- packages/effect/src/encoding/index.ts | 14 + packages/effect/src/encoding/index.ts.tpl | 3 + packages/effect/src/index.ts | 1934 +---------------- packages/effect/src/{ => interfaces}/Equal.ts | 17 +- packages/effect/src/{ => interfaces}/Hash.ts | 30 +- .../src/{ => interfaces}/Inspectable.ts | 35 +- .../effect/src/{ => interfaces}/Pipeable.ts | 2 +- .../effect/src/{ => interfaces}/PrimaryKey.ts | 6 +- packages/effect/src/interfaces/index.ts | 81 + packages/effect/src/interfaces/index.ts.tpl | 3 + packages/effect/src/internal/array.ts | 2 +- packages/effect/src/internal/concurrency.ts | 4 +- packages/effect/src/internal/core.ts | 16 +- packages/effect/src/internal/data.ts | 6 +- packages/effect/src/internal/dateTime.ts | 26 +- packages/effect/src/internal/doNotation.ts | 4 +- packages/effect/src/internal/effect.ts | 46 +- .../effect/src/internal/encoding/base64.ts | 4 +- .../effect/src/internal/encoding/base64Url.ts | 4 +- .../effect/src/internal/encoding/common.ts | 6 +- packages/effect/src/internal/encoding/hex.ts | 4 +- packages/effect/src/internal/hashMap.ts | 18 +- packages/effect/src/internal/hashSet.ts | 14 +- packages/effect/src/internal/layer.ts | 4 +- packages/effect/src/internal/matcher.ts | 12 +- packages/effect/src/internal/option.ts | 10 +- packages/effect/src/internal/rcRef.ts | 10 +- packages/effect/src/internal/redacted.ts | 2 +- packages/effect/src/internal/request.ts | 4 +- packages/effect/src/internal/result.ts | 12 +- packages/effect/src/internal/schedule.ts | 8 +- packages/effect/src/internal/schema/util.ts | 6 +- packages/effect/src/internal/tracer.ts | 2 +- .../src/internal/tracing/otlpExporter.ts | 12 +- packages/effect/src/internal/trie.ts | 18 +- packages/effect/src/{ => logging}/Console.ts | 83 +- packages/effect/src/{ => logging}/LogLevel.ts | 34 +- packages/effect/src/{ => logging}/Logger.ts | 134 +- packages/effect/src/logging/index.ts | 293 +++ packages/effect/src/logging/index.ts.tpl | 3 + packages/effect/src/{ => match}/Match.ts | 143 +- packages/effect/src/match/index.ts | 33 + packages/effect/src/match/index.ts.tpl | 3 + .../effect/src/{ => observability}/Metric.ts | 255 ++- .../effect/src/{ => observability}/Tracer.ts | 54 +- packages/effect/src/observability/index.ts | 152 ++ .../effect/src/observability/index.ts.tpl | 3 + packages/effect/src/platform/FileSystem.ts | 49 +- packages/effect/src/platform/Path.ts | 7 +- packages/effect/src/platform/PlatformError.ts | 2 +- packages/effect/src/platform/index.ts | 3 +- .../effect/src/{ => primitives}/BigDecimal.ts | 106 +- .../effect/src/{ => primitives}/BigInt.ts | 83 +- .../effect/src/{ => primitives}/Boolean.ts | 40 +- .../effect/src/{ => primitives}/Number.ts | 72 +- .../effect/src/{ => primitives}/RegExp.ts | 8 +- .../effect/src/{ => primitives}/String.ts | 170 +- packages/effect/src/primitives/index.ts | 63 + packages/effect/src/primitives/index.ts.tpl | 3 + .../effect/src/{ => resources}/LayerMap.ts | 71 +- packages/effect/src/{ => resources}/RcMap.ts | 61 +- packages/effect/src/{ => resources}/RcRef.ts | 27 +- packages/effect/src/{ => resources}/Scope.ts | 70 +- packages/effect/src/resources/index.ts | 36 + packages/effect/src/resources/index.ts.tpl | 3 + packages/effect/src/{ => runtime}/Fiber.ts | 69 +- .../src/{ => runtime}/ManagedRuntime.ts | 22 +- packages/effect/src/{ => runtime}/Runtime.ts | 16 +- .../effect/src/{ => runtime}/Scheduler.ts | 13 +- packages/effect/src/runtime/index.ts | 123 ++ packages/effect/src/runtime/index.ts.tpl | 3 + .../effect/src/{ => scheduling}/Schedule.ts | 221 +- packages/effect/src/scheduling/index.ts | 38 + packages/effect/src/scheduling/index.ts.tpl | 3 + packages/effect/src/schema/AST.ts | 10 +- packages/effect/src/schema/Annotations.ts | 2 +- packages/effect/src/schema/Check.ts | 14 +- packages/effect/src/schema/Formatter.ts | 16 +- packages/effect/src/schema/Getter.ts | 6 +- packages/effect/src/schema/Issue.ts | 4 +- packages/effect/src/schema/MetaAST.ts | 44 +- packages/effect/src/schema/Schema.ts | 58 +- packages/effect/src/schema/Serializer.ts | 6 +- packages/effect/src/schema/ToArbitrary.ts | 8 +- packages/effect/src/schema/ToEquivalence.ts | 6 +- packages/effect/src/schema/ToJsonSchema.ts | 52 +- packages/effect/src/schema/ToParser.ts | 6 +- packages/effect/src/schema/ToPretty.ts | 2 +- packages/effect/src/schema/Transformation.ts | 2 +- packages/effect/src/schema/index.ts | 2 +- packages/effect/src/schema/index.ts.tpl | 2 +- packages/effect/src/{ => services}/Layer.ts | 146 +- .../effect/src/{ => services}/References.ts | 49 +- .../effect/src/{ => services}/ServiceMap.ts | 93 +- packages/effect/src/services/index.ts | 49 + packages/effect/src/services/index.ts.tpl | 3 + packages/effect/src/{ => stream}/Channel.ts | 313 ++- packages/effect/src/{ => stream}/Pull.ts | 68 +- packages/effect/src/{ => stream}/Sink.ts | 82 +- packages/effect/src/{ => stream}/Stream.ts | 280 ++- packages/effect/src/stream/index.ts | 80 + packages/effect/src/stream/index.ts.tpl | 3 + .../effect/src/{ => testing}/FastCheck.ts | 6 +- .../effect/src/{ => testing}/TestClock.ts | 55 +- .../effect/src/{ => testing}/TestConsole.ts | 39 +- packages/effect/src/testing/index.ts | 26 + packages/effect/src/testing/index.ts.tpl | 3 + packages/effect/src/{ => time}/Clock.ts | 30 +- packages/effect/src/{ => time}/Cron.ts | 71 +- packages/effect/src/{ => time}/DateTime.ts | 274 +-- packages/effect/src/{ => time}/Duration.ts | 129 +- packages/effect/src/time/index.ts | 124 ++ packages/effect/src/time/index.ts.tpl | 3 + .../effect/src/{ => transactions}/TxChunk.ts | 105 +- .../src/{ => transactions}/TxHashMap.ts | 163 +- .../src/{ => transactions}/TxHashSet.ts | 101 +- .../effect/src/{ => transactions}/TxQueue.ts | 144 +- .../effect/src/{ => transactions}/TxRef.ts | 30 +- .../src/{ => transactions}/TxSemaphore.ts | 71 +- packages/effect/src/transactions/index.ts | 56 + packages/effect/src/transactions/index.ts.tpl | 3 + packages/effect/src/{ => types}/HKT.ts | 15 +- packages/effect/src/{ => types}/Types.ts | 58 +- packages/effect/src/{ => types}/Unify.ts | 18 +- packages/effect/src/types/index.ts | 50 + packages/effect/src/types/index.ts.tpl | 3 + packages/effect/src/unstable/http/Cookies.ts | 20 +- packages/effect/src/unstable/http/Etag.ts | 4 +- .../src/unstable/http/FetchHttpClient.ts | 6 +- packages/effect/src/unstable/http/Headers.ts | 24 +- packages/effect/src/unstable/http/HttpBody.ts | 8 +- .../effect/src/unstable/http/HttpClient.ts | 30 +- .../src/unstable/http/HttpClientError.ts | 4 +- .../src/unstable/http/HttpClientRequest.ts | 14 +- .../src/unstable/http/HttpClientResponse.ts | 8 +- .../effect/src/unstable/http/HttpEffect.ts | 12 +- .../src/unstable/http/HttpIncomingMessage.ts | 10 +- .../src/unstable/http/HttpMiddleware.ts | 10 +- .../effect/src/unstable/http/HttpPlatform.ts | 6 +- .../effect/src/unstable/http/HttpRouter.ts | 34 +- .../effect/src/unstable/http/HttpServer.ts | 6 +- .../src/unstable/http/HttpServerError.ts | 8 +- .../src/unstable/http/HttpServerRequest.ts | 16 +- .../unstable/http/HttpServerRespondable.ts | 2 +- .../src/unstable/http/HttpServerResponse.ts | 12 +- .../src/unstable/http/HttpTraceContext.ts | 4 +- .../effect/src/unstable/http/Multipart.ts | 20 +- packages/effect/src/unstable/http/Template.ts | 4 +- .../effect/src/unstable/http/UrlParams.ts | 28 +- packages/effect/src/unstable/socket/Socket.ts | 26 +- .../src/unstable/socket/SocketServer.ts | 4 +- packages/effect/src/unstable/tracing/Otlp.ts | 6 +- .../effect/src/unstable/tracing/OtlpLogger.ts | 14 +- .../src/unstable/tracing/OtlpMetrics.ts | 12 +- .../src/unstable/tracing/OtlpResource.ts | 2 +- .../effect/src/unstable/tracing/OtlpTracer.ts | 14 +- packages/effect/test/Channel.test.ts | 6 +- packages/effect/test/Deferred.test.ts | 4 +- packages/effect/test/Duration.test.ts | 4 +- packages/effect/test/Effect.test.ts | 17 +- packages/effect/test/EffectEager.test.ts | 7 +- packages/effect/test/Fiber.test.ts | 4 +- packages/effect/test/FiberHandle.test.ts | 5 +- packages/effect/test/FiberMap.test.ts | 7 +- packages/effect/test/FiberSet.test.ts | 7 +- packages/effect/test/Graph.test.ts | 7 +- packages/effect/test/HashMap.test.ts | 7 +- packages/effect/test/HashSet.test.ts | 5 +- packages/effect/test/HttpClient.test.ts | 6 +- packages/effect/test/Layer.test.ts | 8 +- packages/effect/test/Logger.test.ts | 6 +- packages/effect/test/ManagedRuntime.test.ts | 4 +- packages/effect/test/Metric.test.ts | 12 +- packages/effect/test/PubSub.test.ts | 6 +- packages/effect/test/Queue.test.ts | 5 +- packages/effect/test/RcMap.test.ts | 5 +- packages/effect/test/RcRef.test.ts | 4 +- packages/effect/test/Record.test.ts | 2 +- packages/effect/test/Redacted.test.ts | 4 +- packages/effect/test/Ref.test.ts | 4 +- packages/effect/test/Result.test.ts | 6 +- packages/effect/test/Schedule.test.ts | 8 +- packages/effect/test/Scope.test.ts | 5 +- packages/effect/test/Stream.test.ts | 6 +- packages/effect/test/Struct.test.ts | 4 +- packages/effect/test/TestClock.test.ts | 4 +- packages/effect/test/Tuple.test.ts | 3 +- packages/effect/test/TxChunk.test.ts | 4 +- packages/effect/test/TxHashMap.test.ts | 8 +- packages/effect/test/TxHashSet.test.ts | 7 +- packages/effect/test/TxQueue.test.ts | 8 +- packages/effect/test/TxSemaphore.test.ts | 4 +- packages/effect/test/batching/Request.test.ts | 8 +- packages/effect/test/caching/Cache.test.ts | 13 +- packages/effect/test/config/Config.test.ts | 6 +- .../effect/test/config/ConfigProvider.test.ts | 4 +- packages/effect/test/http/Multipart.test.ts | 4 +- packages/effect/test/schema/Formatter.test.ts | 13 +- packages/effect/test/schema/Schema.test.ts | 35 +- .../effect/test/schema/Serializer.test.ts | 2 +- .../effect/test/schema/ToEquivalence.test.ts | 2 +- .../effect/test/schema/ToJsonSchema.test.ts | 22 +- packages/effect/test/schema/ToPretty.test.ts | 2 +- .../test/schema/standardSchemaV1.test.ts | 4 +- packages/effect/test/utils/assert.ts | 4 +- packages/effect/test/utils/schema.ts | 6 +- packages/platform-bun/src/BunFileSystem.ts | 4 +- packages/platform-bun/src/BunHttpPlatform.ts | 2 +- packages/platform-bun/src/BunHttpServer.ts | 22 +- packages/platform-bun/src/BunMultipart.ts | 4 +- packages/platform-bun/src/BunPath.ts | 8 +- packages/platform-bun/src/BunRuntime.ts | 2 +- packages/platform-bun/src/BunServices.ts | 2 +- packages/platform-bun/src/BunSocket.ts | 2 +- packages/platform-bun/src/BunStream.ts | 10 +- .../src/NodeFileSystem.ts | 8 +- packages/platform-node-shared/src/NodePath.ts | 2 +- .../platform-node-shared/src/NodeRuntime.ts | 15 +- packages/platform-node-shared/src/NodeSink.ts | 8 +- .../platform-node-shared/src/NodeSocket.ts | 18 +- .../src/NodeSocketServer.ts | 12 +- .../platform-node-shared/src/NodeStream.ts | 21 +- .../test/NodeFileSystem.test.ts | 4 +- .../test/NodeSink.test.ts | 8 +- .../test/NodeStream.test.ts | 7 +- packages/platform-node/src/NodeFileSystem.ts | 4 +- packages/platform-node/src/NodeHttpClient.ts | 12 +- .../src/NodeHttpIncomingMessage.ts | 6 +- .../platform-node/src/NodeHttpPlatform.ts | 2 +- packages/platform-node/src/NodeHttpServer.ts | 14 +- packages/platform-node/src/NodeMultipart.ts | 6 +- packages/platform-node/src/NodePath.ts | 8 +- packages/platform-node/src/NodeRuntime.ts | 6 +- packages/platform-node/src/NodeServices.ts | 2 +- packages/platform-node/src/NodeSocket.ts | 2 +- .../platform-node/test/NodeHttpClient.test.ts | 8 +- .../platform-node/test/NodeHttpServer.test.ts | 10 +- .../platform-node/test/NodeSocket.test.ts | 5 +- packages/vitest/src/index.ts | 11 +- packages/vitest/src/internal/internal.ts | 18 +- packages/vitest/src/utils.ts | 8 +- packages/vitest/test/index.test.ts | 6 +- scripts/codemods/ts-fence.test.ts | 2 +- 314 files changed, 8531 insertions(+), 6048 deletions(-) create mode 100644 .specs/CLAUDE-lite.md create mode 100644 .specs/categorization/examples-plan.md create mode 100644 .specs/categorization/plan.md rename packages/effect/src/{ => collections}/Array.ts (92%) rename packages/effect/src/{ => collections}/Chunk.ts (92%) rename packages/effect/src/{ => collections}/Graph.ts (96%) rename packages/effect/src/{ => collections}/HashMap.ts (89%) rename packages/effect/src/{ => collections}/HashSet.ts (89%) rename packages/effect/src/{ => collections}/Iterable.ts (95%) rename packages/effect/src/{ => collections}/MutableHashMap.ts (92%) rename packages/effect/src/{ => collections}/MutableHashSet.ts (92%) rename packages/effect/src/{ => collections}/MutableList.ts (94%) rename packages/effect/src/{ => collections}/NonEmptyIterable.ts (91%) rename packages/effect/src/{ => collections}/Symbol.ts (84%) rename packages/effect/src/{ => collections}/Trie.ts (89%) create mode 100644 packages/effect/src/collections/index.ts create mode 100644 packages/effect/src/collections/index.ts.tpl rename packages/effect/src/{ => concurrency}/Deferred.ts (88%) rename packages/effect/src/{ => concurrency}/FiberHandle.ts (88%) rename packages/effect/src/{ => concurrency}/FiberMap.ts (88%) rename packages/effect/src/{ => concurrency}/FiberSet.ts (89%) rename packages/effect/src/{ => concurrency}/MutableRef.ts (94%) rename packages/effect/src/{ => concurrency}/PubSub.ts (95%) rename packages/effect/src/{ => concurrency}/Queue.ts (92%) rename packages/effect/src/{ => concurrency}/Ref.ts (90%) create mode 100644 packages/effect/src/concurrency/index.ts create mode 100644 packages/effect/src/concurrency/index.ts.tpl rename packages/effect/src/{ => data}/Brand.ts (93%) rename packages/effect/src/{ => data}/Data.ts (93%) rename packages/effect/src/{ => data}/Equivalence.ts (95%) rename packages/effect/src/{ => data}/Filter.ts (96%) rename packages/effect/src/{ => data}/Option.ts (94%) rename packages/effect/src/{ => data}/Order.ts (94%) rename packages/effect/src/{ => data}/Ordering.ts (96%) rename packages/effect/src/{ => data}/Predicate.ts (92%) rename packages/effect/src/{ => data}/Record.ts (86%) rename packages/effect/src/{ => data}/Redacted.ts (86%) rename packages/effect/src/{ => data}/Result.ts (91%) rename packages/effect/src/{ => data}/Struct.ts (90%) rename packages/effect/src/{ => data}/Tuple.ts (90%) create mode 100644 packages/effect/src/data/index.ts create mode 100644 packages/effect/src/data/index.ts.tpl rename packages/effect/src/{ => encoding}/Encoding.ts (84%) create mode 100644 packages/effect/src/encoding/index.ts create mode 100644 packages/effect/src/encoding/index.ts.tpl rename packages/effect/src/{ => interfaces}/Equal.ts (90%) rename packages/effect/src/{ => interfaces}/Hash.ts (94%) rename packages/effect/src/{ => interfaces}/Inspectable.ts (93%) rename packages/effect/src/{ => interfaces}/Pipeable.ts (99%) rename packages/effect/src/{ => interfaces}/PrimaryKey.ts (93%) create mode 100644 packages/effect/src/interfaces/index.ts create mode 100644 packages/effect/src/interfaces/index.ts.tpl rename packages/effect/src/{ => logging}/Console.ts (89%) rename packages/effect/src/{ => logging}/LogLevel.ts (91%) rename packages/effect/src/{ => logging}/Logger.ts (90%) create mode 100644 packages/effect/src/logging/index.ts create mode 100644 packages/effect/src/logging/index.ts.tpl rename packages/effect/src/{ => match}/Match.ts (96%) create mode 100644 packages/effect/src/match/index.ts create mode 100644 packages/effect/src/match/index.ts.tpl rename packages/effect/src/{ => observability}/Metric.ts (94%) rename packages/effect/src/{ => observability}/Tracer.ts (87%) create mode 100644 packages/effect/src/observability/index.ts create mode 100644 packages/effect/src/observability/index.ts.tpl rename packages/effect/src/{ => primitives}/BigDecimal.ts (91%) rename packages/effect/src/{ => primitives}/BigInt.ts (87%) rename packages/effect/src/{ => primitives}/Boolean.ts (88%) rename packages/effect/src/{ => primitives}/Number.ts (86%) rename packages/effect/src/{ => primitives}/RegExp.ts (86%) rename packages/effect/src/{ => primitives}/String.ts (87%) create mode 100644 packages/effect/src/primitives/index.ts create mode 100644 packages/effect/src/primitives/index.ts.tpl rename packages/effect/src/{ => resources}/LayerMap.ts (88%) rename packages/effect/src/{ => resources}/RcMap.ts (91%) rename packages/effect/src/{ => resources}/RcRef.ts (86%) rename packages/effect/src/{ => resources}/Scope.ts (86%) create mode 100644 packages/effect/src/resources/index.ts create mode 100644 packages/effect/src/resources/index.ts.tpl rename packages/effect/src/{ => runtime}/Fiber.ts (87%) rename packages/effect/src/{ => runtime}/ManagedRuntime.ts (92%) rename packages/effect/src/{ => runtime}/Runtime.ts (93%) rename packages/effect/src/{ => runtime}/Scheduler.ts (95%) create mode 100644 packages/effect/src/runtime/index.ts create mode 100644 packages/effect/src/runtime/index.ts.tpl rename packages/effect/src/{ => scheduling}/Schedule.ts (93%) create mode 100644 packages/effect/src/scheduling/index.ts create mode 100644 packages/effect/src/scheduling/index.ts.tpl rename packages/effect/src/{ => services}/Layer.ts (91%) rename packages/effect/src/{ => services}/References.ts (90%) rename packages/effect/src/{ => services}/ServiceMap.ts (91%) create mode 100644 packages/effect/src/services/index.ts create mode 100644 packages/effect/src/services/index.ts.tpl rename packages/effect/src/{ => stream}/Channel.ts (92%) rename packages/effect/src/{ => stream}/Pull.ts (87%) rename packages/effect/src/{ => stream}/Sink.ts (82%) rename packages/effect/src/{ => stream}/Stream.ts (89%) create mode 100644 packages/effect/src/stream/index.ts create mode 100644 packages/effect/src/stream/index.ts.tpl rename packages/effect/src/{ => testing}/FastCheck.ts (93%) rename packages/effect/src/{ => testing}/TestClock.ts (90%) rename packages/effect/src/{ => testing}/TestConsole.ts (87%) create mode 100644 packages/effect/src/testing/index.ts create mode 100644 packages/effect/src/testing/index.ts.tpl rename packages/effect/src/{ => time}/Clock.ts (86%) rename packages/effect/src/{ => time}/Cron.ts (93%) rename packages/effect/src/{ => time}/DateTime.ts (91%) rename packages/effect/src/{ => time}/Duration.ts (92%) create mode 100644 packages/effect/src/time/index.ts create mode 100644 packages/effect/src/time/index.ts.tpl rename packages/effect/src/{ => transactions}/TxChunk.ts (87%) rename packages/effect/src/{ => transactions}/TxHashMap.ts (92%) rename packages/effect/src/{ => transactions}/TxHashSet.ts (89%) rename packages/effect/src/{ => transactions}/TxQueue.ts (91%) rename packages/effect/src/{ => transactions}/TxRef.ts (89%) rename packages/effect/src/{ => transactions}/TxSemaphore.ts (88%) create mode 100644 packages/effect/src/transactions/index.ts create mode 100644 packages/effect/src/transactions/index.ts.tpl rename packages/effect/src/{ => types}/HKT.ts (94%) rename packages/effect/src/{ => types}/Types.ts (90%) rename packages/effect/src/{ => types}/Unify.ts (95%) create mode 100644 packages/effect/src/types/index.ts create mode 100644 packages/effect/src/types/index.ts.tpl diff --git a/.specs/CLAUDE-lite.md b/.specs/CLAUDE-lite.md new file mode 100644 index 0000000000..0feb502d2e --- /dev/null +++ b/.specs/CLAUDE-lite.md @@ -0,0 +1,360 @@ +# Claude Instructions + +## Project Overview + +This is the Effect library repository, focusing on functional programming patterns and effect systems in TypeScript. + +## 🚨 HIGHEST PRIORITY RULES 🚨 + +### ABSOLUTELY FORBIDDEN: try-catch in Effect.gen + +**NEVER use `try-catch` blocks inside `Effect.gen` generators!** + +- Effect generators handle errors through the Effect type system, not JavaScript exceptions +- Use `Effect.tryPromise`, `Effect.try`, or proper Effect error handling instead +- **CRITICAL**: This will cause runtime errors and break Effect's error handling +- **EXAMPLE OF WHAT NOT TO DO**: + ```ts + Effect.gen(function* () { + try { + // ❌ WRONG - Never do this in Effect.gen + const result = yield* someEffect + } catch (error) { + // ❌ This will never be reached and breaks Effect semantics + } + }) + ``` +- **CORRECT PATTERN**: + ```ts + Effect.gen(function* () { + // ✅ Use Effect's built-in error handling + const result = yield* Effect.result(someEffect) + if (result._tag === "Failure") { + // Handle error case + } + }) + ``` + +### ABSOLUTELY FORBIDDEN: Type Assertions + +**NEVER EVER use `as never`, `as any`, or `as unknown` type assertions!** + +- These break TypeScript's type safety and hide real type errors +- Always fix the underlying type issues instead of masking them +- **FORBIDDEN PATTERNS**: + ```ts + // ❌ NEVER do any of these + const value = something as any + const value = something as never + const value = something as unknown + ``` +- **CORRECT APPROACH**: Fix the actual type mismatch by: + - Using proper generic type parameters + - Importing correct types + - Using proper Effect constructors and combinators + - Adjusting function signatures to match usage + +### MANDATORY: Return Yield Pattern for Errors + +**ALWAYS use `return yield*` when yielding errors or interrupts in Effect.gen!** + +- When yielding `Effect.fail`, `Effect.interrupt`, or other terminal effects, always use `return yield*` +- This makes it clear that the generator function terminates at that point +- **MANDATORY PATTERN**: + + ```ts + Effect.gen(function* () { + if (someCondition) { + // ✅ CORRECT - Always use return yield* for errors + return yield* Effect.fail("error message") + } + + if (shouldInterrupt) { + // ✅ CORRECT - Always use return yield* for interrupts + return yield* Effect.interrupt + } + + // Continue with normal flow... + const result = yield* someOtherEffect + return result + }) + ``` + +- **WRONG PATTERNS**: + ```ts + Effect.gen(function* () { + if (someCondition) { + // ❌ WRONG - Missing return keyword + yield* Effect.fail("error message") + // Unreachable code after error! + } + }) + ``` +- **CRITICAL**: Always use `return yield*` to make termination explicit and avoid unreachable code + +## Development Workflow + +### Core Principles + +- **Research → Plan → Implement**: Never jump straight to coding +- **Reality Checkpoints**: Regularly validate progress and approach +- **Zero Tolerance for Errors**: All automated checks must pass +- **Clarity over Cleverness**: Choose clear, maintainable solutions + +### 🚨 MANDATORY FUNCTION DEVELOPMENT WORKFLOW 🚨 + +### Mandatory Validation Steps + +- **🚨 CRITICAL FIRST STEP**: IMMEDIATELY run `pnpm lint --fix ` after editing ANY TypeScript file +- Always run tests after making changes: `pnpm test run ` +- Run type checking: `pnpm check` +- Build the project: `pnpm build` +- **MANDATORY AFTER EVERY EDIT**: Always lint TypeScript files that are changed with `pnpm lint --fix ` +- Always check for type errors before committing: `pnpm check` +- **CRITICAL**: Check JSDoc examples compile: `pnpm docgen` - MUST PASS before committing + +**ALWAYS follow this EXACT sequence when creating ANY new function:** + +1. **Create function** - Write the function implementation in TypeScript file +2. **Lint TypeScript file** - Run `pnpm lint --fix ` +3. **Check compilation** - Run `pnpm check` to ensure it compiles +4. **Write test** - Create comprehensive test for the function in test file +5. **Compile test & lint test file** - Run `pnpm check` then `pnpm lint --fix ` + +**CRITICAL NOTES:** + +- **ONLY LINT TYPESCRIPT FILES** (.ts files) - Do NOT lint markdown, JSON, or other file types +- **NEVER SKIP ANY STEP** - This workflow is MANDATORY for every single function created +- **NEVER CONTINUE** to the next step until the current step passes completely +- **NEVER CREATE MULTIPLE FUNCTIONS** without completing this full workflow for each one + +This ensures: + +- Zero compilation errors at any point +- Clean, properly formatted TypeScript code +- Immediate test coverage for every function +- No accumulation of technical debt + +### When Stuck + +- Ask for guidance rather than guessing + +### When you need to write examples or run code + +For efficient example development, use the `./scratchpad/` directory: + +```bash +# Create temporary development files +touch ./scratchpad/test-example.ts + +# Test execution if needed +pnpm tsx ./scratchpad/test-example.ts +``` + +**⚠️ Remember to Clean Up:** + +```bash +# Clean up test files when done +rm scratchpad/test-*.ts +rm scratchpad/temp*.ts scratchpad/example*.ts +``` + +### Validation and Testing + +**Required Checks (run after every edit):** + +```bash +# 1. Fix linting issues immediately +pnpm lint --fix packages/effect/src/ModifiedFile.ts + +# 2. Verify examples compile +pnpm docgen + +# 3. Verify type checking +pnpm check + +# 4. Confirm progress +node scripts/analyze-jsdoc.mjs --file=ModifiedFile.ts +``` + +## Code Style Guidelines + +### TypeScript Quality Standards + +- **Type Safety**: NEVER use `any` type or `as any` assertions +- **Explicit Types**: Use concrete types over generic `unknown` where possible +- **Type Annotations**: Add explicit annotations when inference fails +- **Early Returns**: Prefer early returns for better readability +- **Input Validation**: Validate all inputs at boundaries +- **Error Handling**: Use proper Effect error management patterns + +### Effect Library Conventions + +- Follow existing TypeScript patterns in the codebase +- Use functional programming principles +- Maintain consistency with Effect library conventions +- Use proper Effect constructors (e.g., `Array.make()`, `Chunk.fromIterable()`) +- Prefer `Effect.gen` for monadic composition +- Use `Data.TaggedError` for custom error types +- Implement resource safety with automatic cleanup patterns + +### Code Organization + +- No comments unless explicitly requested +- Follow existing file structure and naming conventions +- Delete old code when replacing functionality +- **NEVER create new script files or tools unless explicitly requested by the user** +- Choose clarity over cleverness in all implementations + +### Implementation Completeness + +Code is considered complete only when: + +- All linters pass (`pnpm lint`) +- All tests pass (`pnpm test run`) +- All type checks pass (`pnpm check`) +- All JSDoc examples compile (`pnpm docgen`) +- Feature works end-to-end +- Old/deprecated code is removed +- Documentation is updated + +## Testing + +- Test files are located in `packages/*/test/` directories for each package +- Main Effect library tests: `packages/effect/test/` +- Platform-specific tests: `packages/platform-*/test/` +- Use existing test patterns and utilities +- Always verify implementations with tests +- Run specific tests with: `pnpm test run ` + +### Time-Dependent Testing + +- **CRITICAL**: When testing time-dependent code (delays, timeouts, scheduling), always use `TestClock` to avoid flaky tests +- Import `TestClock` from `effect/TestClock` and use `TestClock.advance()` to control time progression +- Never rely on real wall-clock time (`Effect.sleep`, `Effect.timeout`) in tests without TestClock +- Examples of time-dependent operations that need TestClock: + - `Effect.sleep()` and `Effect.delay()` + - `Effect.timeout()` and `Effect.race()` with timeouts + - Scheduled operations and retry logic + - Queue operations with time-based completion + - Any concurrent operations that depend on timing +- Pattern: Use `TestClock.advance("duration")` to simulate time passage instead of actual delays + +### Testing Framework Selection + +#### When to Use @effect/vitest + +- **MANDATORY**: Use `@effect/vitest` for modules that work with Effect values +- **Effect-based functions**: Functions that return `Effect` types +- **Modules**: Effect, Stream, Layer, TestClock, etc. +- **Import pattern**: `import { assert, describe, it } from "@effect/vitest"` +- **Test pattern**: `it.effect("description", () => Effect.gen(function*() { ... }))` + +#### When to Use Regular vitest + +- **MANDATORY**: Use regular `vitest` for pure TypeScript functions +- **Pure functions**: Functions that don't return Effect types (Graph, Data, Equal, etc.) +- **Utility modules**: Graph, Chunk, Array, String, Number, etc. +- **Import pattern**: `import { describe, expect, it } from "vitest"` +- **Test pattern**: `it("description", () => { ... })` + +### it.effect Testing Pattern + +- **MANDATORY**: Use `it.effect` for all Effect-based tests, not `Effect.runSync` with regular `it` +- **CRITICAL**: Import `{ assert, describe, it }` from `@effect/vitest`, not from `vitest` +- **FORBIDDEN**: Never use `expect` from vitest in Effect tests - use `assert` methods instead +- **PATTERN**: All tests should use `it.effect("description", () => Effect.gen(function*() { ... }))` + +#### Correct it.effect Pattern: + +```ts +import { assert, describe, it } from "@effect/vitest" +import * as Effect from "effect/Effect" +import * as SomeModule from "effect/SomeModule" + +describe("ModuleName", () => { + describe("feature group", () => { + it.effect("should do something", () => + Effect.gen(function* () { + const result = yield* SomeModule.operation() + + // Use assert methods, not expect + assert.strictEqual(result, expectedValue) + assert.deepStrictEqual(complexResult, expectedObject) + assert.isTrue(booleanResult) + assert.isFalse(negativeResult) + }) + ) + + it.effect("should handle errors", () => + Effect.gen(function* () { + const txRef = yield* SomeModule.create() + yield* SomeModule.update(txRef, newValue) + + const value = yield* SomeModule.get(txRef) + assert.strictEqual(value, newValue) + }) + ) + }) +}) +``` + +#### Wrong Patterns (NEVER USE): + +```ts +// ❌ WRONG - Using Effect.runSync with regular it +import { describe, expect, it } from "vitest" +it("test", () => { + const result = Effect.runSync( + Effect.gen(function* () { + return yield* someEffect + }) + ) + expect(result).toBe(value) // Wrong assertion method +}) + +// ❌ WRONG - Using expect instead of assert +it.effect("test", () => + Effect.gen(function* () { + const result = yield* someEffect + expect(result).toBe(value) // Should use assert.strictEqual + }) +) +``` + +#### Key it.effect Guidelines: + +- **Import pattern**: `import { assert, describe, it } from "@effect/vitest"` +- **Test structure**: `it.effect("description", () => Effect.gen(function*() { ... }))` +- **Assertions**: Use `assert.strictEqual`, `assert.deepStrictEqual`, `assert.isTrue`, `assert.isFalse` +- **Effect composition**: All operations inside the generator should yield Effects +- **Error testing**: Use `Effect.exit()` for testing error conditions +- **Transactional testing**: Use `Effect.atomic()` for testing transactional behavior + +## Git Workflow + +- Main branch: `main` +- Create feature branches for new work +- Only commit when explicitly requested +- Follow conventional commit messages + +## Key Directories + +### Development & Build + +- `packages/` - Main source code for the Effect library and related packages + - `effect/` - Core Effect library implementation + - `platform-*` - Platform-specific implementations (e.g., Node.js, Browser, Bun) +- `scripts/` - Build and maintenance scripts +- `bundle/` - Bundle size analysis files +- `docs/` - Generated documentation files +- `coverage/` - Test coverage reports +- `scratchpad/` - Temporary development and testing files +- `patches/` - Package patches for dependencies + +### Configuration & Specs + +- `.specs/` - Implementation specifications and plans organized by feature +- `.github/` - GitHub Actions workflows and templates +- `.vscode/` - VS Code workspace configuration +- `.changeset/` - Changeset configuration for versioning diff --git a/.specs/categorization/examples-plan.md b/.specs/categorization/examples-plan.md new file mode 100644 index 0000000000..d80a650f92 --- /dev/null +++ b/.specs/categorization/examples-plan.md @@ -0,0 +1,103 @@ +# JSDoc Examples Import Fix Plan + +## Overview + +Following the module categorization reorganization (`.specs/categorization/plan.md` - make sure to read this first), there are JSDoc examples that have broken imports. This plan outlines a systematic approach to fix all these imports using 10 concurrent tasks. + +First run `pnpm docgen` to identify the examples with import errors, and then +run it again after each task to ensure all examples compile correctly. + +## Task Breakdown + +- Run `pnpm docgen` to generate the initial list of files with import errors. +- Each task will handle a subset of the files, processing them concurrently. +- Each task will focus on fixing import paths based on the new module structure. +- Each task will run `pnpm docgen` after processing its files to ensure all examples compile correctly. + +## Analysis Summary + +### Most Affected Imports (by frequency) + +- **Option** (77 occurrences) - moved to `data/Option` + - `import { Option } from "effect/data"` + - `import * as Option from "effect/data/Option"` +- **Fiber** (32 occurrences) - moved to `runtime/Fiber` + - `import { Fiber } from "effect/runtime"` + - `import * as Fiber from "effect/runtime/Fiber"` +- **Ref** (24 occurrences) - moved to `concurrency/Ref` +- **Brand** (23 occurrences) - moved to `data/Brand` +- **Equivalence** (22 occurrences) - moved to `data/Equivalence` +- **Deferred** (22 occurrences) - moved to `concurrency/Deferred` +- **FiberMap** (21 occurrences) - moved to `concurrency/FiberMap` +- **MutableRef** (18 occurrences) - moved to `concurrency/MutableRef` +- **MutableList** (18 occurrences) - moved to `collections/MutableList` +- **FiberHandle** (17 occurrences) - moved to `concurrency/FiberHandle` +- **FiberSet** (16 occurrences) - moved to `concurrency/FiberSet` +- **Filter** (14 occurrences) - moved to `data/Filter` + +### Import Error Types + +1. **TS2305**: Module '"effect"' has no exported member 'X' - Main exports need updating +2. **TS2307**: Cannot find module 'effect/X' - Direct module imports need path updates + +## Import Fix Patterns + +### Pattern 1: Main Export Updates + +```typescript +// Before +import { Effect, Option, Ref } from "effect" + +// After +import { Effect } from "effect" +import { Ref } from "effect/concurrency" +import { Option } from "effect/data" +``` + +### Pattern 2: Direct Import Updates + +```typescript +// Before +import * as Option from "effect/Option" + +// After +import * as Option from "effect/data/Option" +``` + +### Pattern 3: Mixed Import Updates + +```typescript +// Before +import { Effect, Option, Ref } from "effect" +import * as Array from "effect/Array" + +// After +import { Effect } from "effect" +import * as Array from "effect/collections/Array" +import { Ref } from "effect/concurrency" +import { Option } from "effect/data" +``` + +## Implementation Steps + +1. **Parallel Processing**: Each task will process its assigned files concurrently +2. **Import Detection**: Use regex patterns to identify import statements +3. **Path Resolution**: Update import paths based on the new folder structure +4. **Testing**: After every file change, run `pnpm docgen` to verify all examples compile +5. **Linting**: Run `pnpm lint --fix` to ensure code style consistency +6. **Validation**: Run `pnpm check` after each batch to ensure compilation +7. **Testing**: Run `pnpm docgen` to verify all examples compile + +## Success Criteria + +- All 354 files with import errors are fixed +- `pnpm docgen` runs without any import-related errors +- No regression in functionality +- All imports follow the new module organization + +## Risk Mitigation + +- Create backups before making changes +- Test changes incrementally +- Use version control to track changes +- Validate each task's output before proceeding diff --git a/.specs/categorization/plan.md b/.specs/categorization/plan.md new file mode 100644 index 0000000000..4330282326 --- /dev/null +++ b/.specs/categorization/plan.md @@ -0,0 +1,246 @@ +# Effect Package Categorization Plan + +## Overview + +This plan organizes the 77 top-level files in `packages/effect/src/` into logical subfolders to improve maintainability and developer experience. The categorization follows functional domain boundaries and existing patterns established by the `batching/`, `caching/`, `config/`, `platform/`, `schema/`, and `unstable/` folders. + +## Analysis Summary + +Based on comprehensive analysis, the 77 files fall into the following functional categories: + +### Current Structure + +- **Existing organized folders**: 6 folders with 2-15 files each + +## Proposed Folder Structure + +### 1. **collections/** + +**Purpose**: Data structures and collection utilities + +- `Array.ts` - Array utilities and operations +- `Chunk.ts` - High-performance immutable sequences +- `HashMap.ts` - Immutable hash-based maps +- `HashSet.ts` - Immutable hash-based sets +- `Iterable.ts` - Lazy sequence processing +- `MutableHashMap.ts` - Mutable hash maps +- `MutableHashSet.ts` - Mutable hash sets +- `MutableList.ts` - Mutable linked lists +- `NonEmptyIterable.ts` - Non-empty sequence guarantees +- `Graph.ts` - Graph data structures +- `Symbol.ts` - Symbol utilities +- `Trie.ts` - Prefix tree structures + +### 2. **primitives/** + +**Purpose**: Enhanced primitive type wrappers + +- `BigDecimal.ts` - Arbitrary precision decimal arithmetic +- `BigInt.ts` - Large integer operations +- `Boolean.ts` - Boolean logic utilities +- `Number.ts` - Numeric operations +- `String.ts` - String manipulation +- `RegExp.ts` - Regular expression utilities + +### 3. **data/** + +**Purpose**: Core data types and structures + +- `Option.ts` - Optional values +- `Result.ts` - Success/failure computations +- `Data.ts` - Structural equality data types +- `Brand.ts` - Branded type system +- `Redacted.ts` - Secure value handling +- `Record.ts` - Immutable key-value mappings +- `Struct.ts` - Object structure utilities +- `Tuple.ts` - Fixed-length array operations +- `Equivalence.ts` - Equivalence relations +- `Order.ts` - Total ordering operations +- `Ordering.ts` - Ordering result manipulation +- `Predicate.ts` - Boolean predicates and type guards +- `Filter.ts` - Filtering operations + +### 4. **concurrency/** + +**Purpose**: Concurrency primitives and synchronization + +- `Deferred.ts` - One-time asynchronous variables +- `FiberHandle.ts` - Fiber container management +- `FiberMap.ts` - Keyed fiber collections +- `FiberSet.ts` - Fiber set collections +- `Queue.ts` - Asynchronous queues +- `PubSub.ts` - Publish-subscribe message hubs +- `Ref.ts` - Thread-safe atomic references +- `MutableRef.ts` - Simple mutable references + +### 5. **resources/** + +**Purpose**: Resource management + +- `LayerMap.ts` - Dynamic layer management +- `RcRef.ts` - Reference-counted references +- `RcMap.ts` - Reference-counted maps +- `Scope.ts` - Resource lifecycle management + +### 6. **stream/** + +**Purpose**: Streaming data processing + +- `Stream.ts` - Lazy pull-based streaming +- `Channel.ts` - Bi-directional I/O operations +- `Sink.ts` - Stream consumption +- `Pull.ts` - Low-level streaming primitives + +### 7. **scheduling/** + +**Purpose**: Task scheduling and retry logic + +- `Schedule.ts` - Retry and repetition strategies + +### 8. **time/** + +**Purpose**: Time management and temporal utilities + +- `Clock.ts` - Time-based operations service +- `Duration.ts` - Time span representation +- `DateTime.ts` - Date and time with timezone support +- `Cron.ts` - Cron expression scheduling + +### 9. **logging/** + +**Purpose**: Logging and debugging utilities + +- `Console.ts` - Console operations service +- `Logger.ts` - Structured logging system +- `LogLevel.ts` - Log level management + +### 10. **observability/** + +**Purpose**: Monitoring and observability + +- `Metric.ts` - Application metrics collection +- `Tracer.ts` - Distributed tracing + +### 11. **transactions/** + +**Purpose**: Transactional operations and management + +- `TxQueue.ts` - Transactional queues +- `TxRef.ts` - Transactional references +- `TxSemaphore.ts` - Transactional semaphores +- `TxChunk.ts` - Transactional chunks +- `TxHashMap.ts` - Transactional hash maps +- `TxHashSet.ts` - Transactional hash sets + +### 12. **interfaces/** + +**Purpose**: Interfaces + +- `Pipeable.ts` - Pipe operation support +- `Equal.ts` - Value equality operations +- `Hash.ts` - Value hashing utilities +- `PrimaryKey.ts` - Unique identifier interface +- `Inspectable.ts` - Inspection and debugging + +### 13. **encoding/** + +- `Encoding.ts` - Data encoding/decoding utilities + +### 13. **runtime/** + +- `ManagedRuntime.ts` - Managed runtime lifecycle +- `Runtime.ts` - Effect execution utilities +- `Fiber.ts` - Lightweight concurrency units +- `Scheduler.ts` - Task execution management + +### 14. **match/** + +- `Match.ts` - Type-safe pattern matching + +### 15. **types/** + +- `HKT.ts` - Higher-kinded types +- `Types.ts` - Common type utilities +- `Unify.ts` - Type unification system + +### 16. **services/** + +- `ServiceMap.ts` - Dependency injection container +- `Layer.ts` - Dependency injection system +- `References.ts` - Runtime configuration references + +### 17. **testing/** + +- `FastCheck.ts` - Property-based testing +- `TestConsole.ts` - Testing console implementation +- `TestClock.ts` - Testable time control + +### 17. Remain at the top level + +Do not move the following files. + +- `Effect.ts` - Core Effect abstraction +- `Exit.ts` - Effect computation results +- `Cause.ts` - Structured error information +- `Utils.ts` - General utilities +- `Function.ts` - Core functional programming utilities + +## Implementation Strategy + +### Phase 1: Create Folder Structure + +1. Create all new subfolders in `packages/effect/src/` +2. Each folder will have an `.index.ts` file, similar to existing patterns like + `batching/.index.ts`. `index.ts` files are automatically generated using + `pnpm codegen`. + +### Phase 2: Move Files + +1. Move files to their respective folders +2. Update internal import paths within moved files + +### Phase 3: Update Exports + +1. Maintain backward compatibility - all exports should remain the same +2. Update any example files or documentation + +### Phase 4: Validation + +1. Run `pnpm codegen` to regenerate index files +2. Run `pnpm check` to ensure TypeScript compilation +3. Run `pnpm docgen` to ensure documentation builds +4. Run tests to ensure functionality remains intact + +## Rationale + +### Benefits + +1. **Improved Developer Experience**: Easier to find related functionality +2. **Logical Organization**: Files grouped by functional domain +3. **Maintainability**: Clear separation of concerns +4. **Scalability**: Room for future growth within each category +5. **Consistency**: Follows existing patterns in the codebase + +### Considerations + +1. **Backward Compatibility**: All public exports remain unchanged +2. **Import Paths**: Internal imports will be updated but public API stays same +3. **Documentation**: Examples and docs will reference new structure internally +4. **Bundle Size**: No impact on bundle size, just reorganization + +## Migration Safety + +- All public exports remain exactly the same +- No breaking changes to the public API +- Internal organization only - external consumers unaffected +- Comprehensive validation before completion + +## Expected Outcome + +A well-organized codebase where: + +- Related functionality is co-located +- New contributors can easily find relevant code +- Maintenance becomes easier due to logical grouping +- The structure scales well for future additions +- Public API remains completely unchanged diff --git a/bundle/batching.ts b/bundle/batching.ts index c8f2440bca..e31e8efcaa 100644 --- a/bundle/batching.ts +++ b/bundle/batching.ts @@ -1,6 +1,6 @@ -import * as Array from "#dist/effect/Array" import * as Request from "#dist/effect/batching/Request" import * as Resolver from "#dist/effect/batching/RequestResolver" +import * as Array from "#dist/effect/collections/Array" import * as Effect from "#dist/effect/Effect" class GetNameById extends Request.TaggedClass("GetNameById")<{ diff --git a/bundle/metric.ts b/bundle/metric.ts index 9a5472a623..208051c602 100644 --- a/bundle/metric.ts +++ b/bundle/metric.ts @@ -1,5 +1,5 @@ import * as Effect from "#dist/effect/Effect" -import * as Metric from "#dist/effect/Metric" +import * as Metric from "#dist/effect/observability/Metric" const program = Effect.gen(function*() { yield* Effect.succeed(1).pipe( diff --git a/bundle/pubsub.ts b/bundle/pubsub.ts index 51950f7705..acdfb93c0e 100644 --- a/bundle/pubsub.ts +++ b/bundle/pubsub.ts @@ -1,5 +1,5 @@ +import * as PubSub from "#dist/effect/concurrency/PubSub" import * as Effect from "#dist/effect/Effect" -import * as PubSub from "#dist/effect/PubSub" const program = Effect.gen(function*() { const pubsub = yield* PubSub.unbounded() diff --git a/bundle/queue.ts b/bundle/queue.ts index 5f13b8152f..019cd46fd9 100644 --- a/bundle/queue.ts +++ b/bundle/queue.ts @@ -1,5 +1,5 @@ +import * as Queue from "#dist/effect/concurrency/Queue" import * as Effect from "#dist/effect/Effect" -import * as Queue from "#dist/effect/Queue" const program = Effect.gen(function*() { const queue = yield* Queue.make() diff --git a/bundle/schedule.ts b/bundle/schedule.ts index 89ada343af..354226c904 100644 --- a/bundle/schedule.ts +++ b/bundle/schedule.ts @@ -1,5 +1,5 @@ import * as Effect from "#dist/effect/Effect" -import * as Schedule from "#dist/effect/Schedule" +import * as Schedule from "#dist/effect/scheduling/Schedule" Effect.succeed(123).pipe( Effect.repeat({ diff --git a/bundle/schema-string-async.ts b/bundle/schema-string-async.ts index 70eb08e512..17f722e0a2 100644 --- a/bundle/schema-string-async.ts +++ b/bundle/schema-string-async.ts @@ -1,7 +1,7 @@ -import * as Duration from "#dist/effect/Duration" import * as Effect from "#dist/effect/Effect" import * as Schema from "#dist/effect/schema/Schema" import * as Transformation from "#dist/effect/schema/Transformation" +import * as Duration from "#dist/effect/time/Duration" const schema = Schema.String.pipe(Schema.decodeTo( Schema.String, diff --git a/bundle/stm.ts b/bundle/stm.ts index b651c1748d..048594b04a 100644 --- a/bundle/stm.ts +++ b/bundle/stm.ts @@ -1,5 +1,5 @@ import * as Effect from "#dist/effect/Effect" -import * as TxRef from "#dist/effect/TxRef" +import * as TxRef from "#dist/effect/transactions/TxRef" const program = Effect.gen(function*() { const ref = yield* TxRef.make(0) diff --git a/bundle/stream.ts b/bundle/stream.ts index 588f9ac6a6..ced193f982 100644 --- a/bundle/stream.ts +++ b/bundle/stream.ts @@ -1,5 +1,5 @@ import * as Effect from "#dist/effect/Effect" -import * as Stream from "#dist/effect/Stream" +import * as Stream from "#dist/effect/stream/Stream" Stream.range(1, 100_000).pipe( Stream.runDrain, diff --git a/deno.json b/deno.json index bda7f546bb..6f87873166 100644 --- a/deno.json +++ b/deno.json @@ -1,8 +1,13 @@ { "$schema": "https://raw.githubusercontent.com/denoland/deno/refs/heads/main/cli/schemas/config-file.v1.json", "nodeModulesDir": "manual", - "unstable": ["bare-node-builtins", "node-globals"], - "workspace": ["./packages/*"], + "unstable": [ + "bare-node-builtins", + "node-globals" + ], + "workspace": [ + "./packages/*" + ], "exclude": [ "**/*.mjs", "**/*.cjs", diff --git a/packages/effect/SCHEMA.md b/packages/effect/SCHEMA.md index 3fd15d5307..4f01821eb7 100644 --- a/packages/effect/SCHEMA.md +++ b/packages/effect/SCHEMA.md @@ -206,7 +206,7 @@ This makes it easier to work with schemas in contexts where one direction has no ```ts import type { Effect } from "effect" -import { ServiceMap } from "effect" +import { ServiceMap } from "effect/services" import { Schema } from "effect/schema" // A service that retrieves full user info from an ID @@ -1758,7 +1758,7 @@ Use `Struct.pick` to keep only a selected set of fields. **Example** (Picking specific fields from a struct) ```ts -import { Struct } from "effect" +import { Struct } from "effect/data" import { Schema } from "effect/schema" /* @@ -1779,7 +1779,7 @@ Use `Struct.omit` to remove specified fields from a struct. **Example** (Omitting fields from a struct) ```ts -import { Struct } from "effect" +import { Struct } from "effect/data" import { Schema } from "effect/schema" /* @@ -1800,7 +1800,7 @@ Use `Struct.merge` to add new fields to an existing struct. **Example** (Adding fields to a struct) ```ts -import { Struct } from "effect" +import { Struct } from "effect/data" import { Schema } from "effect/schema" /* @@ -1859,7 +1859,7 @@ Use `Struct.evolve` to transform the value schema of individual fields. **Example** (Modifying the type of a single field) ```ts -import { Struct } from "effect" +import { Struct } from "effect/data" import { Schema } from "effect/schema" /* @@ -1885,7 +1885,7 @@ If you want to transform the value schema of multiple fields at once, you can us **Example** (Making all fields optional) ```ts -import { Struct } from "effect" +import { Struct } from "effect/data" import { Schema } from "effect/schema" /* @@ -1909,7 +1909,7 @@ If you want to map a subset of elements, you can use `Struct.mapPick` or `Struct **Example** (Making a subset of fields optional) ```ts -import { Struct } from "effect" +import { Struct } from "effect/data" import { Schema } from "effect/schema" /* @@ -1929,7 +1929,7 @@ const schema = Schema.Struct({ Or if it's more convenient, you can use `Struct.mapOmit`. ```ts -import { Struct } from "effect" +import { Struct } from "effect/data" import { Schema } from "effect/schema" /* @@ -1953,7 +1953,8 @@ Use `Struct.evolveKeys` to rename field keys while keeping the corresponding val **Example** (Uppercasing keys in a struct) ```ts -import { String, Struct } from "effect" +import { Struct } from "effect/data" +import { String } from "effect/primitives" import { Schema } from "effect/schema" /* @@ -1977,7 +1978,7 @@ If you simply want to rename keys with static keys, you can use `Struct.renameKe **Example** (Renaming keys in a struct) ```ts -import { Struct } from "effect" +import { Struct } from "effect/data" import { Schema } from "effect/schema" /* @@ -2003,7 +2004,8 @@ Use `Struct.evolveEntries` when you want to transform both the key and the value **Example** (Transforming keys and value schemas) ```ts -import { String, Struct } from "effect" +import { Struct } from "effect/data" +import { String } from "effect/primitives" import { Schema } from "effect/schema" /* @@ -2027,7 +2029,7 @@ const schema = Schema.Struct({ The previous examples can be applied to opaque structs as well. ```ts -import { Struct } from "effect" +import { Struct } from "effect/data" import { Schema } from "effect/schema" class A extends Schema.Opaque()( @@ -5027,7 +5029,9 @@ Schema.Number.check(Check.int32) ### BigInts ```ts -import { BigInt, Order, Schema, Check } from "effect" +import { Order } from "effect/data" +import { BigInt } from "effect/primitives" +import { Schema, Check } from "effect/schema" const options = { order: Order.bigint } diff --git a/packages/effect/benchmark/schema/tagged-union.ts b/packages/effect/benchmark/schema/tagged-union.ts index bce87343c7..3ef4e3059f 100644 --- a/packages/effect/benchmark/schema/tagged-union.ts +++ b/packages/effect/benchmark/schema/tagged-union.ts @@ -1,4 +1,4 @@ -import { Array as RA } from "effect" +import { Array as RA } from "effect/collections" import type { AST } from "effect/schema" import { Schema, ToParser } from "effect/schema" import { Bench } from "tinybench" diff --git a/packages/effect/dtslint/Option.tst.ts b/packages/effect/dtslint/Option.tst.ts index aa3f1ab4eb..40e43c7c3f 100644 --- a/packages/effect/dtslint/Option.tst.ts +++ b/packages/effect/dtslint/Option.tst.ts @@ -1,5 +1,6 @@ -import type { Predicate } from "effect" -import { Option, pipe } from "effect" +import { pipe } from "effect" +import type { Predicate } from "effect/data" +import { Option } from "effect/data" import { describe, expect, it } from "tstyche" declare const number: Option.Option diff --git a/packages/effect/dtslint/Struct.tst.ts b/packages/effect/dtslint/Struct.tst.ts index 5f013702f4..faa66fecd4 100644 --- a/packages/effect/dtslint/Struct.tst.ts +++ b/packages/effect/dtslint/Struct.tst.ts @@ -1,4 +1,6 @@ -import { hole, pipe, String as Str, Struct } from "effect" +import { hole, pipe } from "effect" +import { Struct } from "effect/data" +import { String as Str } from "effect/primitives" import { Schema } from "effect/schema" import { describe, expect, it, when } from "tstyche" diff --git a/packages/effect/dtslint/Tuple.tst.ts b/packages/effect/dtslint/Tuple.tst.ts index 401d495d3c..442650076a 100644 --- a/packages/effect/dtslint/Tuple.tst.ts +++ b/packages/effect/dtslint/Tuple.tst.ts @@ -1,4 +1,5 @@ -import { pipe, Tuple } from "effect" +import { pipe } from "effect" +import { Tuple } from "effect/data" import { Schema } from "effect/schema" import { describe, expect, it, when } from "tstyche" diff --git a/packages/effect/dtslint/schema/Check.tst.ts b/packages/effect/dtslint/schema/Check.tst.ts index 222d908bdb..4662799709 100644 --- a/packages/effect/dtslint/schema/Check.tst.ts +++ b/packages/effect/dtslint/schema/Check.tst.ts @@ -1,4 +1,4 @@ -import type { Brand } from "effect" +import type { Brand } from "effect/data" import { Check, Schema } from "effect/schema" import { describe, expect, it } from "tstyche" diff --git a/packages/effect/dtslint/schema/Schema.tst.ts b/packages/effect/dtslint/schema/Schema.tst.ts index 6724eee279..1983652d10 100644 --- a/packages/effect/dtslint/schema/Schema.tst.ts +++ b/packages/effect/dtslint/schema/Schema.tst.ts @@ -1,17 +1,11 @@ -import type { Brand, ServiceMap } from "effect" -import { - Effect, - flow, - hole, - Option, - Predicate, - String as Str, - Struct, - Tuple, -} from "effect" +import type { Brand } from "effect/data" +import type { ServiceMap } from "effect/services" +import { Effect, flow, hole } from "effect" +import { Option, Predicate, Struct, Tuple } from "effect/data" +import { String as Str } from "effect/primitives" import type { Issue } from 'effect/schema'; import { AST, Check, Getter, Schema, Transformation } from 'effect/schema' -import type { NonEmptyReadonlyArray } from "effect/Array" +import type { Array } from "effect/collections" import { immerable, produce } from "immer" import { describe, expect, it, when } from "tstyche" @@ -2338,8 +2332,8 @@ describe("Schema", () => { const schema = Schema.Union([Schema.String, Schema.Number]).mapMembers(Tuple.map(Schema.NonEmptyArray)) expect(Schema.revealCodec(schema)).type.toBe< Schema.Codec< - NonEmptyReadonlyArray | NonEmptyReadonlyArray, - NonEmptyReadonlyArray | NonEmptyReadonlyArray, + Array.NonEmptyReadonlyArray | Array.NonEmptyReadonlyArray, + Array.NonEmptyReadonlyArray | Array.NonEmptyReadonlyArray, never, never > diff --git a/packages/effect/package.json b/packages/effect/package.json index 5ab7513ca3..3c425ee444 100644 --- a/packages/effect/package.json +++ b/packages/effect/package.json @@ -31,9 +31,27 @@ ".": "./src/index.ts", "./batching": "./src/batching/index.ts", "./caching": "./src/caching/index.ts", + "./collections": "./src/collections/index.ts", + "./concurrency": "./src/concurrency/index.ts", "./config": "./src/config/index.ts", + "./data": "./src/data/index.ts", + "./encoding": "./src/encoding/index.ts", + "./interfaces": "./src/interfaces/index.ts", + "./logging": "./src/logging/index.ts", + "./match": "./src/match/index.ts", + "./observability": "./src/observability/index.ts", "./platform": "./src/platform/index.ts", + "./primitives": "./src/primitives/index.ts", + "./resources": "./src/resources/index.ts", + "./runtime": "./src/runtime/index.ts", + "./scheduling": "./src/scheduling/index.ts", "./schema": "./src/schema/index.ts", + "./services": "./src/services/index.ts", + "./stream": "./src/stream/index.ts", + "./testing": "./src/testing/index.ts", + "./time": "./src/time/index.ts", + "./transactions": "./src/transactions/index.ts", + "./types": "./src/types/index.ts", "./unstable/http": "./src/unstable/http/index.ts", "./unstable/socket": "./src/unstable/socket/index.ts", "./unstable/tracing": "./src/unstable/tracing/index.ts", @@ -55,9 +73,27 @@ ".": "./dist/index.js", "./batching": "./dist/batching/index.js", "./caching": "./dist/caching/index.js", + "./collections": "./dist/collections/index.js", + "./concurrency": "./dist/concurrency/index.js", "./config": "./dist/config/index.js", + "./data": "./dist/data/index.js", + "./encoding": "./dist/encoding/index.js", + "./interfaces": "./dist/interfaces/index.js", + "./logging": "./dist/logging/index.js", + "./match": "./dist/match/index.js", + "./observability": "./dist/observability/index.js", "./platform": "./dist/platform/index.js", + "./primitives": "./dist/primitives/index.js", + "./resources": "./dist/resources/index.js", + "./runtime": "./dist/runtime/index.js", + "./scheduling": "./dist/scheduling/index.js", "./schema": "./dist/schema/index.js", + "./services": "./dist/services/index.js", + "./stream": "./dist/stream/index.js", + "./testing": "./dist/testing/index.js", + "./time": "./dist/time/index.js", + "./transactions": "./dist/transactions/index.js", + "./types": "./dist/types/index.js", "./unstable/http": "./dist/unstable/http/index.js", "./unstable/socket": "./dist/unstable/socket/index.js", "./unstable/tracing": "./dist/unstable/tracing/index.js", diff --git a/packages/effect/src/Cause.ts b/packages/effect/src/Cause.ts index 670f799c3d..5582ddfbf3 100644 --- a/packages/effect/src/Cause.ts +++ b/packages/effect/src/Cause.ts @@ -39,17 +39,17 @@ * * @since 2.0.0 */ +import type * as Filter from "./data/Filter.ts" +import type { Option } from "./data/Option.ts" import type * as Effect from "./Effect.ts" -import type { Equal } from "./Equal.ts" -import type * as Filter from "./Filter.ts" -import type { Inspectable } from "./Inspectable.ts" +import type { Equal } from "./interfaces/Equal.ts" +import type { Inspectable } from "./interfaces/Inspectable.ts" +import type { Pipeable } from "./interfaces/Pipeable.ts" import * as core from "./internal/core.ts" import * as effect from "./internal/effect.ts" -import type { Option } from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import * as ServiceMap from "./ServiceMap.ts" -import type { Span } from "./Tracer.ts" -import type { NoInfer } from "./Types.ts" +import type { Span } from "./observability/Tracer.ts" +import * as ServiceMap from "./services/ServiceMap.ts" +import type { NoInfer } from "./types/Types.ts" /** * @example @@ -318,7 +318,8 @@ export interface Fail extends Cause.FailureProto<"Fail"> { /** * @example * ```ts - * import { Cause, Option } from "effect" + * import { Cause } from "effect" +import * as Option from "effect/data/Option" * * const cause = Cause.interrupt(123) * const failure = cause.failures[0] @@ -1037,7 +1038,8 @@ export const UnknownError: new(cause: unknown, message?: string) => UnknownError * * @example * ```ts - * import { Cause, ServiceMap } from "effect" + * import { Cause } from "effect" + * import { ServiceMap } from "effect/services" * * // Define a custom annotation key * class UserId extends ServiceMap.Key()("UserId") {} diff --git a/packages/effect/src/Effect.ts b/packages/effect/src/Effect.ts index 89a7faf555..0a1be6f623 100644 --- a/packages/effect/src/Effect.ts +++ b/packages/effect/src/Effect.ts @@ -22,7 +22,8 @@ * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * // Creating a simple effect * const hello = Effect.succeed("Hello, World!") @@ -66,40 +67,40 @@ * * @since 2.0.0 */ -import type * as Arr from "./Array.ts" import type * as Request from "./batching/Request.ts" import type { RequestResolver } from "./batching/RequestResolver.ts" import type * as Cause from "./Cause.ts" -import type { Clock } from "./Clock.ts" -import * as Duration from "./Duration.ts" +import type * as Arr from "./collections/Array.ts" +import type * as Filter from "./data/Filter.ts" +import type { Option } from "./data/Option.ts" +import type * as Predicate from "./data/Predicate.ts" +import type * as Result from "./data/Result.ts" import * as Exit from "./Exit.ts" -import type { Fiber } from "./Fiber.ts" -import type * as Filter from "./Filter.ts" import { constant, dual, type LazyArg } from "./Function.ts" -import type { TypeLambda } from "./HKT.ts" +import type { Pipeable } from "./interfaces/Pipeable.ts" import * as core from "./internal/core.ts" import * as internal from "./internal/effect.ts" import * as internalLayer from "./internal/layer.ts" import * as internalRequest from "./internal/request.ts" import * as internalSchedule from "./internal/schedule.ts" import type { version } from "./internal/version.ts" -import type * as Layer from "./Layer.ts" -import type { Logger } from "./Logger.ts" -import type { LogLevel } from "./LogLevel.ts" -import * as Metric from "./Metric.ts" -import type { Option } from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import type * as Predicate from "./Predicate.ts" -import { CurrentLogAnnotations, CurrentLogSpans } from "./References.ts" -import type * as Result from "./Result.ts" -import type { Schedule } from "./Schedule.ts" -import type { Scheduler } from "./Scheduler.ts" -import type { Scope } from "./Scope.ts" -import * as ServiceMap from "./ServiceMap.ts" -import type { AnySpan, ParentSpan, Span, SpanLink, SpanOptions, Tracer } from "./Tracer.ts" -import type { TxRef } from "./TxRef.ts" -import type { Concurrency, Covariant, ExcludeTag, ExtractTag, NoInfer, NotFunction, Tags } from "./Types.ts" -import type * as Unify from "./Unify.ts" +import type { Logger } from "./logging/Logger.ts" +import type { LogLevel } from "./logging/LogLevel.ts" +import * as Metric from "./observability/Metric.ts" +import type { AnySpan, ParentSpan, Span, SpanLink, SpanOptions, Tracer } from "./observability/Tracer.ts" +import type { Scope } from "./resources/Scope.ts" +import type { Fiber } from "./runtime/Fiber.ts" +import type { Scheduler } from "./runtime/Scheduler.ts" +import type { Schedule } from "./scheduling/Schedule.ts" +import type * as Layer from "./services/Layer.ts" +import { CurrentLogAnnotations, CurrentLogSpans } from "./services/References.ts" +import * as ServiceMap from "./services/ServiceMap.ts" +import type { Clock } from "./time/Clock.ts" +import * as Duration from "./time/Duration.ts" +import type { TxRef } from "./transactions/TxRef.ts" +import type { TypeLambda } from "./types/HKT.ts" +import type { Concurrency, Covariant, ExcludeTag, ExtractTag, NoInfer, NotFunction, Tags } from "./types/Types.ts" +import type * as Unify from "./types/Unify.ts" import type { YieldWrap } from "./Utils.ts" import { internalCall, SingleShotGen } from "./Utils.ts" @@ -625,7 +626,8 @@ export declare namespace All { * * @example Combining Effects in Tuples * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const tupleOfEffects = [ * Effect.succeed(42).pipe(Effect.tap(Console.log)), @@ -645,7 +647,8 @@ export declare namespace All { * * @example Combining Effects in Iterables * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const iterableOfEffects: Iterable> = [1, 2, 3].map( * (n) => Effect.succeed(n).pipe(Effect.tap(Console.log)) @@ -665,7 +668,8 @@ export declare namespace All { * * @example Combining Effects in Structs * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const structOfEffects = { * a: Effect.succeed(42).pipe(Effect.tap(Console.log)), @@ -685,7 +689,8 @@ export declare namespace All { * * @example Combining Effects in Records * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const recordOfEffects: Record> = { * key1: Effect.succeed(1).pipe(Effect.tap(Console.log)), @@ -705,7 +710,8 @@ export declare namespace All { * * @example Short-Circuiting Behavior * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.all([ * Effect.succeed("Task1").pipe(Effect.tap(Console.log)), @@ -769,7 +775,8 @@ export const all: < * @example * ```ts * // Title: Applying Effects to Iterable Elements - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const result = Effect.forEach([1, 2, 3, 4, 5], (n, index) => * Console.log(`Currently at index ${index}`).pipe(Effect.as(n * 2)) @@ -787,7 +794,8 @@ export const all: < * * @example * // Title: Using discard to Ignore Results - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * // Apply effects but discard the results * const result = Effect.forEach( @@ -1631,7 +1639,8 @@ export const withFiber: ( * * @example * ```ts - * import { Effect, Result } from "effect" + * import { Effect } from "effect" + * import { Result } from "effect/data" * * const success = Result.succeed(42) * const failure = Result.fail("Something went wrong") @@ -1654,7 +1663,8 @@ export const fromResult: (result: Result.Result) => Effect = i * * @example * ```ts - * import { Effect, Option } from "effect" + * import { Effect } from "effect" +import * as Option from "effect/data/Option" * * const some = Option.some(42) * const none = Option.none() @@ -1679,7 +1689,8 @@ export const fromOption: ( * * @example * ```ts - * import { Effect, Option } from "effect" + * import { Effect } from "effect" +import * as Option from "effect/data/Option" * * // Option is yieldable in Effect * const program = Effect.gen(function* () { @@ -1899,7 +1910,8 @@ export const andThen: { * @example * ```ts * // Title: Logging a step in a pipeline - * import { Console, Effect, pipe } from "effect" + * import { Effect, pipe } from "effect" + * import { Console } from "effect/logging" * * // Function to apply a discount safely to a transaction amount * const applyDiscount = ( @@ -1998,7 +2010,8 @@ export const tap: { * * @example * ```ts - * import { Effect, Result } from "effect" + * import { Effect } from "effect" + * import { Result } from "effect/data" * * const success = Effect.succeed(42) * const failure = Effect.fail("Something went wrong") @@ -2168,7 +2181,8 @@ export const as: { * * @example * ```ts - * import { Effect, Option } from "effect" + * import { Effect } from "effect" +import * as Option from "effect/data/Option" * * const program = Effect.asSome(Effect.succeed(42)) * @@ -2475,7 +2489,8 @@ export const catchTag: { * * @example * ```ts - * import { Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Data } from "effect/data" * * // Define tagged error types * class ValidationError extends Data.TaggedError("ValidationError")<{ @@ -2568,7 +2583,8 @@ export const catchTags: { * * @example * ```ts - * import { Effect, Console, Cause } from "effect" + * import { Effect, Cause } from "effect" + * import { Console } from "effect/logging" * * // An effect that might fail in different ways * const program = Effect.die("Something went wrong") @@ -2622,7 +2638,8 @@ export const catchCause: { * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * // An effect that might throw an unexpected error (defect) * const program = Effect.sync(() => { @@ -2699,7 +2716,8 @@ export const catchFilter: { * * @example * ```ts - * import { Effect, Cause, Console } from "effect" + * import { Effect, Cause } from "effect" + * import { Console } from "effect/logging" * * const httpRequest = Effect.fail("Network Error") * @@ -2863,7 +2881,8 @@ export const orDie: (self: Effect) => Effect = in * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * // Simulate a task that fails with an error * const task: Effect.Effect = Effect.fail("NetworkError") @@ -2902,7 +2921,8 @@ export const tapError: { * * @example * ```ts - * import { Effect, Cause, Console } from "effect" + * import { Effect, Cause } from "effect" + * import { Console } from "effect/logging" * * const task = Effect.fail("Something went wrong") * @@ -2937,7 +2957,8 @@ export const tapCause: { * * @example * ```ts - * import { Effect, Cause, Console } from "effect" + * import { Effect, Cause } from "effect" + * import { Console } from "effect/logging" * * const task = Effect.fail("Network timeout") * @@ -2987,7 +3008,8 @@ export const tapCauseFilter: { * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * // Simulate a task that fails with a recoverable error * const task1: Effect.Effect = Effect.fail("NetworkError") @@ -3089,7 +3111,8 @@ export declare namespace Retry { * @category Error handling * @example * ```ts - * import { Effect, Schedule } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" * * // Options for configuring retry behavior * const retryOptions: Effect.Retry.Options = { @@ -3130,7 +3153,8 @@ export declare namespace Retry { * * @example * ```ts - * import { Effect, Schedule } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" * * let attempt = 0 * const task = Effect.callback((resume) => { @@ -3192,7 +3216,9 @@ export const retry: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * let attempt = 0 * const networkRequest = Effect.gen(function* () { @@ -3487,7 +3513,8 @@ export const timeoutOption: { * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const slowQuery = Effect.gen(function* () { * yield* Console.log("Starting database query...") @@ -3534,7 +3561,8 @@ export const timeoutOrElse: { * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.delay( * Console.log("Delayed message"), @@ -3564,7 +3592,8 @@ export const delay: { * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.log("Start") @@ -3609,7 +3638,8 @@ export const sleep: (duration: Duration.DurationInput) => Effect = interna * * @example * ```ts - * import { Effect, Duration } from "effect" + * import { Effect } from "effect" + * import { Duration } from "effect/time" * * // Multiple effects with different delays * const effect1 = Effect.delay(Effect.succeed("Fast"), Duration.millis(100)) @@ -3647,7 +3677,8 @@ export const raceAll: >( * * @example * ```ts - * import { Effect, Duration } from "effect" + * import { Effect } from "effect" + * import { Duration } from "effect/time" * * // Multiple effects with different delays and potential failures * const effect1 = Effect.delay(Effect.succeed("First"), Duration.millis(200)) @@ -3852,7 +3883,9 @@ export const filterOrFail: { * * @example * ```ts - * import { Effect, Option, Console } from "effect" + * import { Effect } from "effect" +import * as Option from "effect/data/Option" + * import { Console } from "effect/logging" * * const shouldLog = true * @@ -4107,7 +4140,9 @@ export const matchCauseEager: { * * @example * ```ts - * import { Effect, Console, Cause, Filter } from "effect" + * import { Effect, Cause } from "effect" + * import * as Filter from "effect/data/Filter" + * import { Console } from "effect/logging" * * const task = Effect.fail(new Error("Task failed")) * @@ -4244,7 +4279,10 @@ export const matchEffect: { * * @example * ```ts - * import { Effect, ServiceMap, Console, Option } from "effect" + * import { Effect } from "effect" +import * as Option from "effect/data/Option" + * import { Console } from "effect/logging" + * import { ServiceMap } from "effect/services" * * const Logger = ServiceMap.Key<{ log: (msg: string) => void }>("Logger") * const Database = ServiceMap.Key<{ query: (sql: string) => string }>("Database") @@ -4280,7 +4318,10 @@ export const services: () => Effect, never, R> = int * * @example * ```ts - * import { Effect, ServiceMap, Console, Option } from "effect" + * import { Effect } from "effect" +import * as Option from "effect/data/Option" + * import { Console } from "effect/logging" + * import { ServiceMap } from "effect/services" * * const Logger = ServiceMap.Key<{ log: (msg: string) => void }>("Logger") * const Cache = ServiceMap.Key<{ get: (key: string) => string | null }>("Cache") @@ -4320,7 +4361,9 @@ export const servicesWith: ( * * @example * ```ts - * import { Effect, ServiceMap, Layer } from "effect" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" + * import { Layer } from "effect/services" * * interface Database { * readonly query: (sql: string) => Effect.Effect @@ -4393,7 +4436,8 @@ export const provide: { * * @example * ```ts - * import { Effect, ServiceMap } from "effect" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" * * // Define service keys * const Logger = ServiceMap.Key<{ log: (msg: string) => void }>("Logger") @@ -4432,7 +4476,8 @@ export const provideServices: { * * @example * ```ts - * import { Effect, ServiceMap } from "effect" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" * * interface Database { * readonly query: (sql: string) => Effect.Effect @@ -4463,7 +4508,9 @@ export const service: (key: ServiceMap.Key) => Effect = * * @example * ```ts - * import { Effect, Option, ServiceMap } from "effect" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" +import * as Option from "effect/data/Option" * * // Define a service key * const Logger = ServiceMap.Key<{ log: (msg: string) => void }>("Logger") @@ -4495,7 +4542,8 @@ export const serviceOption: (key: ServiceMap.Key) => Effect void }>("Logger") @@ -4536,7 +4584,9 @@ export const updateServices: { * * @example * ```ts - * import { Effect, ServiceMap, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { ServiceMap } from "effect/services" * * // Define a counter service * const Counter = ServiceMap.Key<{ count: number }>("Counter") @@ -4578,7 +4628,9 @@ export const updateService: { * * @example * ```ts - * import { Effect, ServiceMap, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { ServiceMap } from "effect/services" * * // Define a service for configuration * const Config = ServiceMap.Key<{ apiUrl: string; timeout: number }>("Config") @@ -4629,7 +4681,9 @@ export const provideService: { * * @example * ```ts - * import { Effect, ServiceMap, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { ServiceMap } from "effect/services" * * // Define a database connection service * interface DatabaseConnection { @@ -4686,7 +4740,8 @@ export const provideServiceEffect: { * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const task = (id: number) => Effect.gen(function* () { * yield* Console.log(`Task ${id} starting`) @@ -4730,7 +4785,9 @@ export const withConcurrency: { * * @example * ```ts - * import { Effect, Console, Scope } from "effect" + * import { Effect } from "effect" + * import { Scope } from "effect/resources" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * const currentScope = yield* Effect.scope @@ -4765,7 +4822,8 @@ export const scope: Effect = internal.scope * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const resource = Effect.acquireRelease( * Console.log("Acquiring resource").pipe(Effect.as("resource")), @@ -4798,7 +4856,9 @@ export const scoped: ( * * @example * ```ts - * import { Effect, Console, Scope } from "effect" + * import { Effect } from "effect" + * import { Scope } from "effect/resources" + * import { Console } from "effect/logging" * * const program = Effect.scopedWith((scope) => * Effect.gen(function* () { @@ -4850,7 +4910,8 @@ export const scopedWith: ( * * @example * ```ts - * import { Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" * * // Simulate a resource that needs cleanup * interface FileHandle { @@ -4914,7 +4975,8 @@ export const acquireRelease: ( * * @example * ```ts - * import { Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" * * interface Database { * readonly connection: string @@ -4975,7 +5037,8 @@ export const acquireUseRelease: ( * * @example * ```ts - * import { Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.scoped( * Effect.gen(function* () { @@ -5022,7 +5085,8 @@ export const addFinalizer: ( * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const task = Effect.gen(function* () { * yield* Console.log("Task started") @@ -5064,7 +5128,8 @@ export const ensuring: { * * @example * ```ts - * import { Effect, Console, Cause } from "effect" + * import { Effect, Cause } from "effect" + * import { Console } from "effect/logging" * * const task = Effect.fail(new Error("Something went wrong")) * @@ -5097,7 +5162,8 @@ export const onError: { * * @example * ```ts - * import { Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" * * const task = Effect.succeed(42) * @@ -5171,7 +5237,8 @@ export const onExitInterruptible: { * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * let i = 1 * const expensiveTask = Effect.promise(() => { @@ -5245,7 +5312,8 @@ export const cached: (self: Effect) => Effect> * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * let i = 1 * const expensiveTask = Effect.promise(() => { @@ -5316,7 +5384,8 @@ export const cachedWithTTL: { * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * let i = 1 * const expensiveTask = Effect.promise(() => { @@ -5409,7 +5478,9 @@ export const interruptible: ( * * @example * ```ts - * import { Effect, Console, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" + * import { Console } from "effect/logging" * * const task = Effect.forever(Effect.succeed("working...")) * @@ -5441,7 +5512,9 @@ export const onInterrupt: { * * @example * ```ts - * import { Effect, Console, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" + * import { Console } from "effect/logging" * * const criticalTask = Effect.gen(function* () { * yield* Console.log("Starting critical section...") @@ -5469,7 +5542,8 @@ export const uninterruptible: ( * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.uninterruptibleMask((restore) => * Effect.gen(function* () { @@ -5505,7 +5579,8 @@ export const uninterruptibleMask: ( * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.interruptibleMask((restore) => * Effect.gen(function* () { @@ -5794,7 +5869,8 @@ export declare namespace Repeat { * @category repetition / recursion * @example * ```ts - * import { Effect, Schedule } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" * * // Options for configuring repeat behavior * const repeatOptions: Effect.Repeat.Options = { @@ -5817,7 +5893,9 @@ export declare namespace Repeat { * * @example * ```ts - * import { Effect, Console, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" + * import { Console } from "effect/logging" * * const task = Effect.gen(function* () { * yield* Console.log("Task running...") @@ -5869,7 +5947,9 @@ export const forever: | { readonly autoYield? * @example * ```ts * // Success Example - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * const action = Console.log("success") * const policy = Schedule.addDelay(Schedule.recurs(2), () => "100 millis") @@ -5880,7 +5960,8 @@ export const forever: | { readonly autoYield? * * @example * // Failure Example - * import { Effect, Schedule } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" * * let count = 0 * @@ -5941,7 +6022,10 @@ export const repeat: { * * @example * ```ts - * import { Effect, Schedule, Console, Option } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" +import * as Option from "effect/data/Option" + * import { Console } from "effect/logging" * * let attempt = 0 * const task = Effect.gen(function* () { @@ -5997,7 +6081,9 @@ export const repeatOrElse: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * const task = Effect.gen(function* () { * yield* Console.log("Task executing...") @@ -6051,7 +6137,9 @@ export const schedule = dual< * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * const task = (input: number) => * Effect.gen(function* () { @@ -6611,7 +6699,8 @@ export const request: { * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const longRunningTask = Effect.gen(function* () { * yield* Effect.sleep("2 seconds") @@ -6650,7 +6739,9 @@ export const fork: < * * @example * ```ts - * import { Effect, Scope, Fiber } from "effect" + * import { Effect } from "effect" + * import { Scope } from "effect/resources" + * import { Fiber } from "effect/runtime" * * const task = Effect.gen(function* () { * yield* Effect.sleep("10 seconds") @@ -6694,7 +6785,8 @@ export const forkIn: { * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const backgroundTask = Effect.gen(function* () { * yield* Effect.sleep("5 seconds") @@ -6737,7 +6829,8 @@ export const forkScoped: < * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const daemonTask = Effect.gen(function* () { * while (true) { @@ -6823,7 +6916,10 @@ export interface RunOptions { * @example * ```ts * // Title: Running an Effect in the Background - * import { Effect, Console, Schedule, Fiber } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Fiber } from "effect/runtime" + * import { Console } from "effect/logging" * * // ┌─── Effect * // ▼ @@ -6852,7 +6948,8 @@ export const runFork: (effect: Effect, options?: RunOptions | * * @example * ```ts - * import { Effect, ServiceMap } from "effect" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" * * interface Logger { * log: (message: string) => void @@ -6924,7 +7021,8 @@ export const runPromise: ( * * @example * ```ts - * import { Effect, ServiceMap } from "effect" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" * * interface Config { * apiUrl: string @@ -7008,7 +7106,8 @@ export const runPromiseExit: ( * * @example * ```ts - * import { Effect, ServiceMap, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { ServiceMap } from "effect/services" * * interface Database { * query: (sql: string) => string @@ -7104,7 +7203,8 @@ export const runSync: (effect: Effect) => A = internal.runSync * * @example * ```ts - * import { Effect, ServiceMap } from "effect" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" * * interface MathService { * add: (a: number, b: number) => number @@ -7208,7 +7308,8 @@ export const runSyncExit: (effect: Effect) => Exit.Exit = inte * * @example * ```ts - * import { Effect, ServiceMap, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { ServiceMap } from "effect/services" * * // Define a logger service * const Logger = ServiceMap.Key<{ log: (msg: string) => void }>("Logger") @@ -7934,7 +8035,8 @@ export const fnUntraced: fn.Untraced = internal.fnUntraced * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.clockWith((clock) => * clock.currentTimeMillis.pipe( @@ -8175,7 +8277,8 @@ export const logTrace: (...message: ReadonlyArray) => Effect = intern * * @example * ```ts - * import { Effect, Logger } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Create a custom logger that logs to the console * const customLogger = Logger.make(({ message }) => @@ -8334,7 +8437,8 @@ export const withLogSpan = dual< * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * const counter = Metric.counter("effect_executions", { * description: "Counts effect executions" @@ -8353,7 +8457,8 @@ export const withLogSpan = dual< * * @example * ```ts - * import { Effect, Metric, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Metric } from "effect/observability" * * // Track different exit types with custom mapping * const exitTracker = Metric.frequency("exit_types", { @@ -8413,7 +8518,8 @@ export const track: { * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * const successCounter = Metric.counter("successes").pipe( * Metric.withConstantInput(1) @@ -8431,7 +8537,8 @@ export const track: { * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * // Track successful request sizes * const requestSizeGauge = Metric.gauge("request_size_bytes") @@ -8488,7 +8595,8 @@ export const trackSuccesses: { * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * const errorCounter = Metric.counter("errors").pipe( * Metric.withConstantInput(1) @@ -8506,7 +8614,8 @@ export const trackSuccesses: { * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * // Track error types using frequency metric * const errorTypeFrequency = Metric.frequency("error_types") @@ -8563,7 +8672,8 @@ export const trackErrors: { * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * const defectCounter = Metric.counter("defects").pipe( * Metric.withConstantInput(1) @@ -8581,7 +8691,8 @@ export const trackErrors: { * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * // Track defect types using frequency metric * const defectTypeFrequency = Metric.frequency("defect_types") @@ -8638,7 +8749,9 @@ export const trackDefects: { * * @example * ```ts - * import { Effect, Metric, Duration } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Duration } from "effect/time" * * const executionTimer = Metric.timer("execution_time") * @@ -8654,7 +8767,9 @@ export const trackDefects: { * * @example * ```ts - * import { Effect, Metric, Duration } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Duration } from "effect/time" * * // Track execution time in milliseconds using custom mapping * const durationGauge = Metric.gauge("execution_millis") @@ -8762,7 +8877,8 @@ export class Transaction extends ServiceMap.Key< * * @example * ```ts - * import { Effect, TxRef } from "effect" + * import { Effect } from "effect" + * import { TxRef } from "effect/transactions" * * const program = Effect.gen(function* () { * const ref1 = yield* TxRef.make(0) @@ -8793,7 +8909,8 @@ export const atomic = ( * * @example * ```ts - * import { Effect, TxRef } from "effect" + * import { Effect } from "effect" + * import { TxRef } from "effect/transactions" * * const program = Effect.atomicWith((txState) => * Effect.gen(function* () { @@ -8852,7 +8969,8 @@ export const atomicWith = ( * * @example * ```ts - * import { Effect, TxRef } from "effect" + * import { Effect } from "effect" + * import { TxRef } from "effect/transactions" * * const program = Effect.gen(function* () { * const ref1 = yield* TxRef.make(0) @@ -8894,7 +9012,8 @@ export const transaction = ( * * @example * ```ts - * import { Effect, TxRef } from "effect" + * import { Effect } from "effect" + * import { TxRef } from "effect/transactions" * * const program = Effect.transactionWith((txState) => * Effect.gen(function* () { @@ -9018,8 +9137,8 @@ function clearTransaction(state: Transaction["Service"]) { * @example * * ```ts - * import * as Effect from "effect/Effect" - * import * as TxRef from "effect/TxRef" + * import { Effect } from "effect" + * import * as TxRef from "effect/transactions/TxRef" * * const program = Effect.gen(function*() { * // create a transactional reference diff --git a/packages/effect/src/Exit.ts b/packages/effect/src/Exit.ts index 1ecbd11858..5b515c633c 100644 --- a/packages/effect/src/Exit.ts +++ b/packages/effect/src/Exit.ts @@ -10,12 +10,12 @@ * @since 2.0.0 */ import type * as Cause from "./Cause.ts" +import type * as Filter from "./data/Filter.ts" import type * as Effect from "./Effect.ts" -import type * as Filter from "./Filter.ts" import * as core from "./internal/core.ts" import * as effect from "./internal/effect.ts" import type { version } from "./internal/version.ts" -import type { NoInfer } from "./Types.ts" +import type { NoInfer } from "./types/Types.ts" /** * @example diff --git a/packages/effect/src/Function.ts b/packages/effect/src/Function.ts index c8c3dc33e2..c561060d4a 100644 --- a/packages/effect/src/Function.ts +++ b/packages/effect/src/Function.ts @@ -1,15 +1,15 @@ /** * @since 2.0.0 */ -import type { TypeLambda } from "./HKT.ts" -import { pipeArguments } from "./Pipeable.ts" +import { pipeArguments } from "./interfaces/Pipeable.ts" +import type { TypeLambda } from "./types/HKT.ts" /** * Type lambda for function types, used for higher-kinded type operations. * * @example * ```ts - * import type { Kind } from "effect/HKT" + * import type { Kind } from "effect/types/HKT" * import type { FunctionTypeLambda } from "effect/Function" * * // Create a function type using the type lambda @@ -30,10 +30,10 @@ export interface FunctionTypeLambda extends TypeLambda { * @example * ```ts * import * as assert from "node:assert" - * import { isFunction } from "effect/Predicate" + * import * as Predicate from "effect/data/Predicate" * - * assert.deepStrictEqual(isFunction(isFunction), true) - * assert.deepStrictEqual(isFunction("function"), false) + * assert.deepStrictEqual(Predicate.isFunction(Predicate.isFunction), true) + * assert.deepStrictEqual(Predicate.isFunction("function"), false) * ``` * * @category guards @@ -183,7 +183,7 @@ export const dual: { * ```ts * import * as assert from "node:assert" * import { pipe, apply } from "effect/Function" - * import { length } from "effect/String" + * import { length } from "effect/primitives/String" * * assert.deepStrictEqual(pipe(length, apply("hello")), 5) * ``` @@ -530,7 +530,8 @@ export const untupled = , B>(f: (a: A) => B): ( * becomes: * * ```ts skip-type-checking - * import { pipe, Array } from "effect" + * import { pipe } from "effect" + * import { Array } from "effect/collections" * * pipe(as, Array.map(f), Array.filter(g)) * ``` diff --git a/packages/effect/src/Utils.ts b/packages/effect/src/Utils.ts index 81fe4c4be7..4e304f4050 100644 --- a/packages/effect/src/Utils.ts +++ b/packages/effect/src/Utils.ts @@ -1,11 +1,11 @@ /** * @since 2.0.0 */ +import { isNullable, isObject } from "./data/Predicate.ts" import { identity } from "./Function.ts" -import type { Kind, TypeLambda } from "./HKT.ts" import { getBugErrorMessage } from "./internal/errors.ts" -import { isNullable, isObject } from "./Predicate.ts" -import type * as Types from "./Types.ts" +import type { Kind, TypeLambda } from "./types/HKT.ts" +import type * as Types from "./types/Types.ts" /** * Copyright 2014 Thom Chiovoloni, released under the MIT license. @@ -49,7 +49,8 @@ export type GenKindTypeId = "~effect/Utils/GenKind" /** * @example * ```ts - * import { Utils, Option } from "effect" + * import { Utils } from "effect" +import * as Option from "effect/data/Option" * * // A GenKind wraps types to make them generator-compatible * declare const genKind: Utils.GenKind @@ -67,7 +68,8 @@ export interface GenKind extends Variance() * const genValue = adapter(Option.some(42)) @@ -208,7 +210,8 @@ export const makeGenKind = ( /** * @example * ```ts - * import { Utils, Option } from "effect" + * import { Utils } from "effect" +import * as Option from "effect/data/Option" * * // Variance defines the type parameter relationships * declare const variance: Utils.Variance @@ -228,7 +231,8 @@ export interface Variance { /** * @example * ```ts - * import { Utils, Option } from "effect" + * import { Utils } from "effect" +import * as Option from "effect/data/Option" * * // Gen enables generator-based syntax * declare const gen: Utils.Gen> @@ -267,7 +271,8 @@ export type Gen = < /** * @example * ```ts - * import { Utils, Option } from "effect" + * import { Utils } from "effect" +import * as Option from "effect/data/Option" * * // Adapter enables chaining computations in generator functions * const adapter: Utils.Adapter = Utils.adapter() @@ -549,7 +554,8 @@ export interface Adapter { /** * @example * ```ts - * import { Utils, Result } from "effect" + * import { Utils } from "effect" + * import { Result } from "effect/data" * * // Create an adapter for Result type * const adapter = Utils.adapter() diff --git a/packages/effect/src/batching/Request.ts b/packages/effect/src/batching/Request.ts index 2e513462ac..29772122b3 100644 --- a/packages/effect/src/batching/Request.ts +++ b/packages/effect/src/batching/Request.ts @@ -14,16 +14,16 @@ * @since 2.0.0 */ import type * as Cause from "../Cause.ts" +import type * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" import type * as Effect from "../Effect.ts" import type * as Exit from "../Exit.ts" import { dual } from "../Function.ts" import * as core from "../internal/core.ts" import { StructuralPrototype } from "../internal/core.ts" import * as internalEffect from "../internal/effect.ts" -import type * as Option from "../Option.ts" -import { hasProperty } from "../Predicate.ts" -import type * as ServiceMap from "../ServiceMap.ts" -import type * as Types from "../Types.ts" +import type * as ServiceMap from "../services/ServiceMap.ts" +import type * as Types from "../types/Types.ts" /** * @example @@ -224,7 +224,8 @@ export type Result> = T extends Request { @@ -630,7 +631,8 @@ export interface Entry { /** * @example * ```ts - * import { Effect, ServiceMap } from "effect" + * import { Effect } from "effect" +import { ServiceMap } from "effect/services" * import { Request } from "effect/batching" * * interface GetUser extends Request.Request { diff --git a/packages/effect/src/batching/RequestResolver.ts b/packages/effect/src/batching/RequestResolver.ts index 697b49d60e..695059ce20 100644 --- a/packages/effect/src/batching/RequestResolver.ts +++ b/packages/effect/src/batching/RequestResolver.ts @@ -1,20 +1,20 @@ /** * @since 2.0.0 */ -import type { NonEmptyArray } from "../Array.ts" import * as Cache from "../caching/Cache.ts" -import * as Duration from "../Duration.ts" +import type { NonEmptyArray } from "../collections/Array.ts" +import * as MutableHashMap from "../collections/MutableHashMap.ts" +import { hasProperty } from "../data/Predicate.ts" import type { Effect } from "../Effect.ts" import { constTrue, dual, identity } from "../Function.ts" +import { type Pipeable, pipeArguments } from "../interfaces/Pipeable.ts" import { exitFail, exitSucceed } from "../internal/core.ts" import * as effect from "../internal/effect.ts" import * as internal from "../internal/request.ts" -import * as MutableHashMap from "../MutableHashMap.ts" -import { type Pipeable, pipeArguments } from "../Pipeable.ts" -import { hasProperty } from "../Predicate.ts" -import * as ServiceMap from "../ServiceMap.ts" -import * as Tracer from "../Tracer.ts" -import type * as Types from "../Types.ts" +import * as Tracer from "../observability/Tracer.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import * as Duration from "../time/Duration.ts" +import type * as Types from "../types/Types.ts" import type * as Request from "./Request.ts" /** @@ -361,10 +361,10 @@ export const fromFunctionBatched = ( */ export const fromEffect = ( f: (entry: Request.Entry) => Effect, Request.Error> -): RequestResolver => { - effect.fork(effect.void) // ensure middleware is registered - return make((entries) => +): RequestResolver => + make((entries) => effect.callback((resume) => { + effect.fork(effect.void) // ensure middleware is registered const parent = effect.getCurrentFiber()! let done = 0 for (let i = 0; i < entries.length; i++) { @@ -380,7 +380,6 @@ export const fromEffect = ( } }) ) -} /** * Constructs a request resolver from a list of tags paired to functions, that takes @@ -882,77 +881,8 @@ export const withSpan: { })) /** - * Wraps a request resolver in a cache, allowing it to cache results up to a - * specified capacity and optional time-to-live. - * * @since 4.0.0 - * @category Caching - */ -export const asCache: { - < - A extends Request.Any, - ServiceMode extends "lookup" | "construction" = "lookup" - >(options: { - readonly capacity: number - readonly timeToLive?: ((exit: Request.Result, request: A) => Duration.DurationInput) | undefined - readonly requireServicesAt?: ServiceMode & "lookup" | "construction" | undefined - }): (self: RequestResolver) => Effect< - Cache.Cache< - A, - Request.Success, - Request.Error, - ServiceMode extends "lookup" ? Request.Services : never - >, - never, - ServiceMode extends "lookup" ? never : Request.Services - > - < - A extends Request.Any, - ServiceMode extends "lookup" | "construction" = "lookup" - >(self: RequestResolver, options: { - readonly capacity: number - readonly timeToLive?: ((exit: Request.Result, request: A) => Duration.DurationInput) | undefined - readonly requireServicesAt?: ServiceMode & "lookup" | "construction" | undefined - }): Effect< - Cache.Cache< - A, - Request.Success, - Request.Error, - ServiceMode extends "lookup" ? Request.Services : never - >, - never, - ServiceMode extends "lookup" ? never : Request.Services - > -} = dual(2, < - A extends Request.Any, - ServiceMode extends "lookup" | "construction" = "lookup" ->(self: RequestResolver, options: { - readonly capacity: number - readonly timeToLive?: ((exit: Request.Result, request: A) => Duration.DurationInput) | undefined - readonly requireServicesAt?: ServiceMode | undefined -}): Effect< - Cache.Cache< - A, - Request.Success, - Request.Error, - ServiceMode extends "lookup" ? Request.Services : never - >, - never, - ServiceMode extends "lookup" ? never : Request.Services -> => - Cache.makeWithTtl({ - capacity: options.capacity, - timeToLive: options.timeToLive as any, - requireServicesAt: options.requireServicesAt ?? "lookup" as ServiceMode, - lookup: (req: A) => internal.request(req, self) - })) - -/** - * Adds caching capabilities to a request resolver, allowing it to cache - * results up to a specified capacity and optional time-to-live. - * - * @since 4.0.0 - * @category Caching + * @category combinators */ export const withCache: { (options: { @@ -968,6 +898,10 @@ export const withCache: { readonly timeToLive?: ((exit: Request.Result, request: A) => Duration.DurationInput) | undefined }): Effect> => effect.map( - asCache(self, options), + Cache.makeWithTtl({ + capacity: options.capacity, + timeToLive: options.timeToLive as any, + lookup: (req: A) => internal.request(req, self) as Effect, Request.Error> + }), (cache) => fromEffect((entry) => effect.provideServices(Cache.get(cache, entry.request), entry.services)) )) diff --git a/packages/effect/src/caching/Cache.ts b/packages/effect/src/caching/Cache.ts index 8b175996e9..322f4c4470 100644 --- a/packages/effect/src/caching/Cache.ts +++ b/packages/effect/src/caching/Cache.ts @@ -1,21 +1,21 @@ /** * @since 4.0.0 */ -import * as Deferred from "../Deferred.ts" -import * as Duration from "../Duration.ts" +import * as Iterable from "../collections/Iterable.ts" +import * as MutableHashMap from "../collections/MutableHashMap.ts" +import * as Deferred from "../concurrency/Deferred.ts" +import * as Option from "../data/Option.ts" +import type { Predicate } from "../data/Predicate.ts" import type * as Effect from "../Effect.ts" import type * as Exit from "../Exit.ts" -import type * as Fiber from "../Fiber.ts" import { dual } from "../Function.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" import * as core from "../internal/core.ts" import { PipeInspectableProto } from "../internal/core.ts" import * as effect from "../internal/effect.ts" -import * as Iterable from "../Iterable.ts" -import * as MutableHashMap from "../MutableHashMap.ts" -import * as Option from "../Option.ts" -import type { Pipeable } from "../Pipeable.ts" -import type { Predicate } from "../Predicate.ts" -import * as ServiceMap from "../ServiceMap.ts" +import type * as Fiber from "../runtime/Fiber.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import * as Duration from "../time/Duration.ts" /** * @since 4.0.0 @@ -35,7 +35,8 @@ export type TypeId = "~effect/caching/Cache" * * @example * ```ts - * import { Effect, Duration } from "effect" + * import { Effect } from "effect" +import { Duration } from "effect/time" * import { Cache } from "effect/caching" * * // Basic cache with string keys and number values @@ -56,7 +57,8 @@ export type TypeId = "~effect/caching/Cache" * * @example * ```ts - * import { Effect, Duration } from "effect" + * import { Effect } from "effect" +import { Duration } from "effect/time" * import { Cache } from "effect/caching" * * // Cache with error handling @@ -79,7 +81,9 @@ export type TypeId = "~effect/caching/Cache" * * @example * ```ts - * import { Effect, Duration, Data } from "effect" + * import { Effect } from "effect" + * import { Data } from "effect/data" +import { Duration } from "effect/time" * import { Cache } from "effect/caching" * * // Cache with complex key types and TTL @@ -103,11 +107,11 @@ export type TypeId = "~effect/caching/Cache" * @since 4.0.0 * @category Models */ -export interface Cache extends Pipeable { +export interface Cache extends Pipeable { readonly [TypeId]: TypeId readonly map: MutableHashMap.MutableHashMap> readonly capacity: number - readonly lookup: (key: Key) => Effect.Effect + readonly lookup: (key: Key) => Effect.Effect readonly timeToLive: (exit: Exit.Exit, key: Key) => Duration.Duration } @@ -131,7 +135,8 @@ export interface Entry { * * @example * ```ts - * import { Effect, Exit, Duration } from "effect" + * import { Effect, Exit } from "effect" +import { Duration } from "effect/time" * import { Cache } from "effect/caching" * * // Cache with different TTL for success vs failure @@ -180,23 +185,12 @@ export interface Entry { * @since 4.0.0 * @category Constructors */ -export const makeWithTtl = < - Key, - A, - E = never, - R = never, - ServiceMode extends "lookup" | "construction" = "construction" ->(options: { +export const makeWithTtl = (options: { readonly lookup: (key: Key) => Effect.Effect readonly capacity: number readonly timeToLive?: ((exit: Exit.Exit, key: Key) => Duration.DurationInput) | undefined - readonly requireServicesAt?: ServiceMode & "lookup" | "construction" | undefined -}): Effect.Effect< - Cache, - never, - ServiceMode extends "lookup" ? never : R -> => - effect.servicesWith((services: ServiceMap.ServiceMap) => { +}): Effect.Effect, never, R> => + effect.servicesWith((services: ServiceMap.ServiceMap) => { const self = Object.create(Proto) self.lookup = (key: Key): Effect.Effect => effect.updateServices( @@ -261,25 +255,12 @@ export const makeWithTtl = < * @since 4.0.0 * @category Constructors */ -export const make = < - Key, - A, - E = never, - R = never, - ServiceMode extends "lookup" | "construction" = "construction" ->( - options: { - readonly lookup: (key: Key) => Effect.Effect - readonly capacity: number - readonly timeToLive?: Duration.DurationInput | undefined - readonly requireServicesAt?: ServiceMode & "lookup" | "construction" | undefined - } -): Effect.Effect< - Cache, - never, - ServiceMode extends "lookup" ? never : R -> => - makeWithTtl({ +export const make = (options: { + readonly lookup: (key: Key) => Effect.Effect + readonly capacity: number + readonly timeToLive?: Duration.DurationInput | undefined +}): Effect.Effect, never, R> => + makeWithTtl({ ...options, timeToLive: options.timeToLive ? () => options.timeToLive! : defaultTimeToLive }) @@ -384,11 +365,11 @@ const defaultTimeToLive = (_: Exit.Exit, _key: unknown): Duration.Du * @category Combinators */ export const get: { - (key: Key): (self: Cache) => Effect.Effect - (self: Cache, key: Key): Effect.Effect + (key: Key): (self: Cache) => Effect.Effect + (self: Cache, key: Key): Effect.Effect } = dual( 2, - (self: Cache, key: Key): Effect.Effect => + (self: Cache, key: Key): Effect.Effect => core.withFiber((fiber) => { const oentry = MutableHashMap.get(self.map, key) if (Option.isSome(oentry) && !hasExpired(oentry.value, fiber)) { @@ -424,7 +405,7 @@ const hasExpired = (entry: Entry, fiber: Fiber.Fiber= entry.expiresAt } -const checkCapacity = (self: Cache) => { +const checkCapacity = (self: Cache) => { let diff = MutableHashMap.size(self.map) - self.capacity if (diff <= 0) return // MutableHashMap has insertion order, so we can remove the oldest entries @@ -446,7 +427,8 @@ const checkCapacity = (self: Cache) => { * @example * ```ts * import { Cache } from "effect/caching" - * import { Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" * * const program = Effect.gen(function*() { * const cache = yield* Cache.make({ @@ -472,7 +454,9 @@ const checkCapacity = (self: Cache) => { * @example * ```ts * import { Cache } from "effect/caching" - * import { Effect, Option, TestClock } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" +import { TestClock } from "effect/testing" * * // Expired entries return None * const program = Effect.gen(function*() { @@ -501,7 +485,10 @@ const checkCapacity = (self: Cache) => { * @example * ```ts * import { Cache } from "effect/caching" - * import { Effect, Option, Deferred, Fiber } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" +import * as Deferred from "effect/concurrency/Deferred" +import { Fiber } from "effect/runtime" * * // Waits for ongoing computation to complete * const program = Effect.gen(function*() { @@ -530,19 +517,19 @@ const checkCapacity = (self: Cache) => { * @category Combinators */ export const getOption: { - (key: Key): (self: Cache) => Effect.Effect, E> - (self: Cache, key: Key): Effect.Effect, E> + (key: Key): (self: Cache) => Effect.Effect, E> + (self: Cache, key: Key): Effect.Effect, E> } = dual( 2, - (self: Cache, key: Key): Effect.Effect, E> => + (self: Cache, key: Key): Effect.Effect, E> => core.withFiber((fiber) => { const oentry = getOptionImpl(self, key, fiber) return Option.isSome(oentry) ? effect.asSome(Deferred.await(oentry.value.deferred)) : effect.succeedNone }) ) -const getOptionImpl = ( - self: Cache, +const getOptionImpl = ( + self: Cache, key: Key, fiber: Fiber.Fiber, isRead = true @@ -568,11 +555,11 @@ const getOptionImpl = ( * @category Combinators */ export const getSuccess: { - (key: Key): (self: Cache) => Effect.Effect> - (self: Cache, key: Key): Effect.Effect> + (key: Key): (self: Cache) => Effect.Effect> + (self: Cache, key: Key): Effect.Effect> } = dual( 2, - (self: Cache, key: Key): Effect.Effect> => + (self: Cache, key: Key): Effect.Effect> => core.withFiber((fiber) => effect.succeed( getOptionImpl(self, key, fiber).pipe( @@ -630,7 +617,8 @@ export const getSuccess: { * * @example * ```ts - * import { Effect, TestClock } from "effect" + * import { Effect } from "effect" +import { TestClock } from "effect/testing" * import { Cache } from "effect/caching" * * // TTL behavior with set operations @@ -680,11 +668,11 @@ export const getSuccess: { * @category Combinators */ export const set: { - (key: Key, value: A): (self: Cache) => Effect.Effect - (self: Cache, key: Key, value: A): Effect.Effect + (key: Key, value: A): (self: Cache) => Effect.Effect + (self: Cache, key: Key, value: A): Effect.Effect } = dual( 3, - (self: Cache, key: Key, value: A): Effect.Effect => + (self: Cache, key: Key, value: A): Effect.Effect => core.withFiber((fiber) => { const exit = core.exitSucceed(value) const deferred = Deferred.unsafeMake() @@ -730,7 +718,8 @@ export const set: { * * @example * ```ts - * import { Effect, TestClock } from "effect" + * import { Effect } from "effect" +import { TestClock } from "effect/testing" * import { Cache } from "effect/caching" * * // TTL expiration behavior @@ -789,8 +778,8 @@ export const set: { * @category Combinators */ export const has: { - (key: Key): (self: Cache) => Effect.Effect - (self: Cache, key: Key): Effect.Effect + (key: Key): (self: Cache) => Effect.Effect + (self: Cache, key: Key): Effect.Effect } = dual( 2, (self: Cache, key: Key): Effect.Effect => @@ -842,9 +831,9 @@ export const has: { * @category Combinators */ export const invalidate: { - (key: Key): (self: Cache) => Effect.Effect - (self: Cache, key: Key): Effect.Effect -} = dual(2, (self: Cache, key: Key): Effect.Effect => + (key: Key): (self: Cache) => Effect.Effect + (self: Cache, key: Key): Effect.Effect +} = dual(2, (self: Cache, key: Key): Effect.Effect => effect.sync(() => { MutableHashMap.remove(self.map, key) })) @@ -898,11 +887,11 @@ export const invalidate: { * @category Combinators */ export const invalidateWhen: { - (key: Key, f: Predicate): (self: Cache) => Effect.Effect - (self: Cache, key: Key, f: Predicate): Effect.Effect + (key: Key, f: Predicate): (self: Cache) => Effect.Effect + (self: Cache, key: Key, f: Predicate): Effect.Effect } = dual( 3, - (self: Cache, key: Key, f: Predicate): Effect.Effect => + (self: Cache, key: Key, f: Predicate): Effect.Effect => core.withFiber((fiber) => { const oentry = getOptionImpl(self, key, fiber, false) if (Option.isNone(oentry)) { @@ -960,7 +949,9 @@ export const invalidateWhen: { * * @example * ```ts - * import { Effect, TestClock, Duration } from "effect" + * import { Effect } from "effect" +import { Duration } from "effect/time" +import { TestClock } from "effect/testing" * import { Cache } from "effect/caching" * * // Refresh resets TTL (Time To Live) @@ -1011,11 +1002,11 @@ export const invalidateWhen: { * @category Combinators */ export const refresh: { - (key: Key): (self: Cache) => Effect.Effect - (self: Cache, key: Key): Effect.Effect + (key: Key): (self: Cache) => Effect.Effect + (self: Cache, key: Key): Effect.Effect } = dual( 2, - (self: Cache, key: Key): Effect.Effect => + (self: Cache, key: Key): Effect.Effect => core.withFiber((fiber) => { const deferred = Deferred.unsafeMake() const entry: Entry = { @@ -1082,7 +1073,7 @@ export const refresh: { * @since 4.0.0 * @category Combinators */ -export const invalidateAll = (self: Cache): Effect.Effect => +export const invalidateAll = (self: Cache): Effect.Effect => effect.sync(() => { MutableHashMap.clear(self.map) }) @@ -1125,7 +1116,7 @@ export const invalidateAll = (self: Cache): Effect.E * @since 4.0.0 * @category Combinators */ -export const size = (self: Cache): Effect.Effect => +export const size = (self: Cache): Effect.Effect => effect.sync(() => MutableHashMap.size(self.map)) /** @@ -1158,7 +1149,7 @@ export const size = (self: Cache): Effect.Effect(self: Cache): Effect.Effect> => +export const keys = (self: Cache): Effect.Effect> => core.withFiber((fiber) => { const now = fiber.getRef(effect.ClockRef).unsafeCurrentTimeMillis() return effect.succeed(Iterable.filterMap(self.map, ([key, entry]) => { @@ -1201,7 +1192,7 @@ export const keys = (self: Cache): Effect.Effect(self: Cache): Effect.Effect> => +export const values = (self: Cache): Effect.Effect> => effect.map(entries(self), Iterable.map(([, value]) => value)) /** @@ -1212,7 +1203,7 @@ export const values = (self: Cache): Effect.Effect(self: Cache): Effect.Effect> => +export const entries = (self: Cache): Effect.Effect> => core.withFiber((fiber) => { const now = fiber.getRef(effect.ClockRef).unsafeCurrentTimeMillis() return effect.succeed(Iterable.filterMap(self.map, ([key, entry]) => { diff --git a/packages/effect/src/Array.ts b/packages/effect/src/collections/Array.ts similarity index 92% rename from packages/effect/src/Array.ts rename to packages/effect/src/collections/Array.ts index 776d11aa7d..2f45edfe85 100644 --- a/packages/effect/src/Array.ts +++ b/packages/effect/src/collections/Array.ts @@ -3,29 +3,29 @@ * * @since 2.0.0 */ -import * as Equal from "./Equal.ts" -import * as Equivalence from "./Equivalence.ts" -import * as Filter from "./Filter.ts" -import type { LazyArg } from "./Function.ts" -import { dual, identity } from "./Function.ts" -import type { TypeLambda } from "./HKT.ts" -import * as internalArray from "./internal/array.ts" -import * as internalDoNotation from "./internal/doNotation.ts" -import * as moduleIterable from "./Iterable.ts" -import * as Option from "./Option.ts" -import * as Order from "./Order.ts" -import * as Predicate from "./Predicate.ts" -import * as Record from "./Record.ts" -import * as Result from "./Result.ts" -import * as Tuple from "./Tuple.ts" -import type { NoInfer } from "./Types.ts" +import * as moduleIterable from "../collections/Iterable.ts" +import * as Equivalence from "../data/Equivalence.ts" +import * as Filter from "../data/Filter.ts" +import * as Option from "../data/Option.ts" +import * as Order from "../data/Order.ts" +import * as Predicate from "../data/Predicate.ts" +import * as Record from "../data/Record.ts" +import * as Result from "../data/Result.ts" +import * as Tuple from "../data/Tuple.ts" +import type { LazyArg } from "../Function.ts" +import { dual, identity } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as internalArray from "../internal/array.ts" +import * as internalDoNotation from "../internal/doNotation.ts" +import type { TypeLambda } from "../types/HKT.ts" +import type { NoInfer } from "../types/Types.ts" /** * Reference to the global Array constructor. * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const arr = new Array.Array(3) * console.log(arr) // [undefined, undefined, undefined] @@ -41,8 +41,8 @@ export const Array = globalThis.Array * * @example * ```ts - * import type { Kind } from "effect/HKT" - * import type { ReadonlyArrayTypeLambda } from "effect/Array" + * import type { Kind } from "effect/types/HKT" + * import type { ReadonlyArrayTypeLambda } from "effect/collections/Array" * * // Create a ReadonlyArray type using the type lambda * type NumberArray = Kind @@ -61,7 +61,7 @@ export interface ReadonlyArrayTypeLambda extends TypeLambda { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const nonEmpty: Array.NonEmptyReadonlyArray = [1, 2, 3] * const head = nonEmpty[0] // 1 (guaranteed to exist) @@ -77,7 +77,7 @@ export type NonEmptyReadonlyArray = readonly [A, ...Array] * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const nonEmpty: Array.NonEmptyArray = [1, 2, 3] * nonEmpty.push(4) // Mutable operations are allowed @@ -93,7 +93,7 @@ export type NonEmptyArray = [A, ...Array] * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.make(1, 2, 3) * console.log(result) // [1, 2, 3] @@ -111,7 +111,7 @@ export const make = >( * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.allocate(3) * console.log(result) // [ <3 empty items> ] @@ -129,7 +129,7 @@ export const allocate = (n: number): Array => new Arra * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.makeBy(5, n => n * 2) * console.log(result) // [0, 2, 4, 6, 8] @@ -155,7 +155,7 @@ export const makeBy: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.range(1, 3) * console.log(result) // [1, 2, 3] @@ -174,7 +174,7 @@ export const range = (start: number, end: number): NonEmptyArray => * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.replicate("a", 3) * console.log(result) // ["a", "a", "a"] @@ -195,7 +195,7 @@ export const replicate: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.fromIterable(new Set([1, 2, 3])) * console.log(result) // [1, 2, 3] @@ -212,7 +212,7 @@ export const fromIterable = (collection: Iterable): Array => * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * console.log(Array.ensure("a")) // ["a"] * console.log(Array.ensure(["a"])) // ["a"] @@ -229,7 +229,7 @@ export const ensure = (self: ReadonlyArray | A): Array => Array.isArray * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.fromRecord({ a: 1, b: 2, c: 3 }) * console.log(result) // [["a", 1], ["b", 2], ["c", 3]] @@ -245,7 +245,8 @@ export const fromRecord: (self: Readonly>) => * * @example * ```ts - * import { Array, Option } from "effect" + * import { Array } from "effect/collections" +import * as Option from "effect/data/Option" * * console.log(Array.fromOption(Option.some(1))) // [1] * console.log(Array.fromOption(Option.none())) // [] @@ -261,7 +262,7 @@ export const fromOption: (self: Option.Option) => Array = Option.toArra * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const match = Array.match({ * onEmpty: () => "empty", @@ -301,7 +302,7 @@ export const match: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const matchLeft = Array.matchLeft({ * onEmpty: () => "empty", @@ -341,7 +342,7 @@ export const matchLeft: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const matchRight = Array.matchRight({ * onEmpty: () => "empty", @@ -384,7 +385,7 @@ export const matchRight: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.prepend([2, 3, 4], 1) * console.log(result) // [1, 2, 3, 4] @@ -405,7 +406,7 @@ export const prepend: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.prependAll([2, 3], [0, 1]) * console.log(result) // [0, 1, 2, 3] @@ -432,7 +433,7 @@ export const prependAll: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.append([1, 2, 3], 4); * console.log(result) // [1, 2, 3, 4] @@ -452,7 +453,7 @@ export const append: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.appendAll([1, 2], [3, 4]) * console.log(result) // [1, 2, 3, 4] @@ -481,7 +482,7 @@ export const appendAll: { * @example * * ```ts - * import { Array } from "effect"; + * import { Array } from "effect/collections"; * * const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value) * console.log(result) // [0, 1, 3, 6, 10] @@ -517,7 +518,7 @@ export const scan: { * @example * * ```ts - * import { Array } from "effect"; + * import { Array } from "effect/collections"; * * const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value) * console.log(result) // [10, 9, 7, 4, 0] @@ -545,7 +546,7 @@ export const scanRight: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * console.log(Array.isArray(null)) // false * console.log(Array.isArray([1, 2, 3])) // true @@ -565,7 +566,7 @@ export const isArray: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * console.log(Array.isEmptyArray([])) // true * console.log(Array.isEmptyArray([1, 2, 3])) // false @@ -582,7 +583,7 @@ export const isEmptyArray = (self: Array): self is [] => self.length === 0 * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * console.log(Array.isEmptyReadonlyArray([])) // true * console.log(Array.isEmptyReadonlyArray([1, 2, 3])) // false @@ -601,7 +602,7 @@ export const isEmptyReadonlyArray: (self: ReadonlyArray) => self is readon * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * console.log(Array.isNonEmptyArray([])) // false * console.log(Array.isNonEmptyArray([1, 2, 3])) // true @@ -620,7 +621,7 @@ export const isNonEmptyArray: (self: Array) => self is NonEmptyArray = * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * console.log(Array.isNonEmptyReadonlyArray([])) // false * console.log(Array.isNonEmptyReadonlyArray([1, 2, 3])) // true @@ -637,7 +638,7 @@ export const isNonEmptyReadonlyArray: (self: ReadonlyArray) => self is Non * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.length([1, 2, 3]) * console.log(result) // 3 @@ -657,7 +658,7 @@ const clamp = (i: number, as: ReadonlyArray): number => Math.floor(Math.mi * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.get([1, 2, 3], 1) * console.log(result) // Some(2) @@ -682,7 +683,7 @@ export const get: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.unsafeGet([1, 2, 3], 1) * console.log(result) // 2 @@ -711,7 +712,7 @@ export const unsafeGet: { * @example * * ```ts - * import { Array } from "effect"; + * import { Array } from "effect/collections"; * * const result = Array.unprepend([1, 2, 3, 4]) * console.log(result) // [1, [2, 3, 4]] @@ -730,7 +731,7 @@ export const unprepend = ( * @example * * ```ts - * import { Array } from "effect"; + * import { Array } from "effect/collections"; * * const result = Array.unappend([1, 2, 3, 4]) * console.log(result) // [[1, 2, 3], 4] @@ -748,7 +749,7 @@ export const unappend = ( * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.head([1, 2, 3]) * console.log(result) // Some(1) @@ -768,7 +769,7 @@ export const head: (self: ReadonlyArray) => Option.Option = get(0) * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.headNonEmpty([1, 2, 3, 4]) * console.log(result) // 1 @@ -784,7 +785,7 @@ export const headNonEmpty: (self: NonEmptyReadonlyArray) => A = unsafeGet( * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.last([1, 2, 3]) * console.log(result) // Some(3) @@ -805,7 +806,7 @@ export const last = (self: ReadonlyArray): Option.Option => * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.lastNonEmpty([1, 2, 3, 4]) * console.log(result) // 4 @@ -821,7 +822,7 @@ export const lastNonEmpty = (self: NonEmptyReadonlyArray): A => self[self. * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.tail([1, 2, 3, 4]) * console.log(result) // Some([2, 3, 4]) @@ -844,7 +845,7 @@ export const tail = (self: Iterable): Option.Option> => { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.tailNonEmpty([1, 2, 3, 4]) * console.log(result) // [2, 3, 4] @@ -860,7 +861,7 @@ export const tailNonEmpty = (self: NonEmptyReadonlyArray): Array => sel * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.init([1, 2, 3, 4]) * console.log(result) // Some([1, 2, 3]) @@ -883,7 +884,7 @@ export const init = (self: Iterable): Option.Option> => { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.initNonEmpty([1, 2, 3, 4]) * console.log(result) // [1, 2, 3] @@ -902,7 +903,7 @@ export const initNonEmpty = (self: NonEmptyReadonlyArray): Array => sel * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.take([1, 2, 3, 4, 5], 3) * console.log(result) // [1, 2, 3] @@ -927,7 +928,7 @@ export const take: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.takeRight([1, 2, 3, 4, 5], 3) * console.log(result) // [3, 4, 5] @@ -951,7 +952,7 @@ export const takeRight: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4) * console.log(result) // [1, 3, 2] @@ -1003,7 +1004,7 @@ const spanIndex = (self: Iterable, predicate: (a: A, i: number) => boolean * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.span([1, 3, 2, 4, 5], x => x % 2 === 1) * console.log(result) // [[1, 3], [2, 4, 5]] @@ -1036,7 +1037,7 @@ export const span: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.drop([1, 2, 3, 4, 5], 2) * console.log(result) // [3, 4, 5] @@ -1061,7 +1062,7 @@ export const drop: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.dropRight([1, 2, 3, 4, 5], 2) * console.log(result) // [1, 2, 3] @@ -1084,7 +1085,7 @@ export const dropRight: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4) * console.log(result) // [4, 5] @@ -1108,7 +1109,7 @@ export const dropWhile: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5) * console.log(result) // Option.some(2) @@ -1137,7 +1138,7 @@ export const findFirstIndex: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5) * console.log(result) // Option.some(1) @@ -1166,7 +1167,7 @@ export const findLastIndex: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3) * console.log(result) // Option.some(4) @@ -1191,7 +1192,7 @@ export const findFirst: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0) * console.log(result) // Option.some(4) @@ -1238,7 +1239,7 @@ export const findLast: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd') * console.log(result) // Option.some(['a', 'b', 'c', 'd', 'e']) @@ -1267,7 +1268,7 @@ export const insertAt: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z') * console.log(result) // ['a', 'z', 'c', 'd'] @@ -1296,7 +1297,7 @@ export const replace: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.replaceOption([1, 2, 3], 1, 4) * console.log(result) // Option.some([1, 4, 3]) @@ -1329,7 +1330,7 @@ export const replaceOption: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2) * console.log(result) // [1, 2, 6, 4] @@ -1361,7 +1362,7 @@ export const modify: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const input = [1, 2, 3, 4] * const result = Array.modifyOption(input, 2, (n) => n * 2) @@ -1402,7 +1403,7 @@ export const modifyOption: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const input = [1, 2, 3, 4] * const result = Array.remove(input, 2) @@ -1433,7 +1434,7 @@ export const remove: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.reverse([1, 2, 3, 4]) * console.log(result) // [4, 3, 2, 1] @@ -1453,7 +1454,8 @@ export const reverse = >( * * @example * ```ts - * import { Array, Order } from "effect" + * import { Array } from "effect/collections" + * import { Order } from "effect/data" * * const result = Array.sort([3, 1, 4, 1, 5], Order.number) * console.log(result) // [1, 1, 3, 4, 5] @@ -1482,7 +1484,8 @@ export const sort: { * @example * * ```ts - * import { Array, Order } from "effect" + * import { Array } from "effect/collections" + * import { Order } from "effect/data" * * const result = Array.sortWith(["aaa", "b", "cc"], (s) => s.length, Order.number) * console.log(result) // ["b", "cc", "aaa"] @@ -1517,7 +1520,9 @@ export const sortWith: { * @example * * ```ts - * import { Array, Order, pipe } from "effect" + * import { pipe } from "effect" + * import { Array } from "effect/collections" + * import { Order } from "effect/data" * * const users = [ * { name: "Alice", age: 30 }, @@ -1571,7 +1576,7 @@ export const sortBy = >( * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.zip([1, 2, 3], ['a', 'b']) * console.log(result) // [[1, 'a'], [2, 'b']] @@ -1597,7 +1602,7 @@ export const zip: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b) * console.log(result) // [5, 7, 9] @@ -1631,7 +1636,7 @@ export const zipWith: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.unzip([[1, "a"], [2, "b"], [3, "c"]]) * console.log(result) // [[1, 2, 3], ['a', 'b', 'c']] @@ -1665,7 +1670,7 @@ export const unzip: >( * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.intersperse([1, 2, 3], 0) * console.log(result) // [1, 0, 2, 0, 3] @@ -1702,7 +1707,7 @@ export const intersperse: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10) * console.log(result) // [10, 2, 3] @@ -1728,7 +1733,7 @@ export const modifyNonEmptyHead: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.setNonEmptyHead([1, 2, 3], 10) * console.log(result) // [10, 2, 3] @@ -1751,7 +1756,7 @@ export const setNonEmptyHead: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2) * console.log(result) // [1, 2, 6] @@ -1775,7 +1780,7 @@ export const modifyNonEmptyLast: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.setNonEmptyLast([1, 2, 3], 4) * console.log(result) // [1, 2, 4] @@ -1799,7 +1804,7 @@ export const setNonEmptyLast: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.rotate(['a', 'b', 'c', 'd'], 2) * console.log(result) // ['c', 'd', 'a', 'b'] @@ -1836,7 +1841,8 @@ export const rotate: { * @example * * ```ts - * import { Array, pipe } from "effect" + * import { pipe } from "effect" + * import { Array } from "effect/collections" * * const isEquivalent = (a: number, b: number) => a === b * const containsNumber = Array.containsWith(isEquivalent) @@ -1868,7 +1874,8 @@ const _equivalence = Equal.equivalence() * @example * * ```ts - * import { Array, pipe } from "effect" + * import { pipe } from "effect" + * import { Array } from "effect/collections" * * const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c')) * console.log(result) // true @@ -1890,7 +1897,7 @@ export const contains: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array] => [as[0] * 2, as.slice(1)]) * console.log(result) // [2, 4, 6, 8, 10] @@ -1942,7 +1949,7 @@ export const chop: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.splitAt([1, 2, 3, 4, 5], 3) * console.log(result) // [[1, 2, 3], [4, 5]] @@ -1973,7 +1980,7 @@ export const splitAt: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.splitNonEmptyAt(["a", "b", "c", "d", "e"], 3) * console.log(result) // [["a", "b", "c"], ["d", "e"]] @@ -1998,7 +2005,7 @@ export const splitNonEmptyAt: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3) * console.log(result) // [[1, 2, 3], [4, 5, 6], [7, 8]] @@ -2022,7 +2029,7 @@ export const split: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3) * console.log(result) // [[1, 2, 3], [4, 5]] @@ -2048,7 +2055,7 @@ export const splitWhere: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.copy([1, 2, 3]) * console.log(result) // [1, 2, 3] @@ -2071,7 +2078,7 @@ export const copy: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.pad([1, 2, 3], 6, 0) * console.log(result) // [1, 2, 3, 0, 0, 0] @@ -2112,7 +2119,7 @@ export const pad: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.chunksOf([1, 2, 3, 4, 5], 2) * console.log(result) // [[1, 2], [3, 4], [5]] @@ -2151,7 +2158,7 @@ export const chunksOf: { * @example * ```ts * import * as assert from "node:assert" - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const numbers = [1, 2, 3, 4, 5] * assert.deepStrictEqual(Array.window(numbers, 3), [[1, 2, 3], [2, 3, 4], [3, 4, 5]]) @@ -2181,7 +2188,7 @@ export const window: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.groupWith(["a", "a", "b", "b", "b", "c", "a"], (x, y) => x === y) * console.log(result) // [["a", "a"], ["b", "b", "b"], ["c"], ["a"]] @@ -2218,7 +2225,7 @@ export const groupWith: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.group([1, 1, 2, 2, 2, 3, 1]) * console.log(result) // [[1, 1], [2, 2, 2], [3], [1]] @@ -2238,7 +2245,7 @@ export const group: (self: NonEmptyReadonlyArray) => NonEmptyArray a === b) * console.log(union) // [1, 2, 3] @@ -2331,7 +2338,7 @@ export const unionWith: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.union([1, 2], [2, 3]) * console.log(result) // [1, 2, 3] @@ -2358,7 +2365,7 @@ export const union: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }] * const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }] @@ -2388,7 +2395,7 @@ export const intersectionWith = (isEquivalent: (self: A, that: A) => boolean) * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.intersection([1, 2, 3], [3, 4, 1]) * console.log(result) // [1, 3] @@ -2409,7 +2416,7 @@ export const intersection: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const array1 = [1, 2, 3] * const array2 = [2, 3, 4] @@ -2438,7 +2445,7 @@ export const differenceWith = (isEquivalent: (self: A, that: A) => boolean): * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const difference = Array.difference([1, 2, 3], [2, 3, 4]) * console.log(difference) // [1] @@ -2457,7 +2464,7 @@ export const difference: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.empty() * console.log(result) // [] @@ -2473,7 +2480,7 @@ export const empty: () => Array = () => [] * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.of(1) * console.log(result) // [1] @@ -2489,7 +2496,7 @@ export const of = (a: A): NonEmptyArray => [a] * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * type ElementType = Array.ReadonlyArray.Infer> * // ElementType is string @@ -2502,7 +2509,7 @@ export const of = (a: A): NonEmptyArray => [a] * * @example * ```ts - * import type { Array } from "effect" + * import type { Array } from "effect/collections" * * // Using ReadonlyArray utility types * type ElementType = Array.ReadonlyArray.Infer @@ -2518,7 +2525,7 @@ export declare namespace ReadonlyArray { * * @example * ```ts - * import type { Array } from "effect" + * import type { Array } from "effect/collections" * * type StringArrayType = Array.ReadonlyArray.Infer * // StringArrayType is string @@ -2536,7 +2543,7 @@ export declare namespace ReadonlyArray { * * @example * ```ts - * import type { Array } from "effect" + * import type { Array } from "effect/collections" * * type Result = Array.ReadonlyArray.With * // Result is NonEmptyArray @@ -2553,7 +2560,7 @@ export declare namespace ReadonlyArray { * * @example * ```ts - * import type { Array } from "effect" + * import type { Array } from "effect/collections" * * type Result = Array.ReadonlyArray.OrNonEmpty * // Result is NonEmptyArray @@ -2575,7 +2582,7 @@ export declare namespace ReadonlyArray { * * @example * ```ts - * import type { Array } from "effect" + * import type { Array } from "effect/collections" * * type Result = Array.ReadonlyArray.AndNonEmpty * // Result is NonEmptyArray @@ -2597,7 +2604,7 @@ export declare namespace ReadonlyArray { * * @example * ```ts - * import type { Array } from "effect" + * import type { Array } from "effect/collections" * * type Nested = readonly (readonly number[])[] * type Flattened = Array.ReadonlyArray.Flatten @@ -2618,7 +2625,7 @@ export declare namespace ReadonlyArray { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.map([1, 2, 3], x => x * 2) * console.log(result) // [2, 4, 6] @@ -2639,7 +2646,7 @@ export const map: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.flatMap([1, 2, 3], x => [x, x * 2]) * console.log(result) // [1, 2, 2, 4, 3, 6] @@ -2679,7 +2686,7 @@ export const flatMap: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.flatten([[1, 2], [], [3, 4], [], [5, 6]]) * console.log(result) // [1, 2, 3, 4, 5, 6] @@ -2699,7 +2706,8 @@ export const flatten: >>(self: S) => * @example * * ```ts - * import { Array, Option } from "effect" + * import { Array } from "effect/collections" +import * as Option from "effect/data/Option" * * const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none() * @@ -2736,7 +2744,8 @@ export const filterMap: { * @example * * ```ts - * import { Array, Option } from "effect" + * import { Array } from "effect/collections" +import * as Option from "effect/data/Option" * * const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none() * @@ -2774,7 +2783,8 @@ export const filterMapWhile: { * @example * * ```ts - * import { Array, Result } from "effect"; + * import { Array } from "effect/collections" + * import { Result } from "effect/data"; * * const isEven = (x: number) => x % 2 === 0 * @@ -2841,7 +2851,8 @@ export const partitionFilter: { * @example * * ```ts - * import { Array, Option } from "effect" + * import { Array } from "effect/collections" +import * as Option from "effect/data/Option" * * const result = Array.getSomes([Option.some(1), Option.none(), Option.some(2)]) * console.log(result) // [1, 2] @@ -2861,7 +2872,8 @@ export const getSomes: >, X = any>( * @example * * ```ts - * import { Array, Result } from "effect" + * import { Array } from "effect/collections" + * import { Result } from "effect/data" * * const result = Array.getErrs([Result.succeed(1), Result.fail("err"), Result.succeed(2)]) * console.log(result) // ["err"] @@ -2889,7 +2901,8 @@ export const getErrs = >>( * @example * * ```ts - * import { Array, Result } from "effect" + * import { Array } from "effect/collections" + * import { Result } from "effect/data" * * const result = Array.getOks([Result.succeed(1), Result.fail("err"), Result.succeed(2)]) * console.log(result) // [1, 2] @@ -2916,7 +2929,7 @@ export const getOks = >>( * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.filter([1, 2, 3, 4], x => x % 2 === 0) * console.log(result) // [2, 4] @@ -2950,7 +2963,7 @@ export const filter: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0) * console.log(result) // [[1, 3], [2, 4]] @@ -2993,7 +3006,8 @@ export const partition: { * * @example * ```ts - * import { Array, Result } from "effect" + * import { Array } from "effect/collections" + * import { Result } from "effect/data" * * const results = [Result.succeed(1), Result.fail("error"), Result.succeed(2)] * const [failures, successes] = Array.separate(results) @@ -3017,7 +3031,7 @@ export const separate: >>( * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n) * console.log(result) // 6 @@ -3041,7 +3055,7 @@ export const reduce: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n) * console.log(result) // 6 @@ -3065,7 +3079,7 @@ export const reduceRight: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const isEven = (n: number) => n % 2 === 0 * const to = Array.liftPredicate(isEven) @@ -3086,7 +3100,8 @@ export const liftPredicate: { // Note: I intentionally avoid using the NoInfer p * * @example * ```ts - * import { Array, Option } from "effect" + * import { Array } from "effect/collections" +import * as Option from "effect/data/Option" * * const parseNumber = Array.liftOption((s: string) => { * const n = Number(s) @@ -3110,7 +3125,7 @@ export const liftOption = , B>( * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * console.log(Array.fromNullable(1)) // [1] * console.log(Array.fromNullable(null)) // [] @@ -3127,7 +3142,7 @@ export const fromNullable = (a: A): Array> => a == null ? empt * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const parseNumber = Array.liftNullable((s: string) => { * const n = Number(s) @@ -3152,7 +3167,7 @@ export const liftNullable = , B>( * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n)) * console.log(result) // [1, 3] @@ -3183,7 +3198,8 @@ export const flatMapNullable: { * @example * * ```ts - * import { Array, Result } from "effect" + * import { Array } from "effect/collections" + * import { Result } from "effect/data" * * const parseNumber = (s: string): Result.Result => * isNaN(Number(s)) ? Result.fail(new Error("Not a number")) : Result.succeed(Number(s)) @@ -3218,7 +3234,7 @@ export const liftResult = , E, B>( * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.every([2, 4, 6], x => x % 2 === 0) * console.log(result) // true @@ -3248,7 +3264,7 @@ export const every: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.some([1, 3, 4], x => x % 2 === 0) * console.log(result) // true @@ -3277,7 +3293,7 @@ export const some: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.extend([1, 2, 3], as => as.length) * console.log(result) // [3, 2, 1] @@ -3306,7 +3322,8 @@ export const extend: { * @example * * ```ts - * import { Array, Order } from "effect" + * import { Array } from "effect/collections" + * import { Order } from "effect/data" * * const result = Array.min([3, 1, 2], Order.number) * console.log(result) // 1 @@ -3326,7 +3343,8 @@ export const min: { * @example * * ```ts - * import { Array, Order } from "effect" + * import { Array } from "effect/collections" + * import { Order } from "effect/data" * * const result = Array.max([3, 1, 2], Order.number) * console.log(result) // 3 @@ -3345,7 +3363,8 @@ export const max: { * * @example * ```ts - * import { Array, Option } from "effect" + * import { Array } from "effect/collections" +import * as Option from "effect/data/Option" * * const result = Array.unfold(1, n => n <= 5 ? Option.some([n, n + 1]) : Option.none()) * console.log(result) // [1, 2, 3, 4, 5] @@ -3374,7 +3393,8 @@ export const unfold = (b: B, f: (b: B) => Option.Option): * * @example * ```ts - * import { Array, Order } from "effect" + * import { Array } from "effect/collections" + * import { Order } from "effect/data" * * const arrayOrder = Array.getOrder(Order.number) * console.log(arrayOrder([1, 2], [1, 3])) // -1 (first is less than second) @@ -3391,7 +3411,7 @@ export const getOrder: (O: Order.Order) => Order.Order> = * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const eq = Array.getEquivalence((a, b) => a === b) * console.log(eq([1, 2, 3], [1, 2, 3])) // true @@ -3410,7 +3430,7 @@ export const getEquivalence: ( * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * Array.forEach([1, 2, 3], n => console.log(n)) // 1, 2, 3 * ``` @@ -3430,7 +3450,7 @@ export const forEach: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b) * console.log(result) // [1, 2, 3] @@ -3469,7 +3489,7 @@ export const dedupeWith: { * * @example * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.dedupe([1, 2, 1, 3, 2, 4]) * console.log(result) // [1, 2, 3, 4] @@ -3489,7 +3509,7 @@ export const dedupe = >( * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b) * console.log(result) // [1, 2, 3] @@ -3519,7 +3539,7 @@ export const dedupeAdjacentWith: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.dedupeAdjacent([1, 1, 2, 2, 3, 3]) * console.log(result) // [1, 2, 3] @@ -3536,7 +3556,7 @@ export const dedupeAdjacent: (self: Iterable) => Array = dedupeAdjacent * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const strings = ["a", "b", "c"] * const joined = Array.join(strings, "-") @@ -3557,7 +3577,7 @@ export const join: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n]) * console.log(result) // [6, [1, 3, 6]] @@ -3598,7 +3618,7 @@ export const mapAccum: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.cartesianWith([1, 2], ["a", "b"], (a, b) => `${a}-${b}`) * console.log(result) // ["1-a", "1-b", "2-a", "2-b"] @@ -3622,7 +3642,7 @@ export const cartesianWith: { * @example * * ```ts - * import { Array } from "effect" + * import { Array } from "effect/collections" * * const result = Array.cartesian([1, 2], ["a", "b"]) * console.log(result) // [[1, "a"], [1, "b"], [2, "a"], [2, "b"]] @@ -3660,7 +3680,8 @@ export const cartesian: { * @example * * ```ts - * import { Array, pipe } from "effect" + * import { pipe } from "effect" + * import { Array } from "effect/collections" * * const doResult = pipe( * Array.Do, @@ -3709,7 +3730,8 @@ export const Do: ReadonlyArray<{}> = of({}) * @example * * ```ts - * import { Array, pipe } from "effect" + * import { pipe } from "effect" + * import { Array } from "effect/collections" * * const doResult = pipe( * Array.Do, @@ -3770,7 +3792,8 @@ export const bind: { * @example * * ```ts - * import { Array, pipe } from "effect" + * import { pipe } from "effect" + * import { Array } from "effect/collections" * * const doResult = pipe( * Array.Do, @@ -3835,7 +3858,8 @@ export { * @example * * ```ts - * import { Array, pipe } from "effect" + * import { pipe } from "effect" + * import { Array } from "effect/collections" * * const doResult = pipe( * Array.Do, diff --git a/packages/effect/src/Chunk.ts b/packages/effect/src/collections/Chunk.ts similarity index 92% rename from packages/effect/src/Chunk.ts rename to packages/effect/src/collections/Chunk.ts index e8e4992064..7526cdd07c 100644 --- a/packages/effect/src/Chunk.ts +++ b/packages/effect/src/collections/Chunk.ts @@ -30,7 +30,7 @@ * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * // Creating chunks * const chunk1 = Chunk.fromIterable([1, 2, 3]) @@ -44,7 +44,7 @@ * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * // Functional transformations * const numbers = Chunk.range(1, 5) // [1, 2, 3, 4, 5] @@ -55,7 +55,8 @@ * * @example * ```ts - * import { Chunk, Effect } from "effect" + * import { Chunk } from "effect/collections" +import { Effect } from "effect" * * // Working with Effects * const processChunk = (chunk: Chunk.Chunk) => @@ -68,28 +69,28 @@ * * @since 2.0.0 */ -import * as RA from "./Array.ts" -import type { NonEmptyReadonlyArray } from "./Array.ts" -import * as Equal from "./Equal.ts" -import * as Equivalence from "./Equivalence.ts" -import { dual, identity, pipe } from "./Function.ts" -import * as Hash from "./Hash.ts" -import type { TypeLambda } from "./HKT.ts" -import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.ts" -import type { NonEmptyIterable } from "./NonEmptyIterable.ts" -import type { Option } from "./Option.ts" -import * as O from "./Option.ts" -import * as Order from "./Order.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" -import { hasProperty, type Predicate, type Refinement } from "./Predicate.ts" -import type { Result } from "./Result.ts" -import type { Covariant, NoInfer } from "./Types.ts" +import * as RA from "../collections/Array.ts" +import type { NonEmptyReadonlyArray } from "../collections/Array.ts" +import type { NonEmptyIterable } from "../collections/NonEmptyIterable.ts" +import * as Equivalence from "../data/Equivalence.ts" +import type { Option } from "../data/Option.ts" +import * as O from "../data/Option.ts" +import * as Order from "../data/Order.ts" +import { hasProperty, type Predicate, type Refinement } from "../data/Predicate.ts" +import type { Result } from "../data/Result.ts" +import { dual, identity, pipe } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import { format, type Inspectable, NodeInspectSymbol, toJSON } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import type { TypeLambda } from "../types/HKT.ts" +import type { Covariant, NoInfer } from "../types/Types.ts" /** * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * console.log(Chunk.TypeId) // "~effect/Chunk" * ``` @@ -104,7 +105,7 @@ export const TypeId: TypeId = "~effect/Chunk" * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * declare const chunk: Chunk.Chunk * @@ -122,7 +123,7 @@ export type TypeId = "~effect/Chunk" * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk: Chunk.Chunk = Chunk.make(1, 2, 3) * console.log(chunk.length) // 3 @@ -152,7 +153,7 @@ export interface Chunk extends Iterable, Equal.Equal, Pipeable, Inspec * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const nonEmptyChunk: Chunk.NonEmptyChunk = Chunk.make(1, 2, 3) * console.log(Chunk.headNonEmpty(nonEmptyChunk)) // 1 @@ -169,8 +170,8 @@ export interface NonEmptyChunk extends Chunk, NonEmptyIterable {} * * @example * ```ts - * import type { Kind } from "effect/HKT" - * import type { ChunkTypeLambda } from "effect/Chunk" + * import type { Kind } from "effect/types/HKT" + * import type { ChunkTypeLambda } from "effect/collections/Chunk" * * // Create a Chunk type using the type lambda * type NumberChunk = Kind @@ -238,7 +239,8 @@ const emptyArray: ReadonlyArray = [] * * @example * ```ts - * import { Chunk, Equivalence } from "effect" + * import { Chunk } from "effect/collections" +import * as Equivalence from "effect/data/Equivalence" * * const chunk1 = Chunk.make(1, 2, 3) * const chunk2 = Chunk.make(1, 2, 3) @@ -347,7 +349,7 @@ const makeChunk = (backing: Backing): Chunk => { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3) * const array = [1, 2, 3] @@ -372,7 +374,7 @@ const _empty = makeChunk({ _tag: "IEmpty" }) * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const emptyChunk = Chunk.empty() * console.log(Chunk.size(emptyChunk)) // 0 @@ -388,7 +390,7 @@ export const empty: () => Chunk = () => _empty * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4) * console.log(chunk) @@ -406,7 +408,7 @@ export const make = ]>(...as: As * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.of("hello") * console.log(chunk) @@ -423,7 +425,7 @@ export const of = (a: A): NonEmptyChunk => makeChunk({ _tag: "ISingleton", * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.fromIterable([1, 2, 3]) * console.log(chunk) @@ -473,7 +475,7 @@ const toArray_ = (self: Chunk): Array => toReadonlyArray(self).slice() * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3) * const array = Chunk.toArray(chunk) @@ -522,7 +524,7 @@ const toReadonlyArray_ = (self: Chunk): ReadonlyArray => { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3) * const readonlyArray = Chunk.toReadonlyArray(chunk) @@ -567,7 +569,7 @@ const reverseChunk = (self: Chunk): Chunk => { * @example * * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3) * const result = Chunk.reverse(chunk) @@ -586,7 +588,8 @@ export const reverse: >(self: S) => Chunk.With(self: ReadonlyArray): Chunk => * * @example * ```ts - * import { Chunk, Array } from "effect" + * import { Chunk } from "effect/collections" +import * as Array from "effect/collections/Array" * * const nonEmptyArray = Array.make(1, 2, 3, 4, 5) * const chunk = Chunk.unsafeFromNonEmptyArray(nonEmptyArray) @@ -659,7 +663,7 @@ export const unsafeFromNonEmptyArray = (self: NonEmptyReadonlyArray): NonE * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make("a", "b", "c", "d") * @@ -713,7 +717,7 @@ export const unsafeGet: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3) * const newChunk = Chunk.append(chunk, 4) @@ -738,7 +742,7 @@ export const append: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(2, 3, 4) * const newChunk = Chunk.prepend(chunk, 1) @@ -763,7 +767,7 @@ export const prepend: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.take(chunk, 3) @@ -820,7 +824,7 @@ export const take: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.drop(chunk, 2) @@ -876,7 +880,7 @@ export const drop: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.dropRight(chunk, 2) @@ -897,7 +901,7 @@ export const dropRight: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.dropWhile(chunk, (n) => n < 3) @@ -928,7 +932,7 @@ export const dropWhile: { * @example * * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const result = Chunk.make(1, 2).pipe(Chunk.prependAll(Chunk.make("a", "b")), Chunk.toArray) * @@ -955,7 +959,7 @@ export const prependAll: { * @example * * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const result = Chunk.make(1, 2).pipe(Chunk.appendAll(Chunk.make("a", "b")), Chunk.toArray) * @@ -1019,7 +1023,8 @@ export const appendAll: { * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * const chunk = Chunk.make("1", "2", "hello", "3", "world") * const numbers = Chunk.filterMap(chunk, (str) => { @@ -1052,7 +1057,7 @@ export const filterMap: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5, 6) * const evenNumbers = Chunk.filter(chunk, (n) => n % 2 === 0) @@ -1082,7 +1087,8 @@ export const filter: { * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * const chunk = Chunk.make("1", "2", "hello", "3", "4") * const result = Chunk.filterMapWhile(chunk, (s) => { @@ -1113,7 +1119,8 @@ export const filterMapWhile: { * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * const chunk = Chunk.make(Option.some(1), Option.none(), Option.some(3)) * const result = Chunk.compact(chunk) @@ -1131,7 +1138,7 @@ export const compact = (self: Chunk>): Chunk => filterMap(self, * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3) * const duplicated = Chunk.flatMap(chunk, (n) => Chunk.make(n, n)) @@ -1180,7 +1187,7 @@ export const flatMap: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4) * @@ -1214,7 +1221,7 @@ export const forEach: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const nested = Chunk.make( * Chunk.make(1, 2), @@ -1243,7 +1250,7 @@ export const flatten: >>(self: S) => Chunk.Flatten * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5, 6, 7, 8, 9) * const chunked = Chunk.chunksOf(chunk, 3) @@ -1287,7 +1294,7 @@ export const chunksOf: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk1 = Chunk.make(1, 2, 3, 4) * const chunk2 = Chunk.make(3, 4, 5, 6) @@ -1322,7 +1329,7 @@ export const intersection: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * console.log(Chunk.isEmpty(Chunk.empty())) // true * console.log(Chunk.isEmpty(Chunk.make(1, 2, 3))) // false @@ -1338,7 +1345,7 @@ export const isEmpty = (self: Chunk): boolean => self.length === 0 * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * console.log(Chunk.isNonEmpty(Chunk.empty())) // false * console.log(Chunk.isNonEmpty(Chunk.make(1, 2, 3))) // true @@ -1354,7 +1361,8 @@ export const isNonEmpty = (self: Chunk): self is NonEmptyChunk => self. * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * console.log(Chunk.head(Chunk.empty())) // { _tag: "None" } * console.log(Chunk.head(Chunk.make(1, 2, 3))) // { _tag: "Some", value: 1 } @@ -1372,7 +1380,7 @@ export const head: (self: Chunk) => Option = get(0) * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4) * console.log(Chunk.unsafeHead(chunk)) // 1 @@ -1398,7 +1406,7 @@ export const unsafeHead = (self: Chunk): A => unsafeGet(self, 0) * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const nonEmptyChunk = Chunk.make(1, 2, 3, 4) * console.log(Chunk.headNonEmpty(nonEmptyChunk)) // 1 @@ -1420,7 +1428,8 @@ export const headNonEmpty: (self: NonEmptyChunk) => A = unsafeHead * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * console.log(Chunk.last(Chunk.empty())) // { _tag: "None" } * console.log(Chunk.last(Chunk.make(1, 2, 3))) // { _tag: "Some", value: 3 } @@ -1438,7 +1447,7 @@ export const last = (self: Chunk): Option => get(self, self.length - 1) * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4) * console.log(Chunk.unsafeLast(chunk)) // 4 @@ -1464,7 +1473,7 @@ export const unsafeLast = (self: Chunk): A => unsafeGet(self, self.length * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const nonEmptyChunk = Chunk.make(1, 2, 3, 4) * console.log(Chunk.lastNonEmpty(nonEmptyChunk)) // 4 @@ -1486,7 +1495,7 @@ export const lastNonEmpty: (self: NonEmptyChunk) => A = unsafeLast * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * // Extract the element type from a Chunk * declare const chunk: Chunk.Chunk @@ -1506,7 +1515,7 @@ export declare namespace Chunk { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * declare const numberChunk: Chunk.Chunk * declare const stringChunk: Chunk.Chunk @@ -1525,7 +1534,7 @@ export declare namespace Chunk { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * declare const regularChunk: Chunk.Chunk * declare const nonEmptyChunk: Chunk.NonEmptyChunk @@ -1544,7 +1553,7 @@ export declare namespace Chunk { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * declare const emptyChunk: Chunk.Chunk * declare const nonEmptyChunk: Chunk.NonEmptyChunk @@ -1567,7 +1576,7 @@ export declare namespace Chunk { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * declare const emptyChunk: Chunk.Chunk * declare const nonEmptyChunk: Chunk.NonEmptyChunk @@ -1590,7 +1599,7 @@ export declare namespace Chunk { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * declare const nestedChunk: Chunk.Chunk> * declare const nestedNonEmpty: Chunk.NonEmptyChunk> @@ -1614,7 +1623,7 @@ export declare namespace Chunk { * @example * * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const result = Chunk.map(Chunk.make(1, 2), (n) => n + 1) * @@ -1639,7 +1648,7 @@ export const map: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const [finalState, mapped] = Chunk.mapAccum(chunk, 0, (state, current) => [ @@ -1676,7 +1685,7 @@ export const mapAccum: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5, 6) * const [odds, evens] = Chunk.partition(chunk, (n) => n % 2 === 0) @@ -1725,7 +1734,8 @@ export const partition: { * * @example * ```ts - * import { Chunk, Result } from "effect" + * import { Chunk } from "effect/collections" +import * as Result from "effect/data/Result" * * const chunk = Chunk.make("1", "hello", "2", "world", "3") * const [errors, numbers] = Chunk.partitionMap(chunk, (str) => { @@ -1764,7 +1774,8 @@ export const partitionMap: { * * @example * ```ts - * import { Chunk, Result } from "effect" + * import { Chunk } from "effect/collections" +import * as Result from "effect/data/Result" * * const chunk = Chunk.make( * Result.succeed(1), @@ -1799,7 +1810,7 @@ export const separate = (self: Chunk>): [Chunk, Chunk] * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3) * console.log(Chunk.size(chunk)) // 3 @@ -1815,7 +1826,8 @@ export const size = (self: Chunk): number => self.length * * @example * ```ts - * import { Chunk, Order } from "effect" + * import { Chunk } from "effect/collections" +import * as Order from "effect/data/Order" * * const numbers = Chunk.make(3, 1, 4, 1, 5, 9, 2, 6) * const sorted = Chunk.sort(numbers, Order.number) @@ -1847,7 +1859,8 @@ export const sort: { * * @example * ```ts - * import { Chunk, Order } from "effect" + * import { Chunk } from "effect/collections" +import * as Order from "effect/data/Order" * * const people = Chunk.make( * { name: "Alice", age: 30 }, @@ -1887,7 +1900,7 @@ export const sortWith: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5, 6) * const [before, after] = Chunk.splitAt(chunk, 3) @@ -1919,7 +1932,7 @@ export const splitAt: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const nonEmptyChunk = Chunk.make(1, 2, 3, 4, 5, 6) * const [before, after] = Chunk.splitNonEmptyAt(nonEmptyChunk, 3) @@ -1953,7 +1966,7 @@ export const splitNonEmptyAt: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5, 6, 7, 8, 9) * const chunks = Chunk.split(chunk, 3) @@ -1986,7 +1999,7 @@ export const split: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5, 6) * const [before, fromMatch] = Chunk.splitWhere(chunk, (n) => n > 3) @@ -2027,7 +2040,8 @@ export const splitWhere: { * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * const chunk = Chunk.make(1, 2, 3, 4) * console.log(Chunk.tail(chunk)) // Option.some(Chunk.make(2, 3, 4)) @@ -2049,7 +2063,7 @@ export const tail = (self: Chunk): Option> => self.length > 0 ? O * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const nonEmptyChunk = Chunk.make(1, 2, 3, 4) * const result = Chunk.tailNonEmpty(nonEmptyChunk) @@ -2073,7 +2087,7 @@ export const tailNonEmpty = (self: NonEmptyChunk): Chunk => drop(self, * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5, 6) * const lastThree = Chunk.takeRight(chunk, 3) @@ -2101,7 +2115,7 @@ export const takeRight: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 3, 2, 1) * const result = Chunk.takeWhile(chunk, (n) => n < 4) @@ -2142,7 +2156,7 @@ export const takeWhile: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk1 = Chunk.make(1, 2, 3) * const chunk2 = Chunk.make(3, 4, 5) @@ -2172,7 +2186,7 @@ export const union: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 2, 3, 1, 4, 3) * const result = Chunk.dedupe(chunk) @@ -2199,7 +2213,7 @@ export const dedupe = (self: Chunk): Chunk => unsafeFromArray(RA.dedupe * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 1, 2, 2, 2, 3, 1, 1) * const result = Chunk.dedupeAdjacent(chunk) @@ -2223,7 +2237,7 @@ export const dedupeAdjacent = (self: Chunk): Chunk => unsafeFromArray(R * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const pairs = Chunk.make([1, "a"] as const, [2, "b"] as const, [3, "c"] as const) * const [numbers, letters] = Chunk.unzip(pairs) @@ -2250,7 +2264,7 @@ export const unzip = (self: Chunk): [Chunk, Chunk] * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const numbers = Chunk.make(1, 2, 3) * const letters = Chunk.make("a", "b", "c") @@ -2281,7 +2295,7 @@ export const zipWith: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const numbers = Chunk.make(1, 2, 3) * const letters = Chunk.make("a", "b", "c") @@ -2311,7 +2325,7 @@ export const zip: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make("a", "b", "c", "d") * const result = Chunk.remove(chunk, 1) @@ -2343,7 +2357,8 @@ export const remove: { * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * const chunk = Chunk.make(1, 2, 3, 4) * const result = Chunk.modifyOption(chunk, 1, (n) => n * 10) @@ -2377,7 +2392,7 @@ export const modifyOption: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4) * const result = Chunk.modify(chunk, 1, (n) => n * 10) @@ -2409,7 +2424,7 @@ export const modify: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make("a", "b", "c", "d") * const result = Chunk.replace(chunk, 1, "X") @@ -2438,7 +2453,8 @@ export const replace: { * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * const chunk = Chunk.make("a", "b", "c", "d") * const result = Chunk.replaceOption(chunk, 1, "X") @@ -2469,7 +2485,7 @@ export const replaceOption: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.makeBy(5, (i) => i * 2) * console.log(chunk) @@ -2489,7 +2505,7 @@ export const makeBy: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.range(1, 5) * console.log(chunk) @@ -2511,7 +2527,7 @@ export const range = (start: number, end: number): NonEmptyChunk => * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * console.log(Chunk.contains(chunk, 3)) // true @@ -2540,7 +2556,7 @@ export const contains: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make({ id: 1, name: "Alice" }, { id: 2, name: "Bob" }) * @@ -2572,7 +2588,8 @@ export const containsWith: ( * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.findFirst(chunk, (n) => n > 3) @@ -2604,7 +2621,8 @@ export const findFirst: { * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.findFirstIndex(chunk, (n) => n > 3) @@ -2633,7 +2651,8 @@ export const findFirstIndex: { * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.findLast(chunk, (n) => n < 4) @@ -2664,7 +2683,8 @@ export const findLast: { * * @example * ```ts - * import { Chunk, Option } from "effect" + * import { Chunk } from "effect/collections" +import * as Option from "effect/data/Option" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const result = Chunk.findLastIndex(chunk, (n) => n < 4) @@ -2693,7 +2713,7 @@ export const findLastIndex: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const allPositive = Chunk.make(1, 2, 3, 4, 5) * console.log(Chunk.every(allPositive, (n) => n > 0)) // true @@ -2730,7 +2750,7 @@ export const every: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * console.log(Chunk.some(chunk, (n) => n > 4)) // true @@ -2761,7 +2781,7 @@ export const some: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make("apple", "banana", "cherry") * const result = Chunk.join(chunk, ", ") @@ -2793,7 +2813,7 @@ export const join: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4, 5) * const sum = Chunk.reduce(chunk, 0, (acc, n) => acc + n) @@ -2822,7 +2842,7 @@ export const reduce: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3, 4) * const result = Chunk.reduceRight(chunk, 0, (acc, n) => acc + n) @@ -2852,7 +2872,7 @@ export const reduceRight: { * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk1 = Chunk.make({ id: 1, name: "Alice" }, { id: 2, name: "Bob" }) * const chunk2 = Chunk.make({ id: 1, name: "Alice" }, { id: 3, name: "Charlie" }) @@ -2889,7 +2909,7 @@ export const differenceWith = (isEquivalent: (self: A, that: A) => boolean): * * @example * ```ts - * import { Chunk } from "effect" + * import { Chunk } from "effect/collections" * * const chunk1 = Chunk.make(1, 2, 3, 4, 5) * const chunk2 = Chunk.make(3, 4, 6, 7) diff --git a/packages/effect/src/Graph.ts b/packages/effect/src/collections/Graph.ts similarity index 96% rename from packages/effect/src/Graph.ts rename to packages/effect/src/collections/Graph.ts index b1a28c925e..139dc9f8b0 100644 --- a/packages/effect/src/Graph.ts +++ b/packages/effect/src/collections/Graph.ts @@ -2,16 +2,16 @@ * @since 4.0.0 */ -import * as Data from "./Data.ts" -import * as Equal from "./Equal.ts" -import { dual } from "./Function.ts" -import * as Hash from "./Hash.ts" -import type { Inspectable } from "./Inspectable.ts" -import { format, NodeInspectSymbol } from "./Inspectable.ts" -import * as Option from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" -import type { Mutable } from "./Types.ts" +import * as Data from "../data/Data.ts" +import * as Option from "../data/Option.ts" +import { dual } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import { format, NodeInspectSymbol } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import type { Mutable } from "../types/Types.ts" /** * Safely get a value from a Map, returning an Option. @@ -235,7 +235,7 @@ export const isGraph = (u: unknown): u is Graph => typeof u == * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * // Directed graph with initial nodes and edges * const graph = Graph.directed((mutable) => { @@ -276,7 +276,7 @@ export const directed = (mutate?: (mutable: MutableDirectedGraph) => * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * // Undirected graph with initial nodes and edges * const graph = Graph.undirected((mutable) => { @@ -321,7 +321,7 @@ export const undirected = (mutate?: (mutable: MutableUndirectedGraph * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed() * const mutable = Graph.beginMutation(graph) @@ -365,7 +365,7 @@ export const beginMutation = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed() * const mutable = Graph.beginMutation(graph) @@ -398,7 +398,7 @@ export const endMutation = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed() * const newGraph = Graph.mutate(graph, (mutable) => { @@ -436,7 +436,7 @@ export const mutate: { * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const result = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -473,7 +473,8 @@ export const addNode = ( * * @example * ```ts - * import { Graph, Option } from "effect" + * import { Graph } from "effect/collections" +import * as Option from "effect/data/Option" * * const graph = Graph.mutate(Graph.directed(), (mutable) => { * Graph.addNode(mutable, "Node A") @@ -500,7 +501,7 @@ export const getNode = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.mutate(Graph.directed(), (mutable) => { * Graph.addNode(mutable, "Node A") @@ -528,7 +529,7 @@ export const hasNode = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const emptyGraph = Graph.directed() * console.log(Graph.nodeCount(emptyGraph)) // 0 @@ -554,7 +555,8 @@ export const nodeCount = ( * * @example * ```ts - * import { Graph, Option } from "effect" + * import { Graph } from "effect/collections" +import * as Option from "effect/data/Option" * * const graph = Graph.mutate(Graph.directed(), (mutable) => { * Graph.addNode(mutable, "Node A") @@ -589,7 +591,7 @@ export const findNode = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.mutate(Graph.directed(), (mutable) => { * Graph.addNode(mutable, "Start A") @@ -625,7 +627,8 @@ export const findNodes = ( * * @example * ```ts - * import { Graph, Option } from "effect" + * import { Graph } from "effect/collections" +import * as Option from "effect/data/Option" * * const graph = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -662,7 +665,7 @@ export const findEdge = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -701,7 +704,7 @@ export const findEdges = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * Graph.addNode(mutable, "Node A") @@ -735,7 +738,7 @@ export const updateNode = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const result = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -773,7 +776,7 @@ export const updateEdge = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * Graph.addNode(mutable, "node a") @@ -805,7 +808,7 @@ export const mapNodes = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -842,7 +845,7 @@ export const mapEdges = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -899,7 +902,8 @@ export const reverse = ( * * @example * ```ts - * import { Graph, Option } from "effect" + * import { Graph } from "effect/collections" +import * as Option from "effect/data/Option" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "active") @@ -950,7 +954,8 @@ export const filterMapNodes = ( * * @example * ```ts - * import { Graph, Option } from "effect" + * import { Graph } from "effect/collections" +import * as Option from "effect/data/Option" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -1005,7 +1010,7 @@ export const filterMapEdges = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * Graph.addNode(mutable, "active") @@ -1048,7 +1053,7 @@ export const filterNodes = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -1123,7 +1128,7 @@ const invalidateCycleFlagOnAddition = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const result = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -1195,7 +1200,7 @@ export const addEdge = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const result = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -1258,7 +1263,7 @@ export const removeNode = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const result = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -1350,7 +1355,8 @@ const removeEdgeInternal = ( * * @example * ```ts - * import { Graph, Option } from "effect" + * import { Graph } from "effect/collections" +import * as Option from "effect/data/Option" * * const graph = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -1381,7 +1387,7 @@ export const getEdge = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -1430,7 +1436,7 @@ export const hasEdge = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const emptyGraph = Graph.directed() * console.log(Graph.edgeCount(emptyGraph)) // 0 @@ -1459,7 +1465,7 @@ export const edgeCount = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -1508,7 +1514,7 @@ export const neighbors = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -1567,7 +1573,7 @@ export const neighborsDirected = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.mutate(Graph.directed(), (mutable) => { * const nodeA = Graph.addNode(mutable, "Node A") @@ -1639,7 +1645,7 @@ export const toGraphViz = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -1674,7 +1680,7 @@ export type Direction = "outgoing" | "incoming" * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * // Acyclic directed graph (DAG) * const dag = Graph.directed((mutable) => { @@ -1784,7 +1790,7 @@ export const isAcyclic = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * // Bipartite graph (alternating coloring possible) * const bipartite = Graph.undirected((mutable) => { @@ -1893,7 +1899,7 @@ const getUndirectedNeighbors = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.undirected((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -1951,7 +1957,7 @@ export const connectedComponents = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -2086,7 +2092,8 @@ export interface PathResult { * * @example * ```ts - * import { Graph, Option } from "effect" + * import { Graph } from "effect/collections" +import * as Option from "effect/data/Option" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -2255,7 +2262,7 @@ export interface AllPairsResult { * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -2394,7 +2401,8 @@ export const floydWarshall = ( * * @example * ```ts - * import { Graph, Option } from "effect" + * import { Graph } from "effect/collections" +import * as Option from "effect/data/Option" * * const graph = Graph.directed<{x: number, y: number}, number>((mutable) => { * const a = Graph.addNode(mutable, {x: 0, y: 0}) @@ -2580,7 +2588,8 @@ export const astar = ( * * @example * ```ts - * import { Graph, Option } from "effect" + * import { Graph } from "effect/collections" +import * as Option from "effect/data/Option" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -2741,7 +2750,7 @@ export const bellmanFord = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -2813,7 +2822,7 @@ export class Walker implements Iterable<[T, N]> { * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -2865,7 +2874,7 @@ export type EdgeWalker = Walker> * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -2888,7 +2897,7 @@ export const indices = (walker: Walker): Iterable => walker.visit * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -2911,7 +2920,7 @@ export const values = (walker: Walker): Iterable => walker.visit( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -2949,7 +2958,7 @@ export interface DfsConfig { * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -3045,7 +3054,7 @@ export interface BfsConfig { * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -3136,7 +3145,7 @@ export interface TopoConfig { * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -3276,7 +3285,7 @@ export interface DfsPostOrderConfig { * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const root = Graph.addNode(mutable, "root") @@ -3371,7 +3380,7 @@ export const dfsPostOrder = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -3416,7 +3425,7 @@ export const nodes = ( * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const a = Graph.addNode(mutable, "A") @@ -3473,7 +3482,7 @@ export interface ExternalsConfig { * * @example * ```ts - * import { Graph } from "effect" + * import { Graph } from "effect/collections" * * const graph = Graph.directed((mutable) => { * const source = Graph.addNode(mutable, "source") // 0 - no incoming diff --git a/packages/effect/src/HashMap.ts b/packages/effect/src/collections/HashMap.ts similarity index 89% rename from packages/effect/src/HashMap.ts rename to packages/effect/src/collections/HashMap.ts index 38b25c6956..e248e260f8 100644 --- a/packages/effect/src/HashMap.ts +++ b/packages/effect/src/collections/HashMap.ts @@ -2,19 +2,19 @@ * @since 2.0.0 */ -import type { Equal } from "./Equal.ts" -import type { Inspectable } from "./Inspectable.ts" -import * as internal from "./internal/hashMap.ts" -import type { Option } from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import type { NoInfer } from "./Types.ts" +import type { Option } from "../data/Option.ts" +import type { Equal } from "../interfaces/Equal.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import * as internal from "../internal/hashMap.ts" +import type { NoInfer } from "../types/Types.ts" /** * Unique identifier for HashMap instances. * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * // The TypeId constant can be used for runtime identification * console.log(HashMap.TypeId) // "~effect/HashMap" @@ -34,7 +34,7 @@ export const TypeId: "~effect/HashMap" = internal.HashMapTypeId * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * // Use TypeId for type guards * const isHashMap = (value: unknown): value is HashMap.HashMap => { @@ -54,7 +54,8 @@ export type TypeId = typeof TypeId * * @example * ```ts - * import { HashMap, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import * as Option from "effect/data/Option" * * // Create a HashMap * const map = HashMap.make(["a", 1], ["b", 2], ["c", 3]) @@ -84,7 +85,8 @@ export interface HashMap extends Iterable<[Key, Value]>, Equ * * @example * ```ts - * import { HashMap, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import * as Option from "effect/data/Option" * * // Create a concrete HashMap for type extraction * const inventory = HashMap.make( @@ -120,7 +122,8 @@ export declare namespace HashMap { * * @example * ```ts - * import { HashMap, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" + import * as Option from "effect/data/Option" * * const map = HashMap.make(["a", 1], ["b", 2]) * @@ -142,7 +145,7 @@ export declare namespace HashMap { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * // Create a HashMap to extract key type from * const userMap = HashMap.make( @@ -167,7 +170,7 @@ export declare namespace HashMap { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * // Create a HashMap with user data * const userMap = HashMap.make( @@ -196,7 +199,7 @@ export declare namespace HashMap { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * // Create a product catalog HashMap * const catalog = HashMap.make( @@ -227,7 +230,7 @@ export declare namespace HashMap { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.make(["a", 1], ["b", 2]) * const notMap = { a: 1 } @@ -250,7 +253,7 @@ export const isHashMap: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.empty() * console.log(HashMap.isEmpty(map)) // true @@ -267,7 +270,7 @@ export const empty: () => HashMap = internal.empty * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.make(["a", 1], ["b", 2], ["c", 3]) * console.log(HashMap.size(map)) // 3 @@ -289,7 +292,7 @@ export const make: >( * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const entries = [["a", 1], ["b", 2], ["c", 3]] as const * const map = HashMap.fromIterable(entries) @@ -307,7 +310,7 @@ export const fromIterable: (entries: Iterable) => HashMap * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const emptyMap = HashMap.empty() * const nonEmptyMap = HashMap.make(["a", 1]) @@ -327,7 +330,8 @@ export const isEmpty: (self: HashMap) => boolean = internal.isEmpty * * @example * ```ts - * import { HashMap, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import * as Option from "effect/data/Option" * * const map = HashMap.make(["a", 1], ["b", 2]) * @@ -352,7 +356,9 @@ export const get: { * * @example * ```ts - * import { HashMap, Hash, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import { Hash } from "effect/interfaces" +import * as Option from "effect/data/Option" * * // Useful when implementing custom equality for complex keys * const userMap = HashMap.make( @@ -390,7 +396,8 @@ export const getHash: { * * @example * ```ts - * import { HashMap, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import * as Option from "effect/data/Option" * * const config = HashMap.make( * ["api_url", "https://api.example.com"], @@ -425,7 +432,7 @@ export const unsafeGet: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.make(["a", 1], ["b", 2]) * @@ -451,7 +458,8 @@ export const has: { * * @example * ```ts - * import { HashMap, Hash } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import { Hash } from "effect/interfaces" * * // Create a map with case-sensitive keys * const userMap = HashMap.make( @@ -481,7 +489,7 @@ export const hasHash: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const hm = HashMap.make([1, 'a']) * HashMap.hasBy(hm, (value, key) => value === 'a' && key === 1) // -> true @@ -502,7 +510,7 @@ export const hasBy: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map1 = HashMap.make(["a", 1]) * const map2 = HashMap.set(map1, "b", 2) @@ -527,7 +535,7 @@ export const set: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.make(["a", 1], ["b", 2], ["c", 3]) * const keys = Array.from(HashMap.keys(map)) @@ -544,7 +552,7 @@ export const keys: (self: HashMap) => IterableIterator = internal * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.make(["a", 1], ["b", 2], ["c", 3]) * const values = Array.from(HashMap.values(map)) @@ -561,7 +569,7 @@ export const values: (self: HashMap) => IterableIterator = intern * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const employees = HashMap.make( * ["alice", { department: "engineering", salary: 90000 }], @@ -592,7 +600,7 @@ export const toValues = (self: HashMap): Array => Array.from(valu * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * // Create a configuration map * const config = HashMap.make( @@ -627,7 +635,7 @@ export const entries: (self: HashMap) => IterableIterator<[K, V]> = * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const gameScores = HashMap.make( * ["alice", 1250], @@ -660,7 +668,7 @@ export const toEntries = (self: HashMap): Array<[K, V]> => Array.fro * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const emptyMap = HashMap.empty() * const map = HashMap.make(["a", 1], ["b", 2], ["c", 3]) @@ -679,7 +687,7 @@ export const size: (self: HashMap) => number = internal.size * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.make(["a", 1]) * @@ -706,7 +714,7 @@ export const beginMutation: (self: HashMap) => HashMap = inter * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * // Start with an existing map * const original = HashMap.make(["x", 10], ["y", 20]) @@ -737,7 +745,7 @@ export const endMutation: (self: HashMap) => HashMap = interna * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map1 = HashMap.make(["a", 1]) * const map2 = HashMap.mutate(map1, (mutable) => { @@ -765,7 +773,8 @@ export const mutate: { * * @example * ```ts - * import { HashMap, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import * as Option from "effect/data/Option" * * const map = HashMap.make(["a", 1], ["b", 2]) * @@ -797,7 +806,9 @@ export const modifyAt: { * * @example * ```ts - * import { HashMap, Hash, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import { Hash } from "effect/interfaces" +import * as Option from "effect/data/Option" * * // Useful when working with precomputed hashes for performance * const counters = HashMap.make(["downloads", 100], ["views", 250]) @@ -834,7 +845,7 @@ export const modifyHash: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map1 = HashMap.make(["a", 1], ["b", 2]) * const map2 = HashMap.modify(map1, "a", (value) => value * 3) @@ -856,7 +867,7 @@ export const modify: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map1 = HashMap.make(["a", 1], ["b", 2]) * const map2 = HashMap.make(["b", 20], ["c", 3]) @@ -880,7 +891,7 @@ export const union: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map1 = HashMap.make(["a", 1], ["b", 2], ["c", 3]) * const map2 = HashMap.remove(map1, "b") @@ -903,7 +914,7 @@ export const remove: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map1 = HashMap.make(["a", 1], ["b", 2], ["c", 3], ["d", 4]) * const map2 = HashMap.removeMany(map1, ["b", "d"]) @@ -926,7 +937,7 @@ export const removeMany: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map1 = HashMap.make(["a", 1], ["b", 2]) * const newEntries = [["c", 3], ["d", 4], ["a", 10]] as const // "a" will be overwritten @@ -950,7 +961,7 @@ export const setMany: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map1 = HashMap.make(["a", 1], ["b", 2], ["c", 3]) * const map2 = HashMap.map(map1, (value, key) => `${key}:${value * 2}`) @@ -974,7 +985,7 @@ export const map: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map1 = HashMap.make(["a", 1], ["b", 2]) * const map2 = HashMap.flatMap(map1, (value, key) => @@ -999,7 +1010,7 @@ export const flatMap: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.make(["a", 1], ["b", 2]) * const collected: Array<[string, number]> = [] @@ -1024,7 +1035,7 @@ export const forEach: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.make(["a", 1], ["b", 2], ["c", 3]) * const sum = HashMap.reduce(map, 0, (acc, value) => acc + value) @@ -1045,7 +1056,7 @@ export const reduce: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map1 = HashMap.make(["a", 1], ["b", 2], ["c", 3], ["d", 4]) * const map2 = HashMap.filter(map1, (value) => value % 2 === 0) @@ -1069,7 +1080,8 @@ export const filter: { * * @example * ```ts - * import { HashMap, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import * as Option from "effect/data/Option" * * const map1 = HashMap.make( * ["a", Option.some(1)], @@ -1094,7 +1106,8 @@ export const compact: (self: HashMap>) => HashMap = int * * @example * ```ts - * import { HashMap, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import * as Option from "effect/data/Option" * * const map1 = HashMap.make(["a", 1], ["b", 2], ["c", 3], ["d", 4]) * const map2 = HashMap.filterMap(map1, (value) => @@ -1120,7 +1133,8 @@ export const filterMap: { * * @example * ```ts - * import { HashMap, Option } from "effect" + * import * as HashMap from "effect/collections/HashMap" +import * as Option from "effect/data/Option" * * const map = HashMap.make(["a", 1], ["b", 2], ["c", 3]) * const result = HashMap.findFirst(map, (value) => value > 1) @@ -1144,7 +1158,7 @@ export const findFirst: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.make(["a", 1], ["b", 2], ["c", 3]) * @@ -1165,7 +1179,7 @@ export const some: { * * @example * ```ts - * import { HashMap } from "effect" + * import * as HashMap from "effect/collections/HashMap" * * const map = HashMap.make(["a", 1], ["b", 2], ["c", 3]) * diff --git a/packages/effect/src/HashSet.ts b/packages/effect/src/collections/HashSet.ts similarity index 89% rename from packages/effect/src/HashSet.ts rename to packages/effect/src/collections/HashSet.ts index d4c627c8c4..38daddc60e 100644 --- a/packages/effect/src/HashSet.ts +++ b/packages/effect/src/collections/HashSet.ts @@ -2,20 +2,20 @@ * @since 2.0.0 */ -import type { Equal } from "./Equal.ts" -import * as Dual from "./Function.ts" -import type { Inspectable } from "./Inspectable.ts" -import * as internal from "./internal/hashSet.ts" -import type { Pipeable } from "./Pipeable.ts" -import type { Predicate, Refinement } from "./Predicate.ts" -import type { NoInfer } from "./Types.ts" +import type { Predicate, Refinement } from "../data/Predicate.ts" +import * as Dual from "../Function.ts" +import type { Equal } from "../interfaces/Equal.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import * as internal from "../internal/hashSet.ts" +import type { NoInfer } from "../types/Types.ts" /** * Unique identifier for HashSet instances. * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * // The TypeId constant can be used for runtime identification * console.log(HashSet.TypeId) // "~effect/HashSet" @@ -35,7 +35,7 @@ export const TypeId: "~effect/HashSet" = internal.HashSetTypeId * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * // Use TypeId for type guards * const isHashSet = (value: unknown): value is HashSet.HashSet => { @@ -54,7 +54,7 @@ export type TypeId = typeof TypeId * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * // Create a HashSet * const set = HashSet.make("apple", "banana", "cherry") @@ -85,7 +85,7 @@ export interface HashSet extends Iterable, Equal, Pipeable, In * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * // Create a concrete HashSet for type extraction * const fruits = HashSet.make("apple", "banana", "cherry") @@ -106,7 +106,7 @@ export declare namespace HashSet { /** * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const numbers = HashSet.make(1, 2, 3, 4, 5) * @@ -127,7 +127,7 @@ export declare namespace HashSet { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const set = HashSet.empty() * @@ -149,7 +149,7 @@ export const empty: () => HashSet = internal.empty * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const fruits = HashSet.make("apple", "banana", "cherry") * console.log(HashSet.size(fruits)) // 3 @@ -173,7 +173,7 @@ export const make: >( * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const fromArray = HashSet.fromIterable(["a", "b", "c", "b", "a"]) * console.log(HashSet.size(fromArray)) // 3 @@ -195,7 +195,7 @@ export const fromIterable: (values: Iterable) => HashSet = internal.fro * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const set = HashSet.make(1, 2, 3) * const array = [1, 2, 3] @@ -218,7 +218,7 @@ export const isHashSet: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const set = HashSet.make("a", "b") * const withC = HashSet.add(set, "c") @@ -248,7 +248,7 @@ export const add: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const set = HashSet.make("apple", "banana", "cherry") * @@ -256,7 +256,7 @@ export const add: { * console.log(HashSet.has(set, "grape")) // false * * // Works with any type that implements Equal - * import { Equal, Hash } from "effect" + * import { Equal, Hash } from "effect/interfaces" * * class Person implements Equal.Equal { * constructor(readonly name: string) {} @@ -290,7 +290,7 @@ export const has: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const set = HashSet.make("a", "b", "c") * const withoutB = HashSet.remove(set, "b") @@ -320,7 +320,7 @@ export const remove: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const empty = HashSet.empty() * console.log(HashSet.size(empty)) // 0 @@ -342,7 +342,7 @@ export const size: (self: HashSet) => number = internal.size * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const empty = HashSet.empty() * console.log(HashSet.isEmpty(empty)) // true @@ -361,7 +361,7 @@ export const isEmpty: (self: HashSet) => boolean = internal.isEmpty * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const set1 = HashSet.make("a", "b") * const set2 = HashSet.make("b", "c") @@ -387,7 +387,7 @@ export const union: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const set1 = HashSet.make("a", "b", "c") * const set2 = HashSet.make("b", "c", "d") @@ -413,7 +413,7 @@ export const intersection: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const set1 = HashSet.make("a", "b", "c") * const set2 = HashSet.make("b", "d") @@ -439,7 +439,7 @@ export const difference: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const small = HashSet.make("a", "b") * const large = HashSet.make("a", "b", "c", "d") @@ -467,7 +467,7 @@ export const isSubset: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const numbers = HashSet.make(1, 2, 3) * const doubled = HashSet.map(numbers, n => n * 2) @@ -497,7 +497,7 @@ export const map: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const numbers = HashSet.make(1, 2, 3, 4, 5, 6) * const evens = HashSet.filter(numbers, n => n % 2 === 0) @@ -530,7 +530,7 @@ export const filter: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const numbers = HashSet.make(1, 2, 3, 4, 5) * @@ -557,7 +557,7 @@ export const some: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const numbers = HashSet.make(2, 4, 6, 8) * @@ -584,7 +584,7 @@ export const every: { * * @example * ```ts - * import { HashSet } from "effect" + * import * as HashSet from "effect/collections/HashSet" * * const numbers = HashSet.make(1, 2, 3, 4, 5) * const sum = HashSet.reduce(numbers, 0, (acc, n) => acc + n) diff --git a/packages/effect/src/Iterable.ts b/packages/effect/src/collections/Iterable.ts similarity index 95% rename from packages/effect/src/Iterable.ts rename to packages/effect/src/collections/Iterable.ts index 890cb94d16..bb37aacebb 100644 --- a/packages/effect/src/Iterable.ts +++ b/packages/effect/src/collections/Iterable.ts @@ -12,7 +12,8 @@ * * @example * ```ts - * import { Iterable, Option } from "effect" + * import { Iterable } from "effect/collections" +import * as Option from "effect/data/Option" * * // Create iterables * const numbers = Iterable.range(1, 5) @@ -30,17 +31,17 @@ * @since 2.0.0 */ -import type { NonEmptyArray } from "./Array.ts" -import * as Equal from "./Equal.ts" -import { dual, identity } from "./Function.ts" -import type { Option } from "./Option.ts" -import * as O from "./Option.ts" -import { isBoolean } from "./Predicate.ts" -import type * as Record from "./Record.ts" -import type { Result } from "./Result.ts" -import * as R from "./Result.ts" -import * as Tuple from "./Tuple.ts" -import type { NoInfer } from "./Types.ts" +import type { NonEmptyArray } from "../collections/Array.ts" +import type { Option } from "../data/Option.ts" +import * as O from "../data/Option.ts" +import { isBoolean } from "../data/Predicate.ts" +import type * as Record from "../data/Record.ts" +import type { Result } from "../data/Result.ts" +import * as R from "../data/Result.ts" +import * as Tuple from "../data/Tuple.ts" +import { dual, identity } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import type { NoInfer } from "../types/Types.ts" /** * Creates an iterable by applying a function to consecutive integers. @@ -54,7 +55,7 @@ import type { NoInfer } from "./Types.ts" * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Generate first 5 even numbers * const evens = Iterable.makeBy(n => n * 2, { length: 5 }) @@ -100,7 +101,7 @@ export const makeBy = (f: (i: number) => A, options?: { * @example * ```ts * import * as assert from "node:assert" - * import { range } from "effect/Iterable" + * import { range } from "effect/collections/Iterable" * * assert.deepStrictEqual(Array.from(range(1, 3)), [1, 2, 3]) * ``` @@ -125,7 +126,7 @@ export const range = (start: number, end?: number): Iterable => { * @example * ```ts * import * as assert from "node:assert" - * import { replicate } from "effect/Iterable" + * import { replicate } from "effect/collections/Iterable" * * assert.deepStrictEqual(Array.from(replicate("a", 3)), ["a", "a", "a"]) * ``` @@ -144,7 +145,7 @@ export const replicate: { * @example * ```ts * import * as assert from "node:assert" - * import { fromRecord } from "effect/Iterable" + * import { fromRecord } from "effect/collections/Iterable" * * const x = { a: 1, b: 2, c: 3 } * assert.deepStrictEqual(Array.from(fromRecord(x)), [["a", 1], ["b", 2], ["c", 3]]) @@ -168,7 +169,7 @@ export const fromRecord = (self: Readonly>): I * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [2, 3, 4] * const withOne = Iterable.prepend(numbers, 1) @@ -194,7 +195,7 @@ export const prepend: { * @example * ```ts * import * as assert from "node:assert" - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * assert.deepStrictEqual( * Array.from(Iterable.prependAll([1, 2], ["a", "b"])), @@ -218,7 +219,7 @@ export const prependAll: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [1, 2, 3] * const withFour = Iterable.append(numbers, 4) @@ -245,7 +246,7 @@ export const append: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const first = [1, 2, 3] * const second = [4, 5, 6] @@ -301,7 +302,7 @@ export const appendAll: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Running sum of numbers * const numbers = [1, 2, 3, 4, 5] @@ -351,7 +352,7 @@ export const scan: { * @example * ```ts * import * as assert from "node:assert" - * import { isEmpty } from "effect/Iterable" + * import { isEmpty } from "effect/collections/Iterable" * * assert.deepStrictEqual(isEmpty([]), true); * assert.deepStrictEqual(isEmpty([1, 2, 3]), false); @@ -370,7 +371,7 @@ export const isEmpty = (self: Iterable): self is Iterable => { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [1, 2, 3, 4, 5] * console.log(Iterable.size(numbers)) // 5 @@ -404,7 +405,8 @@ export const size = (self: Iterable): number => { * * @example * ```ts - * import { Iterable, Option } from "effect" + * import { Iterable } from "effect/collections" +import * as Option from "effect/data/Option" * * const numbers = [1, 2, 3] * console.log(Iterable.head(numbers)) // Option.some(1) @@ -435,7 +437,7 @@ export const head = (self: Iterable): Option => { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [1, 2, 3] * console.log(Iterable.unsafeHead(numbers)) // 1 @@ -473,7 +475,7 @@ export const unsafeHead = (self: Iterable): A => { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [1, 2, 3, 4, 5] * const firstThree = Iterable.take(numbers, 3) @@ -520,7 +522,7 @@ export const take: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [2, 4, 6, 8, 3, 10, 12] * const evenPrefix = Iterable.takeWhile(numbers, x => x % 2 === 0) @@ -573,7 +575,7 @@ export const takeWhile: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [1, 2, 3, 4, 5] * const withoutFirstTwo = Iterable.drop(numbers, 2) @@ -623,7 +625,8 @@ export const drop: { * * @example * ```ts - * import { Iterable, Option } from "effect" + * import { Iterable } from "effect/collections" +import * as Option from "effect/data/Option" * * const numbers = [1, 3, 4, 6, 8] * const firstEven = Iterable.findFirst(numbers, x => x % 2 === 0) @@ -686,7 +689,8 @@ export const findFirst: { * * @example * ```ts - * import { Iterable, Option } from "effect" + * import { Iterable } from "effect/collections" +import * as Option from "effect/data/Option" * * const numbers = [1, 3, 4, 6, 8, 2] * const lastEven = Iterable.findLast(numbers, x => x % 2 === 0) @@ -743,7 +747,7 @@ export const findLast: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [1, 2, 3] * const letters = ["a", "b", "c"] @@ -786,7 +790,7 @@ export const zip: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Add corresponding elements * const a = [1, 2, 3, 4] @@ -844,7 +848,7 @@ export const zipWith: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Join numbers with separator * const numbers = [1, 2, 3, 4] @@ -905,7 +909,7 @@ export const intersperse: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Custom equivalence for objects * const byId = (a: { id: number }, b: { id: number }) => a.id === b.id @@ -955,7 +959,7 @@ const _equivalence = Equal.equivalence() * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [1, 2, 3, 4, 5] * console.log(Iterable.contains(numbers, 3)) // true @@ -990,7 +994,7 @@ export const contains: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] * const chunks = Iterable.chunksOf(numbers, 3) @@ -1057,7 +1061,7 @@ export const chunksOf: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Group consecutive equal numbers * const numbers = [1, 1, 2, 2, 2, 3, 1, 1] @@ -1134,7 +1138,7 @@ export const groupWith: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [1, 1, 2, 2, 2, 3, 1, 1] * const grouped = Iterable.group(numbers) @@ -1171,7 +1175,7 @@ export const group: (self: Iterable) => Iterable> = group * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Group by string length * const words = ["a", "bb", "ccc", "dd", "eee", "f"] @@ -1252,7 +1256,7 @@ const constEmptyIterator: Iterator = { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const empty = Iterable.empty() * console.log(Array.from(empty)) // [] @@ -1280,7 +1284,7 @@ export const empty = (): Iterable => constEmpty * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const single = Iterable.of(42) * console.log(Array.from(single)) // [42] @@ -1318,7 +1322,7 @@ export const of = (a: A): Iterable => [a] * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Transform numbers to their squares * const numbers = [1, 2, 3, 4, 5] @@ -1366,7 +1370,7 @@ export const map: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Expand each number to a range * const numbers = [1, 2, 3] @@ -1411,7 +1415,7 @@ export const flatMap: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Flatten nested arrays * const nested = [[1, 2], [3, 4], [5, 6]] @@ -1469,7 +1473,8 @@ export const flatten = (self: Iterable>): Iterable => ({ * * @example * ```ts - * import { Iterable, Option } from "effect" + * import { Iterable } from "effect/collections" +import * as Option from "effect/data/Option" * * // Parse strings to numbers, keeping only valid ones * const strings = ["1", "2", "invalid", "4", "not-a-number"] @@ -1533,7 +1538,8 @@ export const filterMap: { * * @example * ```ts - * import { Iterable, Option } from "effect" + * import { Iterable } from "effect/collections" +import * as Option from "effect/data/Option" * * // Parse numbers until we hit an invalid one * const strings = ["1", "2", "3", "invalid", "4", "5"] @@ -1590,7 +1596,8 @@ export const filterMapWhile: { * @example * ```ts * import * as assert from "node:assert" - * import { Iterable, Option } from "effect" + * import { Iterable } from "effect/collections" +import * as Option from "effect/data/Option" * * assert.deepStrictEqual( * Array.from(Iterable.getSomes([Option.some(1), Option.none(), Option.some(2)])), @@ -1609,7 +1616,8 @@ export const getSomes: (self: Iterable>) => Iterable = filterMap * @example * ```ts * import * as assert from "node:assert" - * import { Iterable, Result } from "effect" + * import { Iterable } from "effect/collections" +import * as Result from "effect/data/Result" * * assert.deepStrictEqual( * Array.from(Iterable.getErrs([Result.succeed(1), Result.fail("err"), Result.succeed(2)])), @@ -1628,7 +1636,8 @@ export const getErrs = (self: Iterable>): Iterable => filt * @example * ```ts * import * as assert from "node:assert" - * import { Iterable, Result } from "effect" + * import { Iterable } from "effect/collections" +import * as Result from "effect/data/Result" * * assert.deepStrictEqual( * Array.from(Iterable.getOks([Result.succeed(1), Result.fail("err"), Result.succeed(2)])), @@ -1653,7 +1662,7 @@ export const getOks = (self: Iterable>): Iterable => filte * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Filter even numbers * const numbers = [1, 2, 3, 4, 5, 6] @@ -1716,7 +1725,7 @@ export const filter: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Extract valid elements from nullable function results * const data = ["1", "2", "invalid", "4"] @@ -1767,7 +1776,7 @@ export const flatMapNullable: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * const numbers = [1, 3, 5, 7, 8] * const hasEven = Iterable.some(numbers, x => x % 2 === 0) @@ -1823,7 +1832,8 @@ export const some: { * * @example * ```ts - * import { Iterable, Option } from "effect" + * import { Iterable } from "effect/collections" +import * as Option from "effect/data/Option" * * // Generate Fibonacci sequence * const fibonacci = Iterable.unfold([0, 1], ([a, b]) => @@ -1878,7 +1888,7 @@ export const unfold = (b: B, f: (b: B) => Option): Iterab * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Print each element * const numbers = [1, 2, 3, 4, 5] @@ -1928,7 +1938,7 @@ export const forEach: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Sum all numbers * const numbers = [1, 2, 3, 4, 5] @@ -1980,7 +1990,7 @@ export const reduce: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Remove adjacent duplicates with custom equality * const numbers = [1, 1, 2, 2, 3, 1, 1] @@ -2049,7 +2059,7 @@ export const dedupeAdjacentWith: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Remove adjacent duplicate numbers * const numbers = [1, 1, 2, 2, 2, 3, 1, 1] @@ -2088,7 +2098,7 @@ export const dedupeAdjacent: (self: Iterable) => Iterable = dedupeAdjac * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // Create coordinate pairs * const xs = [1, 2] @@ -2140,7 +2150,7 @@ export const cartesianWith: { * * @example * ```ts - * import { Iterable } from "effect" + * import { Iterable } from "effect/collections" * * // All pairs of numbers and letters * const numbers = [1, 2, 3] diff --git a/packages/effect/src/MutableHashMap.ts b/packages/effect/src/collections/MutableHashMap.ts similarity index 92% rename from packages/effect/src/MutableHashMap.ts rename to packages/effect/src/collections/MutableHashMap.ts index 07a19fdbfa..fab2702721 100644 --- a/packages/effect/src/MutableHashMap.ts +++ b/packages/effect/src/collections/MutableHashMap.ts @@ -25,21 +25,21 @@ * @since 2.0.0 * @category data-structures */ -import type { NonEmptyArray } from "./Array.ts" -import * as Equal from "./Equal.ts" -import { dual } from "./Function.ts" -import * as Hash from "./Hash.ts" -import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.ts" -import * as Option from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" +import type { NonEmptyArray } from "../collections/Array.ts" +import * as Option from "../data/Option.ts" +import { dual } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import { format, type Inspectable, NodeInspectSymbol, toJSON } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" const TypeId: TypeId = "~effect/MutableHashMap" /** * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.empty() * @@ -63,7 +63,7 @@ export type TypeId = "~effect/MutableHashMap" /** * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * // Create a mutable hash map with string keys and number values * const map: MutableHashMap.MutableHashMap = MutableHashMap.empty() @@ -172,7 +172,7 @@ class BucketIterator implements Iterator<[K, V]> { * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.empty() * @@ -199,7 +199,7 @@ export const empty = (): MutableHashMap => { * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.make( * ["key1", 42], @@ -226,7 +226,7 @@ export const make: >( * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const entries = [ * ["apple", 1], @@ -260,7 +260,8 @@ export const fromIterable = (entries: Iterable): MutableH * * @example * ```ts - * import { MutableHashMap, Option } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" +import * as Option from "effect/data/Option" * * const map = MutableHashMap.make(["key1", 42], ["key2", 100]) * @@ -300,7 +301,7 @@ export const get: { * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.make( * ["apple", 1], @@ -331,7 +332,7 @@ export const keys = (self: MutableHashMap): Array => { * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.make( * ["apple", 1], @@ -389,7 +390,7 @@ const getFromBucket = ( * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.make(["key1", 42], ["key2", 100]) * @@ -418,7 +419,7 @@ export const has: { * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.empty() * @@ -488,7 +489,7 @@ const removeFromBucket = ( * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.make(["count", 5], ["total", 100]) * @@ -549,7 +550,8 @@ export const modify: { * * @example * ```ts - * import { MutableHashMap, Option } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" +import * as Option from "effect/data/Option" * * const map = MutableHashMap.make(["count", 5]) * @@ -628,7 +630,7 @@ export const modifyAt: { * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.make( * ["key1", 42], @@ -686,7 +688,7 @@ export const remove: { * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.make( * ["key1", 42], @@ -722,7 +724,7 @@ export const clear = (self: MutableHashMap) => { * * @example * ```ts - * import { MutableHashMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" * * const map = MutableHashMap.empty() * console.log(MutableHashMap.size(map)) // 0 diff --git a/packages/effect/src/MutableHashSet.ts b/packages/effect/src/collections/MutableHashSet.ts similarity index 92% rename from packages/effect/src/MutableHashSet.ts rename to packages/effect/src/collections/MutableHashSet.ts index ca723480cc..05f24b767e 100644 --- a/packages/effect/src/MutableHashSet.ts +++ b/packages/effect/src/collections/MutableHashSet.ts @@ -24,18 +24,18 @@ * @since 2.0.0 * @category data-structures */ -import * as Dual from "./Function.ts" -import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.ts" -import * as MutableHashMap from "./MutableHashMap.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" +import * as MutableHashMap from "../collections/MutableHashMap.ts" +import * as Dual from "../Function.ts" +import { format, type Inspectable, NodeInspectSymbol, toJSON } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" const TypeId: TypeId = "~effect/MutableHashSet" /** * @example * ```ts - * import { MutableHashSet } from "effect" + * import { MutableHashSet } from "effect/collections" * * type MyTypeId = MutableHashSet.TypeId * const set = MutableHashSet.make("apple", "banana") @@ -51,7 +51,7 @@ export type TypeId = "~effect/MutableHashSet" /** * @example * ```ts - * import { MutableHashSet } from "effect" + * import { MutableHashSet } from "effect/collections" * * // Create a mutable hash set * const set: MutableHashSet.MutableHashSet = MutableHashSet.make("apple", "banana") @@ -115,7 +115,7 @@ const fromHashMap = (keyMap: MutableHashMap.MutableHashMap): Muta * * @example * ```ts - * import { MutableHashSet } from "effect" + * import { MutableHashSet } from "effect/collections" * * const set = MutableHashSet.empty() * @@ -139,7 +139,7 @@ export const empty = (): MutableHashSet => fromHashMap(MutableHash * * @example * ```ts - * import { MutableHashSet } from "effect" + * import { MutableHashSet } from "effect/collections" * * const values = ["apple", "banana", "apple", "cherry", "banana"] * const set = MutableHashSet.fromIterable(values) @@ -168,7 +168,7 @@ export const fromIterable = (keys: Iterable): MutableHashSet => * * @example * ```ts - * import { MutableHashSet } from "effect" + * import { MutableHashSet } from "effect/collections" * * const set = MutableHashSet.make("apple", "banana", "apple", "cherry") * @@ -198,7 +198,7 @@ export const make = >( * * @example * ```ts - * import { MutableHashSet } from "effect" + * import { MutableHashSet } from "effect/collections" * * const set = MutableHashSet.empty() * @@ -235,7 +235,7 @@ export const add: { * * @example * ```ts - * import { MutableHashSet } from "effect" + * import { MutableHashSet } from "effect/collections" * * const set = MutableHashSet.make("apple", "banana", "cherry") * @@ -268,7 +268,7 @@ export const has: { * * @example * ```ts - * import { MutableHashSet } from "effect" + * import { MutableHashSet } from "effect/collections" * * const set = MutableHashSet.make("apple", "banana", "cherry") * @@ -305,7 +305,7 @@ export const remove: { * * @example * ```ts - * import { MutableHashSet } from "effect" + * import { MutableHashSet } from "effect/collections" * * const set = MutableHashSet.empty() * console.log(MutableHashSet.size(set)) // 0 @@ -333,7 +333,7 @@ export const size = (self: MutableHashSet): number => MutableHashMap.size( * * @example * ```ts - * import { MutableHashSet } from "effect" + * import { MutableHashSet } from "effect/collections" * * const set = MutableHashSet.make("apple", "banana", "cherry") * diff --git a/packages/effect/src/MutableList.ts b/packages/effect/src/collections/MutableList.ts similarity index 94% rename from packages/effect/src/MutableList.ts rename to packages/effect/src/collections/MutableList.ts index 5437cfdecc..d5249d3029 100644 --- a/packages/effect/src/MutableList.ts +++ b/packages/effect/src/collections/MutableList.ts @@ -34,7 +34,7 @@ * @since 4.0.0 * @category data-structures */ -import * as Arr from "./Array.ts" +import * as Arr from "../collections/Array.ts" /** * A mutable linked list data structure optimized for high-throughput operations. @@ -43,7 +43,7 @@ import * as Arr from "./Array.ts" * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * // Create a mutable list * const list: MutableList.MutableList = MutableList.make() @@ -79,7 +79,7 @@ export interface MutableList { * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * // Type annotation using the namespace * const processQueue = (queue: MutableList.MutableList) => { @@ -116,7 +116,7 @@ export declare namespace MutableList { * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.append(list, 1) @@ -153,7 +153,7 @@ export declare namespace MutableList { * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * @@ -191,7 +191,7 @@ export const Empty: unique symbol = Symbol.for("effect/MutableList/Empty") * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * @@ -235,7 +235,7 @@ export type Empty = typeof Empty * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * @@ -274,7 +274,7 @@ const emptyBucket = (): MutableList.Bucket => ({ * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * @@ -316,7 +316,7 @@ export const append = (self: MutableList, message: A): void => { * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * @@ -358,7 +358,7 @@ export const prepend = (self: MutableList, message: A): void => { * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.append(list, 4) @@ -393,7 +393,7 @@ export const prependAll = (self: MutableList, messages: Iterable): void * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.append(list, 4) @@ -430,7 +430,7 @@ export const unsafePrependAll = (self: MutableList, messages: ReadonlyArra * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.append(list, 1) @@ -471,7 +471,7 @@ export const appendAll = (self: MutableList, messages: Iterable): numbe * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.append(list, 1) @@ -519,7 +519,7 @@ export const unsafeAppendAll = (self: MutableList, messages: ReadonlyArray * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.appendAll(list, [1, 2, 3, 4, 5]) @@ -558,7 +558,7 @@ export const clear = (self: MutableList): void => { * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.appendAll(list, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) @@ -625,7 +625,7 @@ export const takeN = (self: MutableList, n: number): Array => { * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.appendAll(list, ["apple", "banana", "cherry"]) @@ -666,7 +666,7 @@ export const takeAll = (self: MutableList): Array => takeN(self, self.l * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.appendAll(list, ["first", "second", "third"]) @@ -726,7 +726,7 @@ export const take = (self: MutableList): Empty | A => { * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.appendAll(list, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) @@ -789,7 +789,7 @@ export const filter = (self: MutableList, f: (value: A, i: number) => bool * * @example * ```ts - * import { MutableList } from "effect" + * import * as MutableList from "effect/collections/MutableList" * * const list = MutableList.make() * MutableList.appendAll(list, ["apple", "banana", "apple", "cherry", "apple"]) diff --git a/packages/effect/src/NonEmptyIterable.ts b/packages/effect/src/collections/NonEmptyIterable.ts similarity index 91% rename from packages/effect/src/NonEmptyIterable.ts rename to packages/effect/src/collections/NonEmptyIterable.ts index acad527e28..9ddae7d278 100644 --- a/packages/effect/src/NonEmptyIterable.ts +++ b/packages/effect/src/collections/NonEmptyIterable.ts @@ -23,7 +23,7 @@ * ## Basic Usage * * ```ts - * import { NonEmptyIterable } from "effect" + * import * as NonEmptyIterable from "effect/collections/NonEmptyIterable" * * // NonEmptyIterable is a type that represents any iterable with at least one element * function processNonEmpty(data: NonEmptyIterable.NonEmptyIterable): A { @@ -53,7 +53,10 @@ * ## Working with Different Iterable Types * * ```ts - * import { NonEmptyIterable, Array, Chunk, pipe } from "effect" + * import { pipe } from "effect" + * import * as NonEmptyIterable from "effect/collections/NonEmptyIterable" + * import { Array } from "effect/collections" + * import * as Chunk from "effect/collections/Chunk" * * // Creating non-empty arrays * const nonEmptyArray = Array.make(1, 2, 3) as unknown as NonEmptyIterable.NonEmptyIterable @@ -90,7 +93,10 @@ * ## Integration with Effect Arrays * * ```ts - * import { NonEmptyIterable, Array, Chunk, pipe } from "effect" + * import { pipe } from "effect" + * import * as NonEmptyIterable from "effect/collections/NonEmptyIterable" + * import { Array } from "effect/collections" + * import * as Chunk from "effect/collections/Chunk" * * // Many Array functions work with NonEmptyIterable * declare const nonEmptyData: NonEmptyIterable.NonEmptyIterable @@ -122,7 +128,7 @@ * * @example * ```ts - * import { NonEmptyIterable } from "effect" + * import * as NonEmptyIterable from "effect/collections/NonEmptyIterable" * * // The symbol is used internally for type branding * declare const data: NonEmptyIterable @@ -155,7 +161,9 @@ export declare const nonEmpty: unique symbol * * @example * ```ts - * import { NonEmptyIterable, Array, Chunk } from "effect" + * import * as NonEmptyIterable from "effect/collections/NonEmptyIterable" + * import { Array } from "effect/collections" + * import * as Chunk from "effect/collections/Chunk" * * // Function that requires non-empty data * function getFirst(data: NonEmptyIterable.NonEmptyIterable): A { @@ -202,7 +210,9 @@ export interface NonEmptyIterable extends Iterable { * * @example * ```ts - * import { NonEmptyIterable, Array, Chunk } from "effect" + * import * as NonEmptyIterable from "effect/collections/NonEmptyIterable" + * import { Array } from "effect/collections" + * import * as Chunk from "effect/collections/Chunk" * * // Helper to make iterator iterable for Array.from * const iteratorToIterable = (iterator: Iterator): Iterable => ({ diff --git a/packages/effect/src/Symbol.ts b/packages/effect/src/collections/Symbol.ts similarity index 84% rename from packages/effect/src/Symbol.ts rename to packages/effect/src/collections/Symbol.ts index 68a0114a90..58da04e2e0 100644 --- a/packages/effect/src/Symbol.ts +++ b/packages/effect/src/collections/Symbol.ts @@ -2,8 +2,8 @@ * @since 2.0.0 */ -import * as equivalence from "./Equivalence.ts" -import * as predicate from "./Predicate.ts" +import * as equivalence from "../data/Equivalence.ts" +import * as predicate from "../data/Predicate.ts" /** * Tests if a value is a `symbol`. @@ -11,7 +11,7 @@ import * as predicate from "./Predicate.ts" * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import * as Predicate from "effect/data/Predicate" * * assert.deepStrictEqual(Predicate.isSymbol(Symbol.for("a")), true) * assert.deepStrictEqual(Predicate.isSymbol("a"), false) @@ -30,7 +30,7 @@ export const isSymbol: (u: unknown) => u is symbol = predicate.isSymbol * * @example * ```ts - * import * as S from "effect/Symbol" + * import * as S from "effect/collections/Symbol" * * const sym1 = Symbol("test") * const sym2 = Symbol("test") diff --git a/packages/effect/src/Trie.ts b/packages/effect/src/collections/Trie.ts similarity index 89% rename from packages/effect/src/Trie.ts rename to packages/effect/src/collections/Trie.ts index 82060a8221..1ddea067bc 100644 --- a/packages/effect/src/Trie.ts +++ b/packages/effect/src/collections/Trie.ts @@ -15,19 +15,19 @@ * * @since 2.0.0 */ -import type { Equal } from "./Equal.ts" -import type { Inspectable } from "./Inspectable.ts" -import * as TR from "./internal/trie.ts" -import type { Option } from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import type { Covariant, NoInfer } from "./Types.ts" +import type { Option } from "../data/Option.ts" +import type { Equal } from "../interfaces/Equal.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import * as TR from "../internal/trie.ts" +import type { Covariant, NoInfer } from "../types/Types.ts" const TypeId: TypeId = "~effect/Trie" /** * @example * ```ts - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * type TrieTypeId = Trie.TypeId * const trie = Trie.make(["apple", 1], ["banana", 2]) @@ -43,7 +43,8 @@ export type TypeId = "~effect/Trie" /** * @example * ```ts - * import { Trie, Option } from "effect" +import * as Option from "effect/data/Option" + * import * as Trie from "effect/collections/Trie" * * // Create a trie with string-to-number mappings * const trie: Trie.Trie = Trie.make( @@ -89,7 +90,8 @@ export interface Trie extends Iterable<[string, Value]>, Equal, Pi * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Equal } from "effect" + * import * as Trie from "effect/collections/Trie" +import * as Equal from "effect/interfaces/Equal" * * const trie = Trie.empty() * @@ -108,7 +110,8 @@ export const empty: () => Trie = TR.empty * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Equal } from "effect" + * import * as Trie from "effect/collections/Trie" +import * as Equal from "effect/interfaces/Equal" * * const iterable: Array = [["call", 0], ["me", 1], ["mind", 2], ["mid", 3]] * const trie = Trie.fromIterable(iterable) @@ -129,7 +132,8 @@ export const fromIterable: (entries: Iterable) => Trie< * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Equal } from "effect" + * import * as Trie from "effect/collections/Trie" +import * as Equal from "effect/interfaces/Equal" * * const trie = Trie.make(["ca", 0], ["me", 1]) * @@ -150,7 +154,7 @@ export const make: >( * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie1 = Trie.empty().pipe( * Trie.insert("call", 0) @@ -181,7 +185,7 @@ export const insert: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("cab", 0), @@ -206,7 +210,7 @@ export const keys: (self: Trie) => IterableIterator = TR.keys * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("call", 0), @@ -231,7 +235,7 @@ export const values: (self: Trie) => IterableIterator = TR.values * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("call", 0), @@ -255,7 +259,7 @@ export const entries: (self: Trie) => IterableIterator<[string, V]> = TR.e * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("call", 0), @@ -278,7 +282,7 @@ export const toEntries = (self: Trie): Array<[string, V]> => Array.from(en * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("she", 0), @@ -306,7 +310,7 @@ export const keysWithPrefix: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("she", 0), @@ -336,7 +340,7 @@ export const valuesWithPrefix: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("she", 0), @@ -364,7 +368,7 @@ export const entriesWithPrefix: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("shells", 0), @@ -392,7 +396,8 @@ export const toEntriesWithPrefix: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Option } from "effect" +import * as Option from "effect/data/Option" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("shells", 0), @@ -420,7 +425,7 @@ export const longestPrefixOf: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("a", 0), @@ -441,7 +446,8 @@ export const size: (self: Trie) => number = TR.size * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Option } from "effect" +import * as Option from "effect/data/Option" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("call", 0), @@ -474,7 +480,7 @@ export const get: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("call", 0), @@ -507,7 +513,7 @@ export const has: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty() * const trie1 = trie.pipe(Trie.insert("ma", 0)) @@ -530,7 +536,7 @@ export const isEmpty: (self: Trie) => boolean = TR.isEmpty * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("call", 0), @@ -554,7 +560,8 @@ export const unsafeGet: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Option } from "effect" +import * as Option from "effect/data/Option" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("call", 0), @@ -585,7 +592,7 @@ export const remove: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * const trie = Trie.empty().pipe( * Trie.insert("shells", 0), @@ -627,7 +634,8 @@ export const reduce: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Equal } from "effect" + * import * as Trie from "effect/collections/Trie" +import * as Equal from "effect/interfaces/Equal" * * const trie = Trie.empty().pipe( * Trie.insert("shells", 0), @@ -665,7 +673,8 @@ export const map: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Equal } from "effect" + * import * as Trie from "effect/collections/Trie" +import * as Equal from "effect/interfaces/Equal" * * const trie = Trie.empty().pipe( * Trie.insert("shells", 0), @@ -703,7 +712,9 @@ export const filter: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Equal, Option } from "effect" + * import * as Trie from "effect/collections/Trie" +import * as Equal from "effect/interfaces/Equal" +import * as Option from "effect/data/Option" * * const trie = Trie.empty().pipe( * Trie.insert("shells", 0), @@ -741,7 +752,9 @@ export const filterMap: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Equal, Option } from "effect" + * import * as Trie from "effect/collections/Trie" +import * as Equal from "effect/interfaces/Equal" +import * as Option from "effect/data/Option" * * const trie = Trie.empty>().pipe( * Trie.insert("shells", Option.some(0)), @@ -768,7 +781,7 @@ export const compact: (self: Trie>) => Trie = TR.compact * @example * ```ts * import * as assert from "node:assert" - * import { Trie } from "effect" + * import * as Trie from "effect/collections/Trie" * * let value = 0 * @@ -798,7 +811,9 @@ export const forEach: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Equal, Option } from "effect" + * import * as Trie from "effect/collections/Trie" +import * as Equal from "effect/interfaces/Equal" +import * as Option from "effect/data/Option" * * const trie = Trie.empty().pipe( * Trie.insert("shells", 0), @@ -825,7 +840,8 @@ export const modify: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Equal } from "effect" + * import * as Trie from "effect/collections/Trie" +import * as Equal from "effect/interfaces/Equal" * * const trie = Trie.empty().pipe( * Trie.insert("shells", 0), @@ -853,7 +869,8 @@ export const removeMany: { * @example * ```ts * import * as assert from "node:assert" - * import { Trie, Equal } from "effect" + * import * as Trie from "effect/collections/Trie" +import * as Equal from "effect/interfaces/Equal" * * const trie = Trie.empty().pipe( * Trie.insert("shells", 0), diff --git a/packages/effect/src/collections/index.ts b/packages/effect/src/collections/index.ts new file mode 100644 index 0000000000..781cb90e52 --- /dev/null +++ b/packages/effect/src/collections/index.ts @@ -0,0 +1,373 @@ +/** + * @since 4.0.0 + */ + +/** + * This module provides utility functions for working with arrays in TypeScript. + * + * @since 2.0.0 + */ +export * as Array from "./Array.ts" + +/** + * The `Chunk` module provides an immutable, high-performance sequence data structure + * optimized for functional programming patterns. A `Chunk` is a persistent data structure + * that supports efficient append, prepend, and concatenation operations. + * + * ## What is a Chunk? + * + * A `Chunk` is an immutable sequence of elements of type `A` that provides: + * - **O(1) append and prepend operations** + * - **Efficient concatenation** through tree-like structure + * - **Memory efficiency** with structural sharing + * - **Rich API** with functional programming operations + * - **Type safety** with full TypeScript integration + * + * ## Key Features + * + * - **Immutable**: All operations return new chunks without modifying the original + * - **Efficient**: Optimized data structure with logarithmic complexity for most operations + * - **Functional**: Rich set of transformation and combination operators + * - **Lazy evaluation**: Many operations are deferred until needed + * - **Interoperable**: Easy conversion to/from arrays and other collections + * + * ## Performance Characteristics + * + * - **Append/Prepend**: O(1) amortized + * - **Random Access**: O(log n) + * - **Concatenation**: O(log min(m, n)) + * - **Iteration**: O(n) + * - **Memory**: Structural sharing minimizes allocation + * + * @example + * ```ts + * import { Chunk } from "effect/collections" + * + * // Creating chunks + * const chunk1 = Chunk.fromIterable([1, 2, 3]) + * const chunk2 = Chunk.fromIterable([4, 5, 6]) + * const empty = Chunk.empty() + * + * // Combining chunks + * const combined = Chunk.appendAll(chunk1, chunk2) + * console.log(Chunk.toReadonlyArray(combined)) // [1, 2, 3, 4, 5, 6] + * ``` + * + * @example + * ```ts + * import { Chunk } from "effect/collections" + * + * // Functional transformations + * const numbers = Chunk.range(1, 5) // [1, 2, 3, 4, 5] + * const doubled = Chunk.map(numbers, (n) => n * 2) // [2, 4, 6, 8, 10] + * const evens = Chunk.filter(doubled, (n) => n % 4 === 0) // [4, 8] + * const sum = Chunk.reduce(evens, 0, (acc, n) => acc + n) // 12 + * ``` + * + * @example + * ```ts + * import { Chunk } from "effect/collections" +import { Effect } from "effect" + * + * // Working with Effects + * const processChunk = (chunk: Chunk.Chunk) => + * Effect.gen(function* () { + * const mapped = Chunk.map(chunk, (n) => n * 2) + * const filtered = Chunk.filter(mapped, (n) => n > 5) + * return Chunk.toReadonlyArray(filtered) + * }) + * ``` + * + * @since 2.0.0 + */ +export * as Chunk from "./Chunk.ts" + +/** + * @since 4.0.0 + */ +export * as Graph from "./Graph.ts" + +/** + * @since 2.0.0 + */ +export * as HashMap from "./HashMap.ts" + +/** + * @since 2.0.0 + */ +export * as HashSet from "./HashSet.ts" + +/** + * This module provides utility functions for working with Iterables in TypeScript. + * + * Iterables are objects that implement the iterator protocol, allowing them to be + * consumed with `for...of` loops, spread syntax, and other iteration constructs. + * This module provides a comprehensive set of functions for creating, transforming, + * and working with iterables in a functional programming style. + * + * Unlike arrays, iterables can be lazy and potentially infinite, making them suitable + * for stream processing and memory-efficient data manipulation. All functions in this + * module preserve the lazy nature of iterables where possible. + * + * @example + * ```ts + * import { Iterable } from "effect/collections" +import * as Option from "effect/data/Option" + * + * // Create iterables + * const numbers = Iterable.range(1, 5) + * const doubled = Iterable.map(numbers, x => x * 2) + * const filtered = Iterable.filter(doubled, x => x > 5) + * + * console.log(Array.from(filtered)) // [6, 8, 10] + * + * // Infinite iterables + * const fibonacci = Iterable.unfold([0, 1], ([a, b]) => Option.some([a, [b, a + b]])) + * const first10 = Iterable.take(fibonacci, 10) + * console.log(Array.from(first10)) // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] + * ``` + * + * @since 2.0.0 + */ +export * as Iterable from "./Iterable.ts" + +/** + * @fileoverview + * MutableHashMap is a high-performance, mutable hash map implementation designed for efficient key-value storage + * with support for both structural and referential equality. It provides O(1) average-case performance for + * basic operations and integrates seamlessly with Effect's Equal and Hash interfaces. + * + * The implementation uses a hybrid approach: + * - Referential keys (without Equal implementation) are stored in a native Map + * - Structural keys (with Equal implementation) are stored in hash buckets with collision handling + * + * Key Features: + * - Mutable operations for performance-critical scenarios + * - Supports both structural and referential equality + * - Efficient collision handling through bucketing + * - Iterable interface for easy traversal + * - Memory-efficient storage with automatic bucket management + * + * Performance Characteristics: + * - Get/Set/Has: O(1) average, O(n) worst case (hash collisions) + * - Remove: O(1) average, O(n) worst case + * - Clear: O(1) + * - Size: O(1) + * - Iteration: O(n) + * + * @since 2.0.0 + * @category data-structures + */ +export * as MutableHashMap from "./MutableHashMap.ts" + +/** + * @fileoverview + * MutableHashSet is a high-performance, mutable set implementation that provides efficient storage + * and retrieval of unique values. Built on top of MutableHashMap, it inherits the same performance + * characteristics and support for both structural and referential equality. + * + * The implementation uses a MutableHashMap internally where each value is stored as a key with a + * boolean flag, providing O(1) average-case performance for all operations. + * + * Key Features: + * - Mutable operations for performance-critical scenarios + * - Supports both structural and referential equality + * - Efficient duplicate detection and removal + * - Iterable interface for easy traversal + * - Memory-efficient storage with automatic deduplication + * - Seamless integration with Effect's Equal and Hash interfaces + * + * Performance Characteristics: + * - Add/Has/Remove: O(1) average, O(n) worst case (hash collisions) + * - Clear: O(1) + * - Size: O(1) + * - Iteration: O(n) + * + * @since 2.0.0 + * @category data-structures + */ +export * as MutableHashSet from "./MutableHashSet.ts" + +/** + * @fileoverview + * MutableList is an efficient, mutable linked list implementation optimized for high-throughput + * scenarios like logging, queuing, and streaming. It uses a bucket-based architecture where + * elements are stored in arrays (buckets) linked together, providing optimal performance for + * both append and prepend operations. + * + * The implementation uses a sophisticated bucket system: + * - Each bucket contains an array of elements with an offset pointer + * - Buckets can be marked as mutable or immutable for optimization + * - Elements are taken from the head and added to the tail + * - Memory is efficiently managed through bucket reuse and cleanup + * + * Key Features: + * - Highly optimized for high-frequency append/prepend operations + * - Memory efficient with automatic cleanup of consumed elements + * - Support for bulk operations (appendAll, prependAll, takeN) + * - Filtering and removal operations + * - Zero-copy optimizations for certain scenarios + * + * Performance Characteristics: + * - Append/Prepend: O(1) amortized + * - Take/TakeN: O(1) per element taken + * - Length: O(1) + * - Clear: O(1) + * - Filter: O(n) + * + * Ideal Use Cases: + * - High-throughput logging systems + * - Producer-consumer queues + * - Streaming data buffers + * - Real-time data processing pipelines + * + * @since 4.0.0 + * @category data-structures + */ +export * as MutableList from "./MutableList.ts" + +/** + * @since 2.0.0 + * + * The `NonEmptyIterable` module provides types and utilities for working with iterables + * that are guaranteed to contain at least one element. This provides compile-time + * safety when working with collections that must not be empty. + * + * ## Key Features + * + * - **Type Safety**: Compile-time guarantee that the iterable contains at least one element + * - **Iterator Protocol**: Fully compatible with JavaScript's built-in iteration protocol + * - **Functional Operations**: Safe operations that preserve the non-empty property + * - **Lightweight**: Minimal overhead with maximum type safety + * + * ## Why NonEmptyIterable? + * + * Many operations require non-empty collections to be meaningful: + * - Finding the maximum or minimum value + * - Getting the first or last element + * - Reducing without an initial value + * - Operations that would otherwise need runtime checks + * + * ## Basic Usage + * + * ```ts + * import * as NonEmptyIterable from "effect/collections/NonEmptyIterable" + * + * // NonEmptyIterable is a type that represents any iterable with at least one element + * function processNonEmpty(data: NonEmptyIterable.NonEmptyIterable): A { + * // Safe to get the first element - guaranteed to exist + * const [first] = NonEmptyIterable.unprepend(data) + * return first + * } + * + * // Using Array.make to create non-empty arrays + * const numbers = Array.make(1, 2, 3, 4, 5) as unknown as NonEmptyIterable.NonEmptyIterable + * const firstNumber = processNonEmpty(numbers) // number + * + * // Regular arrays can be asserted as NonEmptyIterable when known to be non-empty + * const values = [1, 2, 3] as unknown as NonEmptyIterable.NonEmptyIterable + * const firstValue = processNonEmpty(values) // number + * + * // Custom iterables that are guaranteed non-empty + * function* generateNumbers(): NonEmptyIterable.NonEmptyIterable { + * yield 1 + * yield 2 + * yield 3 + * } + * + * const firstGenerated = processNonEmpty(generateNumbers()) // number + * ``` + * + * ## Working with Different Iterable Types + * + * ```ts + * import { pipe } from "effect" + * import * as NonEmptyIterable from "effect/collections/NonEmptyIterable" + * import { Array } from "effect/collections" + * import * as Chunk from "effect/collections/Chunk" + * + * // Creating non-empty arrays + * const nonEmptyArray = Array.make(1, 2, 3) as unknown as NonEmptyIterable.NonEmptyIterable + * + * // Working with strings (assert as NonEmptyIterable when known to be non-empty) + * const nonEmptyString = "hello" as unknown as NonEmptyIterable.NonEmptyIterable + * const [firstChar] = NonEmptyIterable.unprepend(nonEmptyString) + * console.log(firstChar) // "h" + * + * // Working with Maps (assert when known to be non-empty) + * const nonEmptyMap = new Map([ + * ["key1", "value1"], + * ["key2", "value2"] + * ]) as unknown as NonEmptyIterable.NonEmptyIterable<[string, string]> + * const [firstEntry] = NonEmptyIterable.unprepend(nonEmptyMap) + * console.log(firstEntry) // ["key1", "value1"] + * + * // Custom generator functions + * function* fibonacci(): NonEmptyIterable.NonEmptyIterable { + * let a = 1, b = 1 + * yield a + * while (true) { + * yield b + * const next = a + b + * a = b + * b = next + * } + * } + * + * const [firstFib, restFib] = NonEmptyIterable.unprepend(fibonacci() as unknown as NonEmptyIterable.NonEmptyIterable) + * console.log(firstFib) // 1 + * ``` + * + * ## Integration with Effect Arrays + * + * ```ts + * import { pipe } from "effect" + * import * as NonEmptyIterable from "effect/collections/NonEmptyIterable" + * import { Array } from "effect/collections" + * import * as Chunk from "effect/collections/Chunk" + * + * // Many Array functions work with NonEmptyIterable + * declare const nonEmptyData: NonEmptyIterable.NonEmptyIterable + * + * const processData = pipe( + * nonEmptyData, + * Array.fromIterable, + * Array.map(x => x * 2), + * Array.filter(x => x > 5), + * // Result is a regular array since filtering might make it empty + * ) + * + * // Safe operations that preserve non-emptiness + * const doubledData = pipe( + * nonEmptyData, + * Array.fromIterable, + * Array.map(x => x * 2) + * // This would still be non-empty if the source was non-empty + * ) + * ``` + */ +export * as NonEmptyIterable from "./NonEmptyIterable.ts" + +/** + * @since 2.0.0 + */ +export * as Symbol from "./Symbol.ts" + +/** + * A `Trie` is used for locating specific `string` keys from within a set. + * + * It works similar to `HashMap`, but with keys required to be `string`. + * This constraint unlocks some performance optimizations and new methods to get string prefixes (e.g. `keysWithPrefix`, `longestPrefixOf`). + * + * Prefix search is also the main feature that makes a `Trie` more suited than `HashMap` for certain usecases. + * + * A `Trie` is often used to store a dictionary (list of words) that can be searched + * in a manner that allows for efficient generation of completion lists + * (e.g. predict the rest of a word a user is typing). + * + * A `Trie` has O(n) lookup time where `n` is the size of the key, + * or even less than `n` on search misses. + * + * @since 2.0.0 + */ +export * as Trie from "./Trie.ts" diff --git a/packages/effect/src/collections/index.ts.tpl b/packages/effect/src/collections/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/collections/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/Deferred.ts b/packages/effect/src/concurrency/Deferred.ts similarity index 88% rename from packages/effect/src/Deferred.ts rename to packages/effect/src/concurrency/Deferred.ts index 8aad3fea34..c7cd925993 100644 --- a/packages/effect/src/Deferred.ts +++ b/packages/effect/src/concurrency/Deferred.ts @@ -17,7 +17,9 @@ * * @example * ```ts - * import { Deferred, Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * // Basic usage: coordinate between fibers * const program = Effect.gen(function* () { @@ -66,16 +68,16 @@ * * @since 2.0.0 */ -import type * as Cause from "./Cause.ts" -import type { Effect, Latch } from "./Effect.ts" -import type * as Exit from "./Exit.ts" -import { dual, identity, type LazyArg } from "./Function.ts" -import * as core from "./internal/core.ts" -import * as internalEffect from "./internal/effect.ts" -import * as Option from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" -import type * as Types from "./Types.ts" +import type * as Cause from "../Cause.ts" +import * as Option from "../data/Option.ts" +import type { Effect, Latch } from "../Effect.ts" +import type * as Exit from "../Exit.ts" +import { dual, identity, type LazyArg } from "../Function.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import * as core from "../internal/core.ts" +import * as internalEffect from "../internal/effect.ts" +import type * as Types from "../types/Types.ts" /** * @since 2.0.0 @@ -100,7 +102,9 @@ export type TypeId = "~effect/Deferred" * * @example * ```ts - * import { Deferred, Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * // Create and use a Deferred for inter-fiber communication * const program = Effect.gen(function* () { @@ -171,7 +175,7 @@ const DeferredProto = { * * @example * ```ts - * import { Deferred } from "effect" + * import { Deferred } from "effect/concurrency" * * const deferred = Deferred.unsafeMake() * console.log(deferred) @@ -192,7 +196,8 @@ export const unsafeMake = (): Deferred => { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -221,7 +226,8 @@ export { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -247,7 +253,8 @@ export { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -277,7 +284,8 @@ export const complete: { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -307,7 +315,8 @@ export const completeWith: { * * @example * ```ts - * import { Deferred, Effect, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -332,7 +341,8 @@ export const done: { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -355,7 +365,8 @@ export const fail: { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -382,7 +393,8 @@ export const failSync: { * * @example * ```ts - * import { Deferred, Effect, Cause } from "effect" + * import { Effect, Cause } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -408,7 +420,8 @@ export const failCause: { * * @example * ```ts - * import { Deferred, Effect, Cause } from "effect" + * import { Effect, Cause } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -435,7 +448,8 @@ export const failCauseSync: { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -458,7 +472,8 @@ export const die: { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -486,7 +501,8 @@ export const dieSync: { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -507,7 +523,8 @@ export const interrupt = (self: Deferred): Effect => * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -534,7 +551,8 @@ export const interruptWith: { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -567,7 +585,9 @@ export const unsafeIsDone = (self: Deferred): boolean => self.effect * * @example * ```ts - * import { Deferred, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -592,7 +612,8 @@ export const poll = ( * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -616,7 +637,8 @@ export const succeed: { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const program = Effect.gen(function*() { * const deferred = yield* Deferred.make() @@ -645,7 +667,8 @@ export const sync: { * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * const deferred = Deferred.unsafeMake() * const success = Deferred.unsafeDone(deferred, Effect.succeed(42)) @@ -677,7 +700,8 @@ export const unsafeDone = (self: Deferred, effect: Effect): bo * * @example * ```ts - * import { Deferred, Effect } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" * * // Define an effect that succeeds * const successEffect = Effect.succeed(42) diff --git a/packages/effect/src/FiberHandle.ts b/packages/effect/src/concurrency/FiberHandle.ts similarity index 88% rename from packages/effect/src/FiberHandle.ts rename to packages/effect/src/concurrency/FiberHandle.ts index a4ab0e3e4f..a134745d3e 100644 --- a/packages/effect/src/FiberHandle.ts +++ b/packages/effect/src/concurrency/FiberHandle.ts @@ -1,28 +1,28 @@ /** * @since 2.0.0 */ -import type { NoSuchElementError } from "./Cause.ts" -import * as Cause from "./Cause.ts" -import * as Deferred from "./Deferred.ts" -import * as Effect from "./Effect.ts" -import * as Exit from "./Exit.ts" -import * as Fiber from "./Fiber.ts" -import * as Filter from "./Filter.ts" -import { dual } from "./Function.ts" -import type * as Inspectable from "./Inspectable.ts" -import { PipeInspectableProto } from "./internal/core.ts" -import * as Option from "./Option.ts" -import { type Pipeable } from "./Pipeable.ts" -import * as Predicate from "./Predicate.ts" -import type { Scheduler } from "./Scheduler.ts" -import type * as Scope from "./Scope.ts" +import type { NoSuchElementError } from "../Cause.ts" +import * as Cause from "../Cause.ts" +import * as Deferred from "../concurrency/Deferred.ts" +import * as Filter from "../data/Filter.ts" +import * as Option from "../data/Option.ts" +import * as Predicate from "../data/Predicate.ts" +import * as Effect from "../Effect.ts" +import * as Exit from "../Exit.ts" +import { dual } from "../Function.ts" +import type * as Inspectable from "../interfaces/Inspectable.ts" +import { type Pipeable } from "../interfaces/Pipeable.ts" +import { PipeInspectableProto } from "../internal/core.ts" +import type * as Scope from "../resources/Scope.ts" +import * as Fiber from "../runtime/Fiber.ts" +import type { Scheduler } from "../runtime/Scheduler.ts" /** * @since 2.0.0 * @category type ids * @example * ```ts - * import { FiberHandle } from "effect" + * import { FiberHandle } from "effect/concurrency" * * const typeId = FiberHandle.TypeId * console.log(typeId) // "~effect/FiberHandle" @@ -35,7 +35,7 @@ export const TypeId: TypeId = "~effect/FiberHandle" * @category type ids * @example * ```ts - * import type { FiberHandle } from "effect" + * import type { FiberHandle } from "effect/concurrency" * * // TypeId is used to identify FiberHandle instances * type MyTypeId = FiberHandle.TypeId @@ -48,7 +48,9 @@ export type TypeId = "~effect/FiberHandle" * @category models * @example * ```ts - * import { Effect, FiberHandle, Fiber } from "effect" + * import { Effect } from "effect" + * import { FiberHandle } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * Effect.gen(function*() { * // Create a FiberHandle that can hold fibers producing strings @@ -77,7 +79,8 @@ export interface FiberHandle extends Pipeable, * @category refinements * @example * ```ts - * import { Effect, FiberHandle } from "effect" + * import { Effect } from "effect" + * import { FiberHandle } from "effect/concurrency" * * Effect.gen(function*() { * const handle = yield* FiberHandle.make() @@ -116,7 +119,8 @@ const unsafeMake = (): FiberHandle => { * * @example * ```ts - * import { Effect, FiberHandle } from "effect" + * import { Effect } from "effect" + * import { FiberHandle } from "effect/concurrency" * * Effect.gen(function*() { * const handle = yield* FiberHandle.make() @@ -158,7 +162,9 @@ export const make = (): Effect.Effect() @@ -200,7 +206,8 @@ export const makeRuntime = (): Effect.Effect< * @category constructors * @example * ```ts - * import { Effect, FiberHandle } from "effect" + * import { Effect } from "effect" + * import { FiberHandle } from "effect/concurrency" * * Effect.gen(function*() { * const run = yield* FiberHandle.makeRuntimePromise() @@ -244,7 +251,9 @@ const isInternalInterruption = Filter.toPredicate(Filter.compose( * @category combinators * @example * ```ts - * import { Effect, FiberHandle, Fiber } from "effect" + * import { Effect } from "effect" + * import { FiberHandle } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * Effect.gen(function*() { * const handle = yield* FiberHandle.make() @@ -323,7 +332,9 @@ export const unsafeSet: { * @category combinators * @example * ```ts - * import { Effect, FiberHandle, Fiber } from "effect" + * import { Effect } from "effect" + * import { FiberHandle } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * Effect.gen(function*() { * const handle = yield* FiberHandle.make() @@ -376,7 +387,9 @@ export const set: { * @category combinators * @example * ```ts - * import { Effect, FiberHandle, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { FiberHandle } from "effect/concurrency" * * Effect.gen(function*() { * const handle = yield* FiberHandle.make() @@ -402,7 +415,9 @@ export const unsafeGet = (self: FiberHandle): Option.Option(self: FiberHandle): Effect.Effect( * * @example * ```ts - * import { Effect, FiberHandle, ServiceMap } from "effect" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" + * import { FiberHandle } from "effect/concurrency" * * interface Users { * readonly _: unique symbol @@ -626,7 +646,8 @@ export const runtime: ( * @category combinators * @example * ```ts - * import { Effect, FiberHandle } from "effect" + * import { Effect } from "effect" + * import { FiberHandle } from "effect/concurrency" * * Effect.gen(function*() { * const handle = yield* FiberHandle.make() @@ -688,7 +709,8 @@ export const runtimePromise = (self: FiberHandle): () => * @category combinators * @example * ```ts - * import { Effect, FiberHandle } from "effect"; + * import { Effect } from "effect" + * import { FiberHandle } from "effect/concurrency"; * * Effect.gen(function* () { * const handle = yield* FiberHandle.make() @@ -709,7 +731,8 @@ export const join = (self: FiberHandle): Effect.Effect => * @category combinators * @example * ```ts - * import { Effect, FiberHandle } from "effect" + * import { Effect } from "effect" + * import { FiberHandle } from "effect/concurrency" * * Effect.gen(function*() { * const handle = yield* FiberHandle.make() diff --git a/packages/effect/src/FiberMap.ts b/packages/effect/src/concurrency/FiberMap.ts similarity index 88% rename from packages/effect/src/FiberMap.ts rename to packages/effect/src/concurrency/FiberMap.ts index 63e70b9999..84e5c0194c 100644 --- a/packages/effect/src/FiberMap.ts +++ b/packages/effect/src/concurrency/FiberMap.ts @@ -1,29 +1,29 @@ /** * @since 2.0.0 */ -import type { NoSuchElementError } from "./Cause.ts" -import * as Cause from "./Cause.ts" -import * as Deferred from "./Deferred.ts" -import * as Effect from "./Effect.ts" -import * as Exit from "./Exit.ts" -import * as Fiber from "./Fiber.ts" -import * as Filter from "./Filter.ts" -import { constVoid, dual } from "./Function.ts" -import type * as Inspectable from "./Inspectable.ts" -import { PipeInspectableProto } from "./internal/core.ts" -import * as Iterable from "./Iterable.ts" -import * as MutableHashMap from "./MutableHashMap.ts" -import * as Option from "./Option.ts" -import { type Pipeable } from "./Pipeable.ts" -import * as Predicate from "./Predicate.ts" -import type * as Scope from "./Scope.ts" +import type { NoSuchElementError } from "../Cause.ts" +import * as Cause from "../Cause.ts" +import * as Iterable from "../collections/Iterable.ts" +import * as MutableHashMap from "../collections/MutableHashMap.ts" +import * as Deferred from "../concurrency/Deferred.ts" +import * as Filter from "../data/Filter.ts" +import * as Option from "../data/Option.ts" +import * as Predicate from "../data/Predicate.ts" +import * as Effect from "../Effect.ts" +import * as Exit from "../Exit.ts" +import { constVoid, dual } from "../Function.ts" +import type * as Inspectable from "../interfaces/Inspectable.ts" +import { type Pipeable } from "../interfaces/Pipeable.ts" +import { PipeInspectableProto } from "../internal/core.ts" +import type * as Scope from "../resources/Scope.ts" +import * as Fiber from "../runtime/Fiber.ts" /** * @since 2.0.0 * @category type ids * @example * ```ts - * import { FiberMap } from "effect" + * import { FiberMap } from "effect/concurrency" * * declare const fiberMap: FiberMap.FiberMap * @@ -38,7 +38,7 @@ export const TypeId: unique symbol = Symbol.for("effect/FiberMap") * @category type ids * @example * ```ts - * import { FiberMap } from "effect" + * import { FiberMap } from "effect/concurrency" * * // TypeId is the type of the FiberMap type identifier * type Id = FiberMap.TypeId @@ -55,7 +55,9 @@ export type TypeId = typeof TypeId * @category models * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * // Create a FiberMap with string keys * const program = Effect.gen(function* () { @@ -90,7 +92,9 @@ export interface FiberMap * @category refinements * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -139,7 +143,9 @@ const unsafeMake = ( * * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * Effect.gen(function*() { * const map = yield* FiberMap.make() @@ -186,7 +192,9 @@ export const make = (): Effect.Effect() @@ -229,7 +237,9 @@ export const makeRuntime = (): Effect.Effect< * @category constructors * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const run = yield* FiberMap.makeRuntimePromise() @@ -278,7 +288,9 @@ const isInternalInterruption = Filter.toPredicate(Filter.compose( * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -367,7 +379,9 @@ export const unsafeSet: { * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -417,7 +431,10 @@ export const set: { * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -456,7 +473,9 @@ export const unsafeGet: { * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -492,7 +511,9 @@ export const get: { * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -523,7 +544,9 @@ export const unsafeHas: { * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -555,7 +578,9 @@ export const has: { * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -603,7 +628,9 @@ export const remove: { * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -648,7 +675,9 @@ const constInterruptedFiber = (function() { * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -725,7 +754,9 @@ const runImpl = ( * * @example * ```ts - * import { Effect, FiberMap, ServiceMap } from "effect" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" + * import { FiberMap } from "effect/concurrency" * * interface Users { * readonly _: unique symbol @@ -799,7 +830,9 @@ export const runtime: ( * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -860,7 +893,9 @@ export const runtimePromise = (self: FiberMap): () * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -886,7 +921,9 @@ export const size = (self: FiberMap): Effect.Effect => * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect"; + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime"; * * Effect.gen(function* () { * const map = yield* FiberMap.make() @@ -908,7 +945,9 @@ export const join = (self: FiberMap): Effect.Effect = * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberMap } from "effect" + * import { Effect } from "effect" + * import { FiberMap } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const map = yield* FiberMap.make() diff --git a/packages/effect/src/FiberSet.ts b/packages/effect/src/concurrency/FiberSet.ts similarity index 89% rename from packages/effect/src/FiberSet.ts rename to packages/effect/src/concurrency/FiberSet.ts index 42fc5454be..001f64a3de 100644 --- a/packages/effect/src/FiberSet.ts +++ b/packages/effect/src/concurrency/FiberSet.ts @@ -1,26 +1,26 @@ /** * @since 2.0.0 */ -import * as Cause from "./Cause.ts" -import * as Deferred from "./Deferred.ts" -import * as Effect from "./Effect.ts" -import * as Exit from "./Exit.ts" -import * as Fiber from "./Fiber.ts" -import * as Filter from "./Filter.ts" -import { constVoid, dual } from "./Function.ts" -import type * as Inspectable from "./Inspectable.ts" -import { PipeInspectableProto } from "./internal/core.ts" -import * as Iterable from "./Iterable.ts" -import { type Pipeable } from "./Pipeable.ts" -import * as Predicate from "./Predicate.ts" -import type * as Scope from "./Scope.ts" +import * as Cause from "../Cause.ts" +import * as Iterable from "../collections/Iterable.ts" +import * as Deferred from "../concurrency/Deferred.ts" +import * as Filter from "../data/Filter.ts" +import * as Predicate from "../data/Predicate.ts" +import * as Effect from "../Effect.ts" +import * as Exit from "../Exit.ts" +import { constVoid, dual } from "../Function.ts" +import type * as Inspectable from "../interfaces/Inspectable.ts" +import { type Pipeable } from "../interfaces/Pipeable.ts" +import { PipeInspectableProto } from "../internal/core.ts" +import type * as Scope from "../resources/Scope.ts" +import * as Fiber from "../runtime/Fiber.ts" /** * @since 2.0.0 * @category type ids * @example * ```ts - * import { FiberSet } from "effect" + * import { FiberSet } from "effect/concurrency" * * console.log(FiberSet.TypeId === "~effect/FiberSet") // true * ``` @@ -32,7 +32,7 @@ export const TypeId: TypeId = "~effect/FiberSet" * @category type ids * @example * ```ts - * import { FiberSet } from "effect" + * import { FiberSet } from "effect/concurrency" * * // TypeId is the unique identifier for FiberSet * type Id = FiberSet.TypeId @@ -48,7 +48,8 @@ export type TypeId = "~effect/FiberSet" * @category models * @example * ```ts - * import { Effect, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" * * const program = Effect.gen(function*() { * const set = yield* FiberSet.make() @@ -82,7 +83,8 @@ export interface FiberSet * @category refinements * @example * ```ts - * import { Effect, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" * * Effect.gen(function*() { * const set = yield* FiberSet.make() @@ -130,7 +132,8 @@ const unsafeMake = ( * * @example * ```ts - * import { Effect, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" * * Effect.gen(function*() { * const set = yield* FiberSet.make() @@ -170,7 +173,9 @@ export const make = (): Effect.Effect, * @category constructors * @example * ```ts - * import { Effect, Fiber, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function*() { * const runFork = yield* FiberSet.makeRuntime() @@ -207,7 +212,8 @@ export const makeRuntime = (): Effect.Effec * @category constructors * @example * ```ts - * import { Effect, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" * * const program = Effect.gen(function*() { * const runPromise = yield* FiberSet.makeRuntimePromise() @@ -250,7 +256,8 @@ const isInternalInterruption = Filter.toPredicate(Filter.compose( * @category combinators * @example * ```ts - * import { Effect, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" * * const program = Effect.gen(function*() { * const set = yield* FiberSet.make() @@ -317,7 +324,8 @@ export const unsafeAdd: { * @category combinators * @example * ```ts - * import { Effect, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" * * const program = Effect.gen(function*() { * const set = yield* FiberSet.make() @@ -363,7 +371,8 @@ export const add: { * @category combinators * @example * ```ts - * import { Effect, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" * * const program = Effect.gen(function*() { * const set = yield* FiberSet.make() @@ -407,7 +416,9 @@ const constInterruptedFiber = (function() { * @category combinators * @example * ```ts - * import { Effect, Fiber, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function*() { * const set = yield* FiberSet.make() @@ -474,7 +485,9 @@ const runImpl = ( * * @example * ```ts - * import { Effect, FiberSet, ServiceMap } from "effect" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" + * import { FiberSet } from "effect/concurrency" * * interface Users { * readonly _: unique symbol @@ -538,7 +551,8 @@ export const runtime: ( * @category combinators * @example * ```ts - * import { Effect, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" * * const program = Effect.gen(function*() { * const set = yield* FiberSet.make() @@ -593,7 +607,8 @@ export const runtimePromise = (self: FiberSet): () => Eff * @category combinators * @example * ```ts - * import { Effect, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" * * const program = Effect.gen(function*() { * const set = yield* FiberSet.make() @@ -619,7 +634,8 @@ export const size = (self: FiberSet): Effect.Effect => * @category combinators * @example * ```ts - * import { Effect, FiberSet } from "effect"; + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency"; * * Effect.gen(function* () { * const set = yield* FiberSet.make() @@ -640,7 +656,8 @@ export const join = (self: FiberSet): Effect.Effect => * @category combinators * @example * ```ts - * import { Effect, FiberSet } from "effect" + * import { Effect } from "effect" + * import { FiberSet } from "effect/concurrency" * * const program = Effect.gen(function*() { * const set = yield* FiberSet.make() diff --git a/packages/effect/src/MutableRef.ts b/packages/effect/src/concurrency/MutableRef.ts similarity index 94% rename from packages/effect/src/MutableRef.ts rename to packages/effect/src/concurrency/MutableRef.ts index 4694369842..970a8d13f3 100644 --- a/packages/effect/src/MutableRef.ts +++ b/packages/effect/src/concurrency/MutableRef.ts @@ -30,18 +30,18 @@ * @since 2.0.0 * @category data-structures */ -import * as Equal from "./Equal.ts" -import * as Dual from "./Function.ts" -import { type Inspectable, toJSON } from "./Inspectable.ts" -import { PipeInspectableProto } from "./internal/core.ts" -import type { Pipeable } from "./Pipeable.ts" +import * as Dual from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import { type Inspectable, toJSON } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { PipeInspectableProto } from "../internal/core.ts" const TypeId: TypeId = "~effect/MutableRef" /** * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * type RefTypeId = MutableRef.TypeId * const ref = MutableRef.make(42) @@ -57,7 +57,7 @@ export type TypeId = "~effect/MutableRef" /** * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * // Create a mutable reference * const ref: MutableRef.MutableRef = MutableRef.make(42) @@ -110,7 +110,7 @@ const MutableRefProto: Omit, "current"> = { * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * // Create a counter reference * const counter = MutableRef.make(0) @@ -142,7 +142,7 @@ export const make = (value: T): MutableRef => { * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const ref = MutableRef.make("initial") * @@ -190,7 +190,7 @@ export const compareAndSet: { * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const counter = MutableRef.make(5) * @@ -221,7 +221,7 @@ export const decrement = (self: MutableRef): MutableRef => updat * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const counter = MutableRef.make(5) * @@ -252,7 +252,7 @@ export const decrementAndGet = (self: MutableRef): number => updateAndGe * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const ref = MutableRef.make("hello") * console.log(MutableRef.get(ref)) // "hello" @@ -281,7 +281,7 @@ export const get = (self: MutableRef): T => self.current * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const counter = MutableRef.make(5) * @@ -313,7 +313,7 @@ export const getAndDecrement = (self: MutableRef): number => getAndUpdat * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const counter = MutableRef.make(5) * @@ -353,7 +353,7 @@ export const getAndIncrement = (self: MutableRef): number => getAndUpdat * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const ref = MutableRef.make("old") * @@ -400,7 +400,7 @@ export const getAndSet: { * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const counter = MutableRef.make(5) * @@ -448,7 +448,7 @@ export const getAndUpdate: { * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const counter = MutableRef.make(5) * @@ -482,7 +482,7 @@ export const increment = (self: MutableRef): MutableRef => updat * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const counter = MutableRef.make(5) * @@ -517,7 +517,7 @@ export const incrementAndGet = (self: MutableRef): number => updateAndGe * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const ref = MutableRef.make("initial") * @@ -566,7 +566,7 @@ export const set: { * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const ref = MutableRef.make("old") * @@ -612,7 +612,7 @@ export const setAndGet: { * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const counter = MutableRef.make(5) * @@ -663,7 +663,7 @@ export const update: { * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const counter = MutableRef.make(5) * @@ -715,7 +715,7 @@ export const updateAndGet: { * * @example * ```ts - * import { MutableRef } from "effect" + * import { MutableRef } from "effect/concurrency" * * const flag = MutableRef.make(false) * diff --git a/packages/effect/src/PubSub.ts b/packages/effect/src/concurrency/PubSub.ts similarity index 95% rename from packages/effect/src/PubSub.ts rename to packages/effect/src/concurrency/PubSub.ts index 6c689eed87..f51c7dc300 100644 --- a/packages/effect/src/PubSub.ts +++ b/packages/effect/src/concurrency/PubSub.ts @@ -7,7 +7,9 @@ * * @example * ```ts - * import { Effect, PubSub, Scope } from "effect" + * import { Effect } from "effect" + * import { Scope } from "effect/resources" + * import { PubSub } from "effect/concurrency" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -28,26 +30,26 @@ * * @since 2.0.0 */ -import * as Arr from "./Array.ts" -import * as Deferred from "./Deferred.ts" -import * as Effect from "./Effect.ts" -import * as Exit from "./Exit.ts" -import type { LazyArg } from "./Function.ts" -import { dual, identity } from "./Function.ts" -import * as MutableList from "./MutableList.ts" -import * as MutableRef from "./MutableRef.ts" -import { nextPow2 } from "./Number.ts" -import * as Option from "./Option.ts" -import { type Pipeable, pipeArguments } from "./Pipeable.ts" -import * as Scope from "./Scope.ts" -import type { Covariant, Invariant } from "./Types.ts" +import * as Arr from "../collections/Array.ts" +import * as MutableList from "../collections/MutableList.ts" +import * as Deferred from "../concurrency/Deferred.ts" +import * as MutableRef from "../concurrency/MutableRef.ts" +import * as Option from "../data/Option.ts" +import * as Effect from "../Effect.ts" +import * as Exit from "../Exit.ts" +import type { LazyArg } from "../Function.ts" +import { dual, identity } from "../Function.ts" +import { type Pipeable, pipeArguments } from "../interfaces/Pipeable.ts" +import { nextPow2 } from "../primitives/Number.ts" +import * as Scope from "../resources/Scope.ts" +import type { Covariant, Invariant } from "../types/Types.ts" /** * The type identifier for PubSub instances. * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * // Check if a value is a PubSub instance * declare const pubsub: PubSub.PubSub @@ -64,7 +66,7 @@ export const TypeId: TypeId = "~effect/PubSub" * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * // Use in type guards or type checking * const isPubSub = (value: unknown): value is PubSub.PubSub => @@ -84,7 +86,8 @@ export type TypeId = "~effect/PubSub" * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * // Create a bounded PubSub with capacity 10 @@ -124,7 +127,7 @@ export interface PubSub extends Pipeable { * * @example * ```ts - * import type { PubSub } from "effect" + * import type { PubSub } from "effect/concurrency" * * // Access types from the namespace * type PubSubType = PubSub.PubSub @@ -140,7 +143,7 @@ export namespace PubSub { * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * // This interface is used internally by PubSub implementations * // Access through the main PubSub API instead @@ -168,7 +171,7 @@ export namespace PubSub { * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * // This interface is used internally by subscription implementations * // Access through the main PubSub subscription API instead @@ -192,7 +195,7 @@ export namespace PubSub { * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * // This type is used internally to track subscribers * declare const pubsub: PubSub.PubSub @@ -212,7 +215,7 @@ export namespace PubSub { * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * // Access replay window from a subscription * declare const subscription: PubSub.Subscription @@ -239,7 +242,8 @@ export namespace PubSub { * * @example * ```ts - * import { PubSub, Effect } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * // Strategy defines how PubSub handles backpressure * const program = Effect.gen(function* () { @@ -311,7 +315,7 @@ export namespace PubSub { * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * // Check if a value is a Subscription instance * declare const subscription: PubSub.Subscription @@ -328,7 +332,7 @@ export const SubscriptionTypeId: SubscriptionTypeId = "~effect/PubSub/Subscripti * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * // Use in type guards * const isSubscription = (value: unknown): value is PubSub.Subscription => @@ -346,7 +350,8 @@ export type SubscriptionTypeId = "~effect/PubSub/Subscription" * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -387,7 +392,8 @@ export interface Subscription extends Pipeable { * * @example * ```ts - * import { PubSub, Effect } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * // Create custom PubSub with specific atomic implementation and strategy @@ -434,7 +440,8 @@ export const make = ( * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * // Create bounded PubSub with capacity 100 @@ -470,7 +477,8 @@ export const bounded = ( * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * // Create dropping PubSub that drops new messages when full @@ -513,7 +521,8 @@ export const dropping = ( * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * // Create sliding PubSub that evicts old messages when full @@ -558,7 +567,8 @@ export const sliding = ( * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * // Create unbounded PubSub @@ -598,7 +608,7 @@ export const unbounded = (options?: { * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * // Create bounded atomic PubSub * const atomic1 = PubSub.makeAtomicBounded(10) @@ -642,7 +652,7 @@ export const makeAtomicBounded = ( * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * // Create unbounded atomic PubSub * const atomic1 = PubSub.makeAtomicUnbounded() @@ -671,7 +681,8 @@ export const makeAtomicUnbounded = (options?: { * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(100) @@ -696,7 +707,8 @@ export const capacity = (self: PubSub): number => self.pubsub.capacity * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -730,7 +742,8 @@ export const size = (self: PubSub): Effect.Effect => * * @example * ```ts - * import { PubSub, Option } from "effect" + * import { PubSub } from "effect/concurrency" +import * as Option from "effect/data/Option" * * // Unsafe synchronous size check * declare const pubsub: PubSub.PubSub @@ -759,7 +772,8 @@ export const unsafeSize = (self: PubSub): Option.Option => { * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(2) @@ -788,7 +802,8 @@ export const isFull = (self: PubSub): Effect.Effect => * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -816,7 +831,9 @@ export const isEmpty = (self: PubSub): Effect.Effect => Effect.ma * * @example * ```ts - * import { Effect, PubSub, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" + * import { PubSub } from "effect/concurrency" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(1) @@ -856,7 +873,8 @@ export const shutdown = (self: PubSub): Effect.Effect => * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -883,7 +901,7 @@ export const isShutdown = (self: PubSub): Effect.Effect => Effect * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * declare const pubsub: PubSub.PubSub * @@ -908,7 +926,9 @@ export const unsafeIsShutdown = (self: PubSub): boolean => self.shutdownFl * * @example * ```ts - * import { Effect, PubSub, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" + * import { PubSub } from "effect/concurrency" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -943,7 +963,8 @@ export const awaitShutdown = (self: PubSub): Effect.Effect => self.s * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -1000,7 +1021,7 @@ export const publish: { * * @example * ```ts - * import { PubSub } from "effect" + * import { PubSub } from "effect/concurrency" * * declare const pubsub: PubSub.PubSub * @@ -1041,7 +1062,8 @@ export const unsafePublish: { * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -1099,7 +1121,9 @@ export const publishAll: { * * @example * ```ts - * import { Effect, PubSub, Scope } from "effect" + * import { Effect } from "effect" + * import { Scope } from "effect/resources" + * import { PubSub } from "effect/concurrency" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -1171,7 +1195,9 @@ const unsubscribe = (self: Subscription): Effect.Effect => * * @example * ```ts - * import { Effect, PubSub, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" + * import { PubSub } from "effect/concurrency" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -1240,7 +1266,8 @@ export const take = (self: Subscription): Effect.Effect => * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -1285,7 +1312,8 @@ export const takeAll = (self: Subscription): Effect.Effect> => * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -1340,7 +1368,9 @@ export const takeUpTo: { * * @example * ```ts - * import { Effect, PubSub, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" + * import { PubSub } from "effect/concurrency" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -1414,7 +1444,8 @@ const takeRemainderLoop = ( * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(10) @@ -1453,7 +1484,8 @@ export const remaining = (self: Subscription): Effect.Effect => * * @example * ```ts - * import { PubSub, Option } from "effect" + * import { PubSub } from "effect/concurrency" +import * as Option from "effect/data/Option" * * declare const subscription: PubSub.Subscription * @@ -2461,7 +2493,8 @@ export class BackPressureStrategy implements PubSub.Strategy { * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * // Create PubSub with dropping strategy @@ -2536,7 +2569,8 @@ export class DroppingStrategy implements PubSub.Strategy { * * @example * ```ts - * import { Effect, PubSub } from "effect" + * import { Effect } from "effect" +import * as PubSub from "effect/concurrency/PubSub" * * const program = Effect.gen(function*() { * // Create PubSub with sliding strategy diff --git a/packages/effect/src/Queue.ts b/packages/effect/src/concurrency/Queue.ts similarity index 92% rename from packages/effect/src/Queue.ts rename to packages/effect/src/concurrency/Queue.ts index 33480b9227..2c4c86d814 100644 --- a/packages/effect/src/Queue.ts +++ b/packages/effect/src/concurrency/Queue.ts @@ -7,7 +7,8 @@ * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * // Creating a bounded queue with capacity 10 * const program = Effect.gen(function*() { @@ -32,23 +33,23 @@ * * @since 3.8.0 */ -import * as Arr from "./Array.ts" -import type { Cause } from "./Cause.ts" -import type { Effect } from "./Effect.ts" -import type { Exit, Failure } from "./Exit.ts" -import * as Filter from "./Filter.ts" -import { dual, identity } from "./Function.ts" -import type { Inspectable } from "./Inspectable.ts" -import * as core from "./internal/core.ts" -import { PipeInspectableProto } from "./internal/core.ts" -import * as internalEffect from "./internal/effect.ts" -import * as Iterable from "./Iterable.ts" -import * as MutableList from "./MutableList.ts" -import * as Option from "./Option.ts" -import { hasProperty } from "./Predicate.ts" -import * as Pull from "./Pull.ts" -import type { Scheduler } from "./Scheduler.ts" -import type * as Types from "./Types.ts" +import type { Cause } from "../Cause.ts" +import * as Arr from "../collections/Array.ts" +import * as Iterable from "../collections/Iterable.ts" +import * as MutableList from "../collections/MutableList.ts" +import * as Filter from "../data/Filter.ts" +import * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" +import type { Effect } from "../Effect.ts" +import type { Exit, Failure } from "../Exit.ts" +import { dual, identity } from "../Function.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import * as core from "../internal/core.ts" +import { PipeInspectableProto } from "../internal/core.ts" +import * as internalEffect from "../internal/effect.ts" +import type { Scheduler } from "../runtime/Scheduler.ts" +import * as Pull from "../stream/Pull.ts" +import type * as Types from "../types/Types.ts" /** * The type identifier for Queue values. @@ -87,7 +88,8 @@ export type DequeueTypeId = "~effect/Queue/Dequeue" * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -113,7 +115,8 @@ export const isQueue = ( * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -167,7 +170,8 @@ export declare namespace Dequeue { * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * // Create a bounded queue @@ -281,7 +285,8 @@ const QueueProto = { * @example * ```ts * import * as assert from "node:assert" - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * Effect.gen(function*() { * const queue = yield* Queue.make() @@ -338,7 +343,8 @@ export const make = ( * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(5) @@ -369,7 +375,8 @@ export const bounded = (capacity: number): Effect> => m * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.sliding(3) @@ -404,7 +411,8 @@ export const sliding = (capacity: number): Effect> => m * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.dropping(2) @@ -437,7 +445,8 @@ export const dropping = (capacity: number): Effect> => * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.unbounded() @@ -471,7 +480,8 @@ export const unbounded = (): Effect> => make() * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(3) @@ -531,7 +541,8 @@ export const offer = (self: Queue, message: A): Effect => * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * // Create a queue effect and extract the queue for unsafe operations * const program = Effect.gen(function*() { @@ -581,7 +592,8 @@ export const unsafeOffer = (self: Queue, message: A): boolean => { * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(3) @@ -625,7 +637,8 @@ export const offerAll = (self: Queue, messages: Iterable): Effect * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * // Create a bounded queue and use unsafe API * const program = Effect.gen(function*() { @@ -684,7 +697,8 @@ export const unsafeOfferAll = (self: Queue, messages: Iterable): * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -713,7 +727,8 @@ export const fail = (self: Queue, error: E) => done(self, core.exitF * * @example * ```ts - * import { Effect, Queue, Cause } from "effect" + * import { Effect, Cause } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -741,7 +756,8 @@ export const failCause = (self: Queue, cause: Cause) => done(self * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -777,7 +793,8 @@ export const end = (self: Queue): Effect => done(sel * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * // Create a queue and use unsafe operations * const program = Effect.gen(function*() { @@ -807,7 +824,8 @@ export const unsafeEnd = (self: Queue) => unsafeDone(self, in * * @example * ```ts - * import { Effect, Queue, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -843,7 +861,8 @@ export const done = (self: Queue, exit: Exit(self: Queue, exit: Exit(2) @@ -938,7 +958,8 @@ export const shutdown = (self: Queue): Effect => * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -1014,7 +1035,8 @@ export const filterDone: Filter.Filter = Filter.fromPredicate(isD * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(5) @@ -1054,7 +1076,8 @@ export const takeAll = (self: Dequeue): Effect, * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -1093,7 +1116,8 @@ export const takeN = ( * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -1135,7 +1159,8 @@ export const takeBetween = ( * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(3) @@ -1181,7 +1206,8 @@ export const take = (self: Dequeue): Effect => * * @example * ```ts - * import { Effect, Queue, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Queue } from "effect/concurrency" * * // Create a queue and use unsafe operations * const program = Effect.gen(function*() { @@ -1259,7 +1285,9 @@ export { * * @example * ```ts - * import { Effect, Queue, Option } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" +import * as Option from "effect/data/Option" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -1298,7 +1326,9 @@ export const size = (self: Dequeue): Effect> = * * @example * ```ts - * import { Effect, Queue, Option } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" +import * as Option from "effect/data/Option" * * // Create a queue and use unsafe operations * const program = Effect.gen(function*() { @@ -1337,7 +1367,8 @@ export const unsafeSize = (self: Dequeue): Option.Option => * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -1371,7 +1402,8 @@ export const asDequeue: (self: Queue) => Dequeue = identity * * @example * ```ts - * import { Effect, Queue } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(10) @@ -1427,7 +1459,8 @@ export const into: { * * @example * ```ts - * import { Queue, Effect } from "effect" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function* () { * const queue = yield* Queue.bounded(10) @@ -1448,7 +1481,8 @@ export const toPull: (self: Dequeue) => Pull.Pull(10) diff --git a/packages/effect/src/Ref.ts b/packages/effect/src/concurrency/Ref.ts similarity index 90% rename from packages/effect/src/Ref.ts rename to packages/effect/src/concurrency/Ref.ts index 7424654ce5..dce76fd7af 100644 --- a/packages/effect/src/Ref.ts +++ b/packages/effect/src/concurrency/Ref.ts @@ -7,7 +7,8 @@ * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * // Create a ref with initial value @@ -28,20 +29,20 @@ * * @since 2.0.0 */ -import * as Effect from "./Effect.ts" -import { dual, identity } from "./Function.ts" -import { PipeInspectableProto } from "./internal/core.ts" -import * as MutableRef from "./MutableRef.ts" -import type * as Option from "./Option.ts" -import type { Invariant } from "./Types.ts" -import type * as Unify from "./Unify.ts" +import * as MutableRef from "../concurrency/MutableRef.ts" +import type * as Option from "../data/Option.ts" +import * as Effect from "../Effect.ts" +import { dual, identity } from "../Function.ts" +import { PipeInspectableProto } from "../internal/core.ts" +import type { Invariant } from "../types/Types.ts" +import type * as Unify from "../types/Unify.ts" /** * The type identifier for Ref values. * * @example * ```ts - * import { Ref } from "effect" + * import { Ref } from "effect/concurrency" * * // Check if a value is a Ref by using the TypeId * const myRef = Ref.unsafeMake(42) @@ -58,7 +59,7 @@ export const TypeId: TypeId = "~effect/Ref" * * @example * ```ts - * import { Ref } from "effect" + * import { Ref } from "effect/concurrency" * * // The TypeId is used internally for type checking * const checkTypeId = (id: Ref.TypeId) => { @@ -80,7 +81,8 @@ export type TypeId = "~effect/Ref" * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * // Create a ref with initial value @@ -114,7 +116,8 @@ export interface Ref extends Ref.Variance { * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * // This interface is used internally for type unification * // Users typically don't need to interact with it directly @@ -139,7 +142,8 @@ export interface RefUnify extends Effect * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * // This interface is used internally to control type unification * // Users typically don't need to interact with it directly @@ -164,7 +168,7 @@ export interface RefUnifyIgnore extends Effect.EffectUnifyIgnore { * * @example * ```ts - * import { Ref } from "effect" + * import { Ref } from "effect/concurrency" * * // Access the TypeId constant * console.log(Ref.TypeId) // "~effect/Ref" @@ -184,7 +188,8 @@ export declare namespace Ref { * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * // This interface defines the invariant nature of Ref's type parameter * // A Ref is both a producer and consumer of A @@ -228,7 +233,7 @@ const RefProto = { * * @example * ```ts - * import { Ref } from "effect" + * import { Ref } from "effect/concurrency" * * // Create a ref directly without Effect * const counter = Ref.unsafeMake(0) @@ -258,7 +263,8 @@ export const unsafeMake = (value: A): Ref => { * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * const ref = yield* Ref.make(42) @@ -277,7 +283,8 @@ export const make = (value: A): Effect.Effect> => Effect.sync(() => un * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * const ref = yield* Ref.make(42) @@ -296,7 +303,8 @@ export const get = (self: Ref) => Effect.sync(() => self.ref.current) * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * const ref = yield* Ref.make(0) @@ -329,7 +337,8 @@ export const set = dual< * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * const ref = yield* Ref.make("initial") @@ -363,7 +372,8 @@ export const getAndSet = dual< * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * const counter = yield* Ref.make(10) @@ -399,7 +409,9 @@ export const getAndUpdate = dual< * * @example * ```ts - * import { Effect, Option, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" +import * as Option from "effect/data/Option" * * const program = Effect.gen(function*() { * const counter = yield* Ref.make(5) @@ -447,7 +459,8 @@ export const getAndUpdateSome = dual< * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * const ref = yield* Ref.make(10) @@ -486,7 +499,8 @@ export const setAndGet = dual< * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * const counter = yield* Ref.make(10) @@ -538,7 +552,9 @@ export const modify = dual< * * @example * ```ts - * import { Effect, Option, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" +import * as Option from "effect/data/Option" * * const program = Effect.gen(function*() { * const counter = yield* Ref.make(5) @@ -597,7 +613,8 @@ export const modifySome = dual< * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * const counter = yield* Ref.make(5) @@ -634,7 +651,8 @@ export const update = dual< * * @example * ```ts - * import { Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" * * const program = Effect.gen(function*() { * const counter = yield* Ref.make(5) @@ -665,7 +683,9 @@ export const updateAndGet = dual< * * @example * ```ts - * import { Effect, Option, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" +import * as Option from "effect/data/Option" * * const program = Effect.gen(function*() { * const counter = yield* Ref.make(5) @@ -712,7 +732,9 @@ export const updateSome = dual< * * @example * ```ts - * import { Effect, Option, Ref } from "effect" + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" +import * as Option from "effect/data/Option" * * const program = Effect.gen(function*() { * const counter = yield* Ref.make(10) @@ -754,7 +776,7 @@ export const updateSomeAndGet = dual< * * @example * ```ts - * import { Ref } from "effect" + * import { Ref } from "effect/concurrency" * * // Create a ref directly * const counter = Ref.unsafeMake(42) diff --git a/packages/effect/src/concurrency/index.ts b/packages/effect/src/concurrency/index.ts new file mode 100644 index 0000000000..b69ccb4ddc --- /dev/null +++ b/packages/effect/src/concurrency/index.ts @@ -0,0 +1,228 @@ +/** + * @since 4.0.0 + */ + +/** + * This module provides utilities for working with `Deferred`, a powerful concurrency + * primitive that represents an asynchronous variable that can be set exactly once. + * Multiple fibers can await the same `Deferred` and will all be notified when it + * completes. + * + * A `Deferred` can be: + * - **Completed successfully** with a value of type `A` + * - **Failed** with an error of type `E` + * - **Interrupted** if the fiber setting it is interrupted + * + * Key characteristics: + * - **Single assignment**: Can only be completed once + * - **Multiple waiters**: Many fibers can await the same `Deferred` + * - **Fiber-safe**: Thread-safe operations across concurrent fibers + * - **Composable**: Works seamlessly with other Effect operations + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" + * import { Fiber } from "effect/runtime" + * + * // Basic usage: coordinate between fibers + * const program = Effect.gen(function* () { + * const deferred = yield* Deferred.make() + * + * // Fiber 1: waits for the value + * const waiter = yield* Effect.fork( + * Effect.gen(function* () { + * const value = yield* Deferred.await(deferred) + * console.log("Received:", value) + * return value + * }) + * ) + * + * // Fiber 2: sets the value after a delay + * const setter = yield* Effect.fork( + * Effect.gen(function* () { + * yield* Effect.sleep("1 second") + * yield* Deferred.succeed(deferred, "Hello from setter!") + * }) + * ) + * + * // Wait for both fibers + * yield* Fiber.join(waiter) + * yield* Fiber.join(setter) + * }) + * + * // Producer-consumer pattern + * const producerConsumer = Effect.gen(function* () { + * const buffer = yield* Deferred.make() + * + * const producer = Effect.gen(function* () { + * const data = [1, 2, 3, 4, 5] + * yield* Deferred.succeed(buffer, data) + * }) + * + * const consumer = Effect.gen(function* () { + * const data = yield* Deferred.await(buffer) + * return data.reduce((sum, n) => sum + n, 0) + * }) + * + * const [, result] = yield* Effect.all([producer, consumer]) + * return result // 15 + * }) + * ``` + * + * @since 2.0.0 + */ +export * as Deferred from "./Deferred.ts" + +/** + * @since 2.0.0 + */ +export * as FiberHandle from "./FiberHandle.ts" + +/** + * @since 2.0.0 + */ +export * as FiberMap from "./FiberMap.ts" + +/** + * @since 2.0.0 + */ +export * as FiberSet from "./FiberSet.ts" + +/** + * @fileoverview + * MutableRef provides a mutable reference container that allows safe mutation of values + * in functional programming contexts. It serves as a bridge between functional and imperative + * programming paradigms, offering atomic operations for state management. + * + * Unlike regular variables, MutableRef encapsulates mutable state and provides controlled + * access through a standardized API. It supports atomic compare-and-set operations for + * thread-safe updates and integrates seamlessly with Effect's ecosystem. + * + * Key Features: + * - Mutable reference semantics with functional API + * - Atomic compare-and-set operations for safe concurrent updates + * - Specialized operations for numeric and boolean values + * - Chainable operations that return the reference or the value + * - Integration with Effect's Equal interface for value comparison + * + * Common Use Cases: + * - State containers in functional applications + * - Counters and accumulators + * - Configuration that needs to be updated at runtime + * - Caching and memoization scenarios + * - Inter-module communication via shared references + * + * Performance Characteristics: + * - Get/Set: O(1) + * - Compare-and-set: O(1) + * - All operations: O(1) + * + * @since 2.0.0 + * @category data-structures + */ +export * as MutableRef from "./MutableRef.ts" + +/** + * This module provides utilities for working with publish-subscribe (PubSub) systems. + * + * A PubSub is an asynchronous message hub where publishers can publish messages and subscribers + * can subscribe to receive those messages. PubSub supports various backpressure strategies, + * message replay, and concurrent access from multiple producers and consumers. + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Scope } from "effect/resources" + * import { PubSub } from "effect/concurrency" + * + * const program = Effect.gen(function*() { + * const pubsub = yield* PubSub.bounded(10) + * + * // Publisher + * yield* PubSub.publish(pubsub, "Hello") + * yield* PubSub.publish(pubsub, "World") + * + * // Subscriber + * yield* Effect.scoped(Effect.gen(function*() { + * const subscription = yield* PubSub.subscribe(pubsub) + * const message1 = yield* PubSub.take(subscription) + * const message2 = yield* PubSub.take(subscription) + * console.log(message1, message2) // "Hello", "World" + * })) + * }) + * ``` + * + * @since 2.0.0 + */ +export * as PubSub from "./PubSub.ts" + +/** + * This module provides utilities for working with asynchronous queues that support various backpressure strategies. + * + * A Queue is a data structure that allows producers to add elements and consumers to take elements + * in a thread-safe manner. The queue supports different strategies for handling backpressure when + * the queue reaches capacity. + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" + * + * // Creating a bounded queue with capacity 10 + * const program = Effect.gen(function*() { + * const queue = yield* Queue.bounded(10) + * + * // Producer: add items to queue + * yield* Queue.offer(queue, 1) + * yield* Queue.offer(queue, 2) + * yield* Queue.offerAll(queue, [3, 4, 5]) + * + * // Consumer: take items from queue + * const item1 = yield* Queue.take(queue) + * const item2 = yield* Queue.take(queue) + * const remaining = yield* Queue.takeAll(queue) + * + * console.log({ item1, item2, remaining }) // { item1: 1, item2: 2, remaining: [3, 4, 5] } + * + * // Signal completion + * yield* Queue.end(queue) + * }) + * ``` + * + * @since 3.8.0 + */ +export * as Queue from "./Queue.ts" + +/** + * This module provides utilities for working with mutable references in a functional context. + * + * A Ref is a mutable reference that can be read, written, and atomically modified. Unlike plain + * mutable variables, Refs are thread-safe and work seamlessly with Effect's concurrency model. + * They provide atomic operations for safe state management in concurrent programs. + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Ref } from "effect/concurrency" + * + * const program = Effect.gen(function*() { + * // Create a ref with initial value + * const counter = yield* Ref.make(0) + * + * // Atomic operations + * yield* Ref.update(counter, n => n + 1) + * yield* Ref.update(counter, n => n * 2) + * + * const value = yield* Ref.get(counter) + * console.log(value) // 2 + * + * // Atomic modify with return value + * const previous = yield* Ref.getAndSet(counter, 100) + * console.log(previous) // 2 + * }) + * ``` + * + * @since 2.0.0 + */ +export * as Ref from "./Ref.ts" diff --git a/packages/effect/src/concurrency/index.ts.tpl b/packages/effect/src/concurrency/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/concurrency/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/config/Config.ts b/packages/effect/src/config/Config.ts index 592c7f2fb2..811bdefd71 100644 --- a/packages/effect/src/config/Config.ts +++ b/packages/effect/src/config/Config.ts @@ -1,24 +1,24 @@ /** * @since 4.0.0 */ -import * as Arr from "../Array.ts" -import type * as Brand from "../Brand.ts" import * as Cause from "../Cause.ts" -import * as DateTime_ from "../DateTime.ts" -import * as Duration_ from "../Duration.ts" +import * as Arr from "../collections/Array.ts" +import type * as Brand from "../data/Brand.ts" +import * as Filter from "../data/Filter.ts" +import type * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Redacted_ from "../data/Redacted.ts" import * as Effect from "../Effect.ts" import * as Exit from "../Exit.ts" -import * as Filter from "../Filter.ts" import type { LazyArg } from "../Function.ts" import { constant, dual } from "../Function.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" import { PipeInspectableProto, YieldableProto } from "../internal/core.ts" -import * as LogLevel_ from "../LogLevel.ts" -import type * as Option from "../Option.ts" -import type { Pipeable } from "../Pipeable.ts" -import { hasProperty } from "../Predicate.ts" -import * as Redacted_ from "../Redacted.ts" -import * as Str from "../String.ts" -import type { NoInfer } from "../Types.ts" +import * as LogLevel_ from "../logging/LogLevel.ts" +import * as Str from "../primitives/String.ts" +import * as DateTime_ from "../time/DateTime.ts" +import * as Duration_ from "../time/Duration.ts" +import type { NoInfer } from "../types/Types.ts" import { type ConfigError, filterMissingDataOnly, InvalidData, MissingData } from "./ConfigError.ts" import * as ConfigProvider from "./ConfigProvider.ts" @@ -423,7 +423,8 @@ export const primitive: { * * @example * ```ts - * import { Effect, Filter } from "effect" + * import { Effect } from "effect" + * import * as Filter from "effect/data/Filter" * import { Config, ConfigProvider } from "effect/config" * * // Create a custom email validation config @@ -446,7 +447,8 @@ export const primitive: { * * @example * ```ts - * import { Effect, Filter } from "effect" + * import { Effect } from "effect" + * import * as Filter from "effect/data/Filter" * import { Config, ConfigProvider } from "effect/config" * * // Create a custom enum-like config using fromFilter @@ -468,7 +470,8 @@ export const primitive: { * * @example * ```ts - * import { Effect, Filter } from "effect" + * import { Effect } from "effect" + * import * as Filter from "effect/data/Filter" * import { Config, ConfigProvider } from "effect/config" * * // Create a config that parses comma-separated values into an array @@ -1068,7 +1071,8 @@ export const Url = (name?: string): Config => * * @example * ```ts - * import { Effect, LogLevel } from "effect" + * import { Effect } from "effect" + * import type { LogLevel } from "effect/logging/LogLevel" * import { Config, ConfigProvider } from "effect/config" * * // Create a log level config @@ -1077,12 +1081,13 @@ export const Url = (name?: string): Config => * // Parse from environment variable * const provider = ConfigProvider.fromEnv({ environment: { LOG_LEVEL: "Debug" } }) * const result = Effect.runSync(Effect.provide(logLevel.asEffect(), ConfigProvider.layer(provider))) - * // result is "Debug" as LogLevel.LogLevel + * // result is "Debug" as LogLevel * ``` * * @example * ```ts - * import { Effect, LogLevel } from "effect" + * import { Effect } from "effect" + * import type { LogLevel } from "effect/logging/LogLevel" * import { Config, ConfigProvider } from "effect/config" * * // Case-insensitive parsing @@ -1093,17 +1098,18 @@ export const Url = (name?: string): Config => * const provider2 = ConfigProvider.fromEnv({ environment: { LOG_LEVEL: "ERROR" } }) * const provider3 = ConfigProvider.fromEnv({ environment: { LOG_LEVEL: "Error" } }) * - * // All produce "Error" as LogLevel.LogLevel + * // All produce "Error" as LogLevel * ``` * * @example * ```ts - * import { Effect, LogLevel } from "effect" + * import { Effect } from "effect" + * import type { LogLevel } from "effect/logging/LogLevel" * import { Config, ConfigProvider } from "effect/config" * * // Using with default values and validation * const logLevel = Config.LogLevel("LOG_LEVEL").pipe( - * Config.withDefault("Info" as LogLevel.LogLevel) + * Config.withDefault("Info" as LogLevel) * ) * * // Valid log levels: "All", "Fatal", "Error", "Warn", "Info", "Debug", "Trace", "None" @@ -1179,7 +1185,8 @@ export const Duration = (name?: string): Config => * * @example * ```ts - * import { Effect, Redacted } from "effect" + * import { Effect } from "effect" + * import { Redacted } from "effect/data" * import { Config, ConfigProvider } from "effect/config" * * // Create a redacted config without a name @@ -1277,7 +1284,8 @@ export const Redacted: { * * @example * ```ts - * import { Brand, Effect } from "effect" + * import { Effect } from "effect" + * import { Brand } from "effect/data" * import { Config, ConfigProvider } from "effect/config" * * // Define a branded string type for user IDs @@ -1300,7 +1308,8 @@ export const Redacted: { * * @example * ```ts - * import { Brand, Effect } from "effect" + * import { Effect } from "effect" + * import { Brand } from "effect/data" * import { Config, ConfigProvider } from "effect/config" * * // Define a branded number type for positive integers @@ -1329,7 +1338,8 @@ export const Redacted: { * * @example * ```ts - * import { Brand, Effect } from "effect" + * import { Effect } from "effect" + * import { Brand } from "effect/data" * import { Config, ConfigProvider } from "effect/config" * * // Define a branded string type for email addresses @@ -1362,7 +1372,8 @@ export const Redacted: { * * @example * ```ts - * import { Brand, Effect } from "effect" + * import { Effect } from "effect" + * import { Brand } from "effect/data" * import { Config, ConfigProvider } from "effect/config" * * // Define a branded type for port numbers diff --git a/packages/effect/src/config/ConfigError.ts b/packages/effect/src/config/ConfigError.ts index 9896f301ac..05c18d79c9 100644 --- a/packages/effect/src/config/ConfigError.ts +++ b/packages/effect/src/config/ConfigError.ts @@ -2,9 +2,9 @@ * @since 4.0.0 */ import type * as Cause from "../Cause.ts" -import * as Data from "../Data.ts" -import * as Filter from "../Filter.ts" -import { hasProperty } from "../Predicate.ts" +import * as Data from "../data/Data.ts" +import * as Filter from "../data/Filter.ts" +import { hasProperty } from "../data/Predicate.ts" /** * @since 4.0.0 diff --git a/packages/effect/src/config/ConfigProvider.ts b/packages/effect/src/config/ConfigProvider.ts index 1963d8693a..6b8056cd8c 100644 --- a/packages/effect/src/config/ConfigProvider.ts +++ b/packages/effect/src/config/ConfigProvider.ts @@ -1,21 +1,21 @@ /** * @since 4.0.0 */ -import * as Arr from "../Array.ts" import * as Cause from "../Cause.ts" +import * as Arr from "../collections/Array.ts" +import { hasProperty } from "../data/Predicate.ts" import * as Effect from "../Effect.ts" import { constant, dual, identity } from "../Function.ts" -import { toStringUnknown } from "../Inspectable.ts" +import { toStringUnknown } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" import { PipeInspectableProto } from "../internal/core.ts" -import * as Layer from "../Layer.ts" -import type { Pipeable } from "../Pipeable.ts" import * as FileSystem from "../platform/FileSystem.ts" import * as Path from "../platform/Path.ts" import type { PlatformError } from "../platform/PlatformError.ts" -import { hasProperty } from "../Predicate.ts" -import type { Scope } from "../Scope.ts" -import * as ServiceMap from "../ServiceMap.ts" -import * as Str from "../String.ts" +import * as Str from "../primitives/String.ts" +import type { Scope } from "../resources/Scope.ts" +import * as Layer from "../services/Layer.ts" +import * as ServiceMap from "../services/ServiceMap.ts" import { type ConfigError, filterMissingDataOnly, MissingData, SourceError } from "./ConfigError.ts" /** diff --git a/packages/effect/src/Brand.ts b/packages/effect/src/data/Brand.ts similarity index 93% rename from packages/effect/src/Brand.ts rename to packages/effect/src/data/Brand.ts index 1793e74559..af48365cf2 100644 --- a/packages/effect/src/Brand.ts +++ b/packages/effect/src/data/Brand.ts @@ -16,17 +16,17 @@ * * @since 2.0.0 */ -import * as Arr from "./Array.ts" -import { identity } from "./Function.ts" -import * as Option from "./Option.ts" -import type { Predicate } from "./Predicate.ts" -import * as Result from "./Result.ts" -import type * as Types from "./Types.ts" +import * as Arr from "../collections/Array.ts" +import * as Option from "../data/Option.ts" +import type { Predicate } from "../data/Predicate.ts" +import * as Result from "../data/Result.ts" +import { identity } from "../Function.ts" +import type * as Types from "../types/Types.ts" /** * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * // TypeId is used internally for branded type identification * console.log(Brand.TypeId) // "~effect/Brand" @@ -40,7 +40,7 @@ export const TypeId: TypeId = "~effect/Brand" /** * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * // TypeId represents the branded type identifier * type BrandTypeId = Brand.TypeId @@ -54,7 +54,7 @@ export type TypeId = "~effect/Brand" /** * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * // RefinedConstructorsTypeId is used internally for refined constructor identification * console.log(Brand.RefinedConstructorsTypeId) // "~effect/Brand/Refined" @@ -68,7 +68,7 @@ export const RefinedConstructorsTypeId: RefinedConstructorsTypeId = "~effect/Bra /** * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * // RefinedConstructorsTypeId represents the refined constructor identifier * type RefineTypeId = Brand.RefinedConstructorsTypeId @@ -84,7 +84,7 @@ export type RefinedConstructorsTypeId = "~effect/Brand/Refined" * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * // Brand interface is used to create branded types * type UserId = string & Brand.Brand<"UserId"> @@ -109,7 +109,7 @@ export interface Brand { * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * // Define a branded type * type UserId = string & Brand.Brand<"UserId"> @@ -130,7 +130,7 @@ export declare namespace Brand { * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * // BrandErrors represents validation failures * const error1 = Brand.error("Invalid value", { value: 42 }) @@ -148,7 +148,7 @@ export declare namespace Brand { * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * // RefinementError represents a validation failure * const error = Brand.error("Value must be positive", { value: -5, expected: "> 0" }) @@ -168,7 +168,7 @@ export declare namespace Brand { * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * type PositiveNumber = number & Brand.Brand<"Positive"> * const PositiveNumber = Brand.refined( @@ -212,7 +212,7 @@ export declare namespace Brand { * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * type PositiveNumber = number & Brand.Brand<"Positive"> * const PositiveNumber = Brand.refined( @@ -234,7 +234,7 @@ export declare namespace Brand { * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * type UserId = string & Brand.Brand<"UserId"> * const UserId = Brand.nominal() @@ -253,7 +253,7 @@ export declare namespace Brand { * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * type UserId = string & Brand.Brand<"UserId"> * const UserId = Brand.nominal() @@ -278,7 +278,7 @@ export declare namespace Brand { * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * type Int = number & Brand.Brand<"Int"> * type Positive = number & Brand.Brand<"Positive"> @@ -309,7 +309,7 @@ export declare namespace Brand { * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * type UserId = Brand.Branded * // Equivalent to: string & Brand.Brand<"UserId"> @@ -325,7 +325,7 @@ export type Branded = A & Brand * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * const validationError = Brand.error("Value must be positive", { value: -5 }) * console.log(validationError) @@ -345,7 +345,7 @@ export const error = (message: string, meta?: unknown): Brand.BrandErrors => [{ * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * const error1 = Brand.error("Must be positive") * const error2 = Brand.error("Must be integer") @@ -373,7 +373,7 @@ export const errors: (...errors: Array) => Brand.BrandErrors * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * type Int = number & Brand.Brand<"Int"> * @@ -426,7 +426,7 @@ export function refined>( * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * type UserId = string & Brand.Brand<"UserId"> * type ProductId = string & Brand.Brand<"ProductId"> @@ -463,7 +463,7 @@ export const nominal = >(): Brand.Constructor< * * @example * ```ts - * import { Brand } from "effect" + * import { Brand } from "effect/data" * * type Int = number & Brand.Brand<"Int"> * const Int = Brand.refined( diff --git a/packages/effect/src/Data.ts b/packages/effect/src/data/Data.ts similarity index 93% rename from packages/effect/src/Data.ts rename to packages/effect/src/data/Data.ts index 6c5bbd344c..8bd733f85f 100644 --- a/packages/effect/src/Data.ts +++ b/packages/effect/src/data/Data.ts @@ -11,7 +11,8 @@ * * @example * ```ts - * import { Data, Equal } from "effect" + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" * * // Basic struct usage * const person1 = Data.struct({ name: "Alice", age: 30 }) @@ -43,13 +44,13 @@ * * @since 2.0.0 */ -import type * as Cause from "./Cause.ts" -import * as core from "./internal/core.ts" -import { StructuralPrototype } from "./internal/core.ts" -import * as internal from "./internal/data.ts" -import * as Predicate from "./Predicate.ts" -import type * as Types from "./Types.ts" -import type { Unify } from "./Unify.ts" +import type * as Cause from "../Cause.ts" +import * as Predicate from "../data/Predicate.ts" +import * as core from "../internal/core.ts" +import { StructuralPrototype } from "../internal/core.ts" +import * as internal from "../internal/data.ts" +import type * as Types from "../types/Types.ts" +import type { Unify } from "../types/Unify.ts" /** * A namespace providing utilities for Case constructors. @@ -59,7 +60,7 @@ import type { Unify } from "./Unify.ts" * * @example * ```ts - * import { Data } from "effect" + * import { Data } from "effect/data" * * interface User { * readonly name: string @@ -88,7 +89,7 @@ export declare namespace Case { * * @example * ```ts - * import { Data } from "effect" + * import { Data } from "effect/data" * * interface User { * readonly name: string @@ -123,7 +124,8 @@ export declare namespace Case { * @example * ```ts * import * as assert from "node:assert" - * import { Data, Equal } from "effect" + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" * * const alice = Data.struct({ name: "Alice", age: 30 }) * @@ -152,7 +154,8 @@ export const struct: >( * * @example * ```ts - * import { Data, Equal } from "effect" + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" * * const obj = { name: "Alice", age: 30 } * const person = Data.unsafeStruct(obj) @@ -178,7 +181,8 @@ export const unsafeStruct = >( * @example * ```ts * import * as assert from "node:assert" - * import { Data, Equal } from "effect" + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" * * const alice = Data.tuple("Alice", 30) * const bob = Data.tuple("Bob", 40) @@ -204,7 +208,8 @@ export const tuple = >(...as: As): Readonly => * @example * ```ts * import * as assert from "node:assert" - * import { Data, Equal } from "effect" + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" * * const alice = Data.struct({ name: "Alice", age: 30 }) * const bob = Data.struct({ name: "Bob", age: 40 }) @@ -237,7 +242,8 @@ export const array = >(as: As): Readonly => un * * @example * ```ts - * import { Data, Equal } from "effect" + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" * * const originalArray = [1, 2, 3] * const dataArray = Data.unsafeArray(originalArray) @@ -266,7 +272,8 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { Data, Equal } from "effect" + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" * * interface Person { * readonly name: string @@ -297,7 +304,7 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { Data } from "effect" + * import { Data } from "effect/data" * * interface Person { * readonly _tag: "Person" // the tag @@ -329,7 +336,8 @@ export const tagged = ( * @example * ```ts * import * as assert from "node:assert" - * import { Data, Equal } from "effect" + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" * * class Person extends Data.Class<{ readonly name: string }> {} * @@ -357,7 +365,8 @@ export const Class: new = {}>( * @example * ```ts * import * as assert from "node:assert" - * import { Data, Equal } from "effect" + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" * * class Person extends Data.TaggedClass("Person")<{ readonly name: string }> {} * @@ -396,7 +405,8 @@ export const TaggedClass = ( * * @example * ```ts - * import { Data, Equal } from "effect" + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" * * class Person extends Data.Structural<{ name: string; age: number }> {} * @@ -422,7 +432,7 @@ export const Structural: new( * * @example * ```ts - * import { Data } from "effect" + * import { Data } from "effect/data" * * // Define a tagged enum type * type HttpError = Data.TaggedEnum<{ @@ -473,7 +483,7 @@ type UntaggedChildren = true extends ChildrenAreTagged * * @example * ```ts - * import { Data } from "effect" + * import { Data } from "effect/data" * * // Basic tagged enum usage * const { Success, Failure } = Data.taggedEnum< @@ -497,7 +507,7 @@ export declare namespace TaggedEnum { * * @example * ```ts - * import * as Data from "effect/Data" + * import { Data } from "effect/data" * * // Define a tagged enum with generic parameters * interface MyTaggedEnum extends Data.TaggedEnum.WithGenerics<2> { @@ -531,7 +541,7 @@ export declare namespace TaggedEnum { * * @example * ```ts - * import { Data } from "effect" + * import { Data } from "effect/data" * * // Define a generic Option type * type Option = Data.TaggedEnum<{ @@ -585,7 +595,7 @@ export declare namespace TaggedEnum { * * @example * ```ts - * import { Data } from "effect" + * import { Data } from "effect/data" * * type Result = * | { readonly _tag: "Success"; readonly value: number } @@ -621,7 +631,7 @@ export declare namespace TaggedEnum { * * @example * ```ts - * import { Data } from "effect" + * import { Data } from "effect/data" * * type Result = * | { readonly _tag: "Success"; readonly value: number } @@ -654,7 +664,7 @@ export declare namespace TaggedEnum { * * @example * ```ts - * import { Data } from "effect" + * import { Data } from "effect/data" * * type HttpError = * | { readonly _tag: "BadRequest"; readonly message: string } @@ -721,7 +731,7 @@ export declare namespace TaggedEnum { * * @example * ```ts - * import { Data } from "effect" + * import { Data } from "effect/data" * * type Result = Data.TaggedEnum<{ * Failure: { readonly error: E } @@ -809,7 +819,7 @@ export declare namespace TaggedEnum { * * @example * ```ts - * import { Data } from "effect" + * import { Data } from "effect/data" * * const { BadRequest, NotFound } = Data.taggedEnum< * | { readonly _tag: "BadRequest"; readonly status: 400; readonly message: string } @@ -820,7 +830,7 @@ export declare namespace TaggedEnum { * ``` * * @example - * import { Data } from "effect" + * import { Data } from "effect/data" * * type MyResult = Data.TaggedEnum<{ * Failure: { readonly error: E } @@ -938,7 +948,8 @@ function taggedMatch< * * @example * ```ts - * import { Data, Effect, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Data } from "effect/data" * * class NetworkError extends Data.Error<{ code: number; message: string }> {} * @@ -966,7 +977,8 @@ export const Error: new = {}>( * * @example * ```ts - * import { Data, Effect, pipe } from "effect" + * import { Effect, pipe } from "effect" + * import { Data } from "effect/data" * * class NetworkError extends Data.TaggedError("NetworkError")<{ * code: number diff --git a/packages/effect/src/Equivalence.ts b/packages/effect/src/data/Equivalence.ts similarity index 95% rename from packages/effect/src/Equivalence.ts rename to packages/effect/src/data/Equivalence.ts index fffc4ed036..595f389210 100644 --- a/packages/effect/src/Equivalence.ts +++ b/packages/effect/src/data/Equivalence.ts @@ -10,7 +10,8 @@ * * @example * ```ts - * import { Equivalence, Array } from "effect" + * import { Equivalence } from "effect/data" + * import { Array } from "effect/collections" * * // Case-insensitive string equivalence * const caseInsensitive = Equivalence.make((a, b) => @@ -36,8 +37,8 @@ * * @since 2.0.0 */ -import { dual } from "./Function.ts" -import type { TypeLambda } from "./HKT.ts" +import { dual } from "../Function.ts" +import type { TypeLambda } from "../types/HKT.ts" /** * Represents an equivalence relation over type `A`. @@ -47,7 +48,7 @@ import type { TypeLambda } from "./HKT.ts" * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * // Simple number equivalence * const numberEq: Equivalence.Equivalence = (a, b) => a === b @@ -80,8 +81,8 @@ export type Equivalence = (self: A, that: A) => boolean * * @example * ```ts - * import { Equivalence } from "effect" - * import type { Kind } from "effect/HKT" + * import { Equivalence } from "effect/data" + * import type { Kind } from "effect/types/HKT" * * // Used internally for type-level computations * type NumberEquivalence = Kind @@ -103,7 +104,7 @@ export interface EquivalenceTypeLambda extends TypeLambda { * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * // Case-insensitive string equivalence * const caseInsensitive = Equivalence.make((a, b) => @@ -142,7 +143,7 @@ const isStrictEquivalent = (x: unknown, y: unknown) => x === y * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * const strictEq = Equivalence.strict() * @@ -171,14 +172,14 @@ export const strict: () => Equivalence = () => isStrictEquivalent * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * console.log(Equivalence.string("hello", "hello")) // true * console.log(Equivalence.string("hello", "Hello")) // false * console.log(Equivalence.string("hello", "world")) // false * * // Use with data structures - * import { Array } from "effect" + * import { Array } from "effect/collections" * const words = ["apple", "banana", "apple", "cherry"] * const unique = Array.dedupeWith(words, Equivalence.string) * console.log(unique) // ["apple", "banana", "cherry"] @@ -197,7 +198,7 @@ export const string: Equivalence = strict() * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * console.log(Equivalence.number(42, 42)) // true * console.log(Equivalence.number(42, 43)) // false @@ -220,7 +221,7 @@ export const number: Equivalence = strict() * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * console.log(Equivalence.boolean(true, true)) // true * console.log(Equivalence.boolean(false, false)) // true @@ -243,7 +244,7 @@ export const boolean: Equivalence = strict() * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * console.log(Equivalence.bigint(123n, 123n)) // true * console.log(Equivalence.bigint(123n, 456n)) // false @@ -268,7 +269,7 @@ export const bigint: Equivalence = strict() * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * const sym1 = Symbol("test") * const sym2 = Symbol("test") @@ -293,7 +294,7 @@ export const symbol: Equivalence = strict() * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * interface Person { * name: string @@ -337,7 +338,7 @@ export const combine: { * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * interface Product { * id: string @@ -391,7 +392,7 @@ const isAlwaysEquivalent: Equivalence = (_x, _y) => true * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * interface Point3D { * x: number @@ -433,7 +434,7 @@ export const combineAll = (collection: Iterable>): Equivalence * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * interface User { * id: number @@ -484,7 +485,7 @@ export const mapInput: { * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * const date1 = new Date("2023-01-01T00:00:00Z") * const date2 = new Date("2023-01-01T00:00:00Z") @@ -513,7 +514,7 @@ export const Date: Equivalence = mapInput(number, (date) => date.getTime() * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * const numberStringEq = Equivalence.product( * Equivalence.number, @@ -559,7 +560,7 @@ export const product: { * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * // String array equivalence using case-insensitive comparison * const caseInsensitive = Equivalence.mapInput( @@ -606,7 +607,7 @@ export const all = (collection: Iterable>): Equivalence( * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * // Create equivalence for string tuples * const stringTupleEq = Equivalence.tuple([ @@ -697,7 +698,7 @@ export const tuple = >>( * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * const numberArrayEq = Equivalence.array(Equivalence.number) * @@ -746,7 +747,7 @@ export const array = (item: Equivalence): Equivalence> => * * @example * ```ts - * import { Equivalence } from "effect" + * import { Equivalence } from "effect/data" * * interface Person { * name: string diff --git a/packages/effect/src/Filter.ts b/packages/effect/src/data/Filter.ts similarity index 96% rename from packages/effect/src/Filter.ts rename to packages/effect/src/data/Filter.ts index db593850f1..c6624e90db 100644 --- a/packages/effect/src/Filter.ts +++ b/packages/effect/src/data/Filter.ts @@ -1,13 +1,13 @@ /** * @since 4.0.0 */ -import type { Effect } from "./Effect.ts" -import * as Equal from "./Equal.ts" -import { dual } from "./Function.ts" -import type * as Option from "./Option.ts" -import * as Predicate from "./Predicate.ts" -import type * as Result from "./Result.ts" -import type { EqualsWith, ExcludeTag, ExtractTag, Tags } from "./Types.ts" +import type * as Option from "../data/Option.ts" +import * as Predicate from "../data/Predicate.ts" +import type * as Result from "../data/Result.ts" +import type { Effect } from "../Effect.ts" +import { dual } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import type { EqualsWith, ExcludeTag, ExtractTag, Tags } from "../types/Types.ts" /** * Represents a filter function that can transform inputs to outputs or filter them out. @@ -17,7 +17,7 @@ import type { EqualsWith, ExcludeTag, ExtractTag, Tags } from "./Types.ts" * * @example * ```ts - * import { Filter } from "effect" + * import { Filter } from "effect/data" * * // A filter that only passes positive numbers * const positiveFilter: Filter.Filter = (n) => @@ -42,7 +42,8 @@ export interface Filter { * * @example * ```ts - * import { Effect, Filter } from "effect" + * import { Effect } from "effect" + * import { Filter } from "effect/data" * * // An effectful filter that validates user data * type User = { id: string; isActive: boolean } @@ -120,7 +121,7 @@ export type WithoutFail = Exclude> * * @example * ```ts - * import { Filter } from "effect" + * import { Filter } from "effect/data" * * // Create a filter for positive numbers * const positiveFilter = Filter.make((n: number) => @@ -153,7 +154,8 @@ export const make = ( * * @example * ```ts - * import { Effect, Filter } from "effect" + * import { Effect } from "effect" + * import { Filter } from "effect/data" * * // Create an effectful filter that validates async * const asyncValidate = Filter.makeEffect((id: string) => @@ -224,7 +226,7 @@ export { * * @example * ```ts - * import { Filter } from "effect" + * import { Filter } from "effect/data" * * // Create filter from predicate * const positiveNumbers = Filter.fromPredicate((n: number) => n > 0) @@ -291,7 +293,7 @@ export const toPredicate = ( * * @example * ```ts - * import { Filter } from "effect" + * import { Filter } from "effect/data" * * console.log(Filter.string("hello")) // "hello" * console.log(Filter.string(42)) // fail @@ -349,7 +351,7 @@ export const instanceOf = * * @example * ```ts - * import { Filter } from "effect" + * import { Filter } from "effect/data" * * console.log(Filter.number(42)) // 42 * console.log(Filter.number(3.14)) // 3.14 @@ -517,7 +519,7 @@ export const zipWith: { * * @example * ```ts - * import { Filter } from "effect" + * import { Filter } from "effect/data" * * const positiveNumbers = Filter.fromPredicate((n: number) => n > 0) * const evenNumbers = Filter.fromPredicate((n: number) => n % 2 === 0) @@ -564,7 +566,7 @@ export const zip: { * * @example * ```ts - * import { Filter } from "effect" + * import { Filter } from "effect/data" * * const positiveNumbers = Filter.fromPredicate((n: number) => n > 0) * const evenNumbers = Filter.fromPredicate((n: number) => n % 2 === 0) @@ -610,7 +612,7 @@ export const andLeft: { * * @example * ```ts - * import { Filter } from "effect" + * import { Filter } from "effect/data" * * const positiveNumbers = Filter.fromPredicate((n: number) => n > 0) * const doubleNumbers = Filter.make((n: number) => n > 0 ? n * 2 : Filter.fail(n)) @@ -656,7 +658,7 @@ export const andRight: { * * @example * ```ts - * import { Filter } from "effect" + * import { Filter } from "effect/data" * * // First filter: only pass strings * const stringFilter = Filter.string @@ -707,7 +709,7 @@ export const compose: { * input. * * @since 4.0.0 - * @category Unsafe + * @category Combinators */ export const composePassthrough: { ( diff --git a/packages/effect/src/Option.ts b/packages/effect/src/data/Option.ts similarity index 94% rename from packages/effect/src/Option.ts rename to packages/effect/src/data/Option.ts index f09c214945..12537a1b5a 100644 --- a/packages/effect/src/Option.ts +++ b/packages/effect/src/data/Option.ts @@ -1,25 +1,25 @@ /** * @since 2.0.0 */ -import type { NoSuchElementError } from "./Cause.ts" -import type { EffectIterator, Yieldable } from "./Effect.ts" -import * as Equal from "./Equal.ts" -import * as Equivalence from "./Equivalence.ts" -import type { LazyArg } from "./Function.ts" -import { constNull, constUndefined, dual, identity, isFunction } from "./Function.ts" -import type { TypeLambda } from "./HKT.ts" -import type { Inspectable } from "./Inspectable.ts" -import * as doNotation from "./internal/doNotation.ts" -import * as option from "./internal/option.ts" -import * as result from "./internal/result.ts" -import type { Order } from "./Order.ts" -import * as order from "./Order.ts" -import type { Pipeable } from "./Pipeable.ts" -import type { Predicate, Refinement } from "./Predicate.ts" -import type { Result } from "./Result.ts" -import type { Covariant, NoInfer, NotFunction } from "./Types.ts" -import type * as Unify from "./Unify.ts" -import * as Gen from "./Utils.ts" +import type { NoSuchElementError } from "../Cause.ts" +import * as Equivalence from "../data/Equivalence.ts" +import type { Order } from "../data/Order.ts" +import * as order from "../data/Order.ts" +import type { Predicate, Refinement } from "../data/Predicate.ts" +import type { Result } from "../data/Result.ts" +import type { EffectIterator, Yieldable } from "../Effect.ts" +import type { LazyArg } from "../Function.ts" +import { constNull, constUndefined, dual, identity, isFunction } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import * as doNotation from "../internal/doNotation.ts" +import * as option from "../internal/option.ts" +import * as result from "../internal/result.ts" +import type { TypeLambda } from "../types/HKT.ts" +import type { Covariant, NoInfer, NotFunction } from "../types/Types.ts" +import type * as Unify from "../types/Unify.ts" +import * as Gen from "../Utils.ts" /** * The `Option` data type represents optional values. An `Option` can either @@ -38,7 +38,7 @@ import * as Gen from "./Utils.ts" * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // Creating an Option with a value * const someValue: Option.Option = Option.some(42) @@ -64,7 +64,7 @@ export type Option = None | Some /** * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.TypeId) * // Output: "~effect/Option" @@ -78,7 +78,7 @@ export const TypeId: TypeId = "~effect/Option" /** * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // Using TypeId for type checking * const checkTypeId = (value: unknown): value is Option.Option => { @@ -95,7 +95,7 @@ export type TypeId = "~effect/Option" /** * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const noneValue = Option.none() * @@ -123,7 +123,7 @@ export interface None extends Pipeable, Inspectable, Yieldable, /** * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const someValue = Option.some(42) * @@ -154,7 +154,8 @@ export interface Some extends Pipeable, Inspectable, Yieldable, /** * @example * ```ts - * import { Option, Unify } from "effect" + * import { Option } from "effect/data" + * import * as Unify from "effect/types/Unify" * * // Internal unification interface used by the Effect library * // for type-level operations with Option types @@ -171,7 +172,7 @@ export interface OptionUnify { /** * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // Namespace containing utility types for Option * type StringOption = Option.Option @@ -187,7 +188,7 @@ export declare namespace Option { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // Declare an Option holding a string * declare const myOption: Option.Option @@ -208,7 +209,7 @@ export declare namespace Option { /** * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // Internal interface for type unification behavior * // Used by the Effect library's type system @@ -223,7 +224,7 @@ export interface OptionUnifyIgnore {} /** * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // Type lambda interface for higher-kinded types with Option * // Used internally by the Effect library's type system @@ -246,7 +247,7 @@ export interface OptionTypeLambda extends TypeLambda { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // An Option holding no value * // @@ -270,7 +271,7 @@ export const none = (): Option => option.none * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // An Option holding the number 1 * // @@ -301,7 +302,7 @@ export const some: (value: A) => Option = option.some * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.isOption(Option.some(1))) * // Output: true @@ -323,7 +324,7 @@ export const isOption: (input: unknown) => input is Option = option.isO * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.isNone(Option.some(1))) * // Output: false @@ -344,7 +345,7 @@ export const isNone: (self: Option) => self is None = option.isNone * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.isSome(Option.some(1))) * // Output: true @@ -382,7 +383,7 @@ export const isSome: (self: Option) => self is Some = option.isSome * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const foo = Option.some(1) * @@ -434,7 +435,7 @@ export const match: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * type MyData = string | number * @@ -477,7 +478,7 @@ export const toRefinement = (f: (a: A) => Option): (a: A) => * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.fromIterable([1, 2, 3])) * // Output: { _id: 'Option', _tag: 'Some', value: 1 } @@ -516,7 +517,8 @@ export const fromIterable = (collection: Iterable): Option => { * * @example * ```ts - * import { Result, Option } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * console.log(Option.getOk(Result.succeed("ok"))) * // Output: { _id: 'Option', _tag: 'Some', value: 'ok' } @@ -550,7 +552,8 @@ export const getOk: (self: Result) => Option = result.getSuccess * * @example * ```ts - * import { Result, Option } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * console.log(Option.getErr(Result.succeed("ok"))) * // Output: { _id: 'Option', _tag: 'None' } @@ -584,7 +587,7 @@ export const getErr: (self: Result) => Option = result.getFailure * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.some(1).pipe(Option.getOrElse(() => 0))) * // Output: 1 @@ -625,7 +628,7 @@ export const getOrElse: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.none().pipe(Option.orElse(() => Option.none()))) * // Output: { _id: 'Option', _tag: 'None' } @@ -668,7 +671,7 @@ export const orElse: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.none().pipe(Option.orElseSome(() => "b"))) * // Output: { _id: 'Option', _tag: 'Some', value: 'b' } @@ -710,7 +713,8 @@ export const orElseSome: { * * @example * ```ts - * import { Option, Result } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * const primary = Option.some("primary") * const fallback = () => Option.some("fallback") @@ -756,7 +760,7 @@ export const orElseResult: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.firstSomeOf([ * Option.none(), @@ -787,7 +791,7 @@ export const firstSomeOf = > = Iterable( * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const parse = (s: string): number | undefined => { * const n = parseFloat(s) @@ -859,7 +863,7 @@ export const liftNullable = , B>( * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.getOrNull(Option.some(1))) * // Output: 1 @@ -888,7 +892,7 @@ export const getOrNull: (self: Option) => A | null = getOrElse(constNull) * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.getOrUndefined(Option.some(1))) * // Output: 1 @@ -916,7 +920,7 @@ export const getOrUndefined: (self: Option) => A | undefined = getOrElse(c * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const parse = Option.liftThrowable(JSON.parse) * @@ -956,7 +960,7 @@ export const liftThrowable = , B>( * @example * ```ts * import * as assert from "node:assert" - * import { Option } from "effect" + * import { Option } from "effect/data" * * assert.deepStrictEqual( * Option.getOrThrowWith(Option.some(1), () => new Error('Unexpected None')), @@ -994,7 +998,7 @@ export const getOrThrowWith: { * @example * ```ts * import * as assert from "node:assert" - * import { Option } from "effect" + * import { Option } from "effect/data" * * assert.deepStrictEqual(Option.getOrThrow(Option.some(1)), 1) * assert.throws(() => Option.getOrThrow(Option.none())) @@ -1023,7 +1027,7 @@ export const getOrThrow: (self: Option) => A = getOrThrowWith(() => new Er * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // Mapping over a `Some` * const someValue = Option.some(2) @@ -1064,7 +1068,7 @@ export const map: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // Replacing the value of a `Some` * const someValue = Option.some(42) @@ -1101,7 +1105,7 @@ export const as: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.asVoid(Option.some(42))) * // Output: { _id: 'Option', _tag: 'Some', value: undefined } @@ -1126,7 +1130,7 @@ export { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.void) * // Output: { _id: 'Option', _tag: 'Some', value: undefined } @@ -1161,7 +1165,7 @@ export { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * interface Address { * readonly city: string @@ -1224,7 +1228,7 @@ export const flatMap: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const maybeValue = Option.some(5) * const maybeNone = Option.none() @@ -1284,7 +1288,7 @@ export const andThen: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * interface Employee { * company?: { @@ -1342,7 +1346,7 @@ export const flatMapNullable: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const nested = Option.some(Option.some("value")) * console.log(Option.flatten(nested)) @@ -1379,7 +1383,7 @@ export const flatten: (self: Option>) => Option = flatMap(identi * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.zipRight(Option.some(1), Option.some("hello"))) * // Output: { _id: 'Option', _tag: 'Some', value: 'hello' } @@ -1416,7 +1420,7 @@ export const zipRight: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.zipLeft(Option.some("hello"), Option.some(1))) * // Output: { _id: 'Option', _tag: 'Some', value: 'hello' } @@ -1450,7 +1454,7 @@ export const zipLeft: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const parse = (s: string): Option.Option => isNaN(Number(s)) ? Option.none() : Option.some(Number(s)) * @@ -1492,7 +1496,7 @@ export const composeK: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const getInteger = (n: number) => Number.isInteger(n) ? Option.some(n) : Option.none() * @@ -1527,7 +1531,7 @@ export const tap: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.product(Option.some("hello"), Option.some(42))) * // Output: { _id: 'Option', _tag: 'Some', value: ['hello', 42] } @@ -1558,7 +1562,7 @@ export const product = (self: Option, that: Option): Option<[A, B]> * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const first = Option.some(1) * const rest = [Option.some(2), Option.some(3), Option.some(4)] @@ -1612,7 +1616,7 @@ export const productMany = ( * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const maybeName: Option.Option = Option.some("John") * const maybeAge: Option.Option = Option.some(25) @@ -1683,7 +1687,7 @@ export const all: > | Record = Option.some("John") * const maybeAge: Option.Option = Option.some(25) @@ -1724,7 +1728,7 @@ export const zipWith: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const optionalFn = Option.some((x: number) => x * 2) * const optionalValue = Option.some(5) @@ -1764,7 +1768,8 @@ export const ap: { * * @example * ```ts - * import { Option, pipe } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" * * const iterable = [Option.some(1), Option.none(), Option.some(2), Option.none()] * @@ -1806,7 +1811,7 @@ export const reduceCompact: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.toArray(Option.some(1))) * // Output: [1] @@ -1841,7 +1846,8 @@ export const toArray = (self: Option): Array => isNone(self) ? [] : [se * * @example * ```ts - * import { Option, Result } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * const parseNumber = (s: string): Result.Result => { * const n = Number(s) @@ -1881,7 +1887,7 @@ export const partitionMap: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // Transform and filter numbers * const transformEven = (n: Option.Option): Option.Option => @@ -1920,7 +1926,7 @@ export const filterMap: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const removeEmptyString = (input: Option.Option) => * Option.filter(input, (value) => value !== "") @@ -1966,9 +1972,10 @@ export const filter: { * * @example * ```ts - * import { Number, Option } from "effect" + * import { Option } from "effect/data" + * import * as N from "effect/primitives/Number" * - * const isEquivalent = Option.getEquivalence(Number.Equivalence) + * const isEquivalent = Option.getEquivalence(N.Equivalence) * * console.log(isEquivalent(Option.none(), Option.none())) * // Output: true @@ -2007,9 +2014,10 @@ export const getEquivalence = (isEquivalent: Equivalence.Equivalence): Equ * * @example * ```ts - * import { Number, Option } from "effect" + * import { Option } from "effect/data" + * import * as N from "effect/primitives/Number" * - * const order = Option.getOrder(Number.Order) + * const order = Option.getOrder(N.Order) * * console.log(order(Option.none(), Option.none())) * // Output: 0 @@ -2047,7 +2055,7 @@ export const getOrder = (O: Order): Order> => * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // A binary function to add two numbers * const add = (a: number, b: number): number => a + b @@ -2085,7 +2093,7 @@ export const lift2 = (f: (a: A, b: B) => C): { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * // Check if a number is positive * const isPositive = (n: number) => n > 0 @@ -2134,9 +2142,10 @@ export const liftPredicate: { // Note: I intentionally avoid using the NoInfer p * * @example * ```ts - * import { Number, Option } from "effect" + * import { Option } from "effect/data" + * import * as N from "effect/primitives/Number" * - * const contains = Option.containsWith(Number.Equivalence) + * const contains = Option.containsWith(N.Equivalence) * * console.log(Option.some(2).pipe(contains(2))) * // Output: true @@ -2174,7 +2183,7 @@ const _equivalence = Equal.equivalence() * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * console.log(Option.some(2).pipe(Option.contains(2))) * // Output: true @@ -2211,7 +2220,7 @@ export const contains: { * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const isEven = (n: number) => n % 2 === 0 * @@ -2257,7 +2266,8 @@ export const exists: { * @example * ```ts * import * as assert from "node:assert" - * import { Option, pipe } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" * * const result = pipe( * Option.Do, @@ -2308,7 +2318,8 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { Option, pipe } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" * * const result = pipe( * Option.Do, @@ -2344,7 +2355,8 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { Option, pipe } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" * * const result = pipe( * Option.Do, @@ -2389,7 +2401,8 @@ export const bind: { * @example * ```ts * import * as assert from "node:assert" - * import { Option, pipe } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" * * const result = pipe( * Option.Do, @@ -2420,7 +2433,7 @@ const adapter = Gen.adapter() * * @example * ```ts - * import { Option } from "effect" + * import { Option } from "effect/data" * * const maybeName: Option.Option = Option.some("John") * const maybeAge: Option.Option = Option.some(25) diff --git a/packages/effect/src/Order.ts b/packages/effect/src/data/Order.ts similarity index 94% rename from packages/effect/src/Order.ts rename to packages/effect/src/data/Order.ts index d9f8eb9618..384cff06e7 100644 --- a/packages/effect/src/Order.ts +++ b/packages/effect/src/data/Order.ts @@ -16,8 +16,8 @@ * * @since 2.0.0 */ -import { dual } from "./Function.ts" -import type { TypeLambda } from "./HKT.ts" +import { dual } from "../Function.ts" +import type { TypeLambda } from "../types/HKT.ts" /** * Represents a total ordering for values of type `A`. @@ -28,7 +28,7 @@ import type { TypeLambda } from "./HKT.ts" * * @example * ```ts - * import { Order } from "effect" + * import { Order } from "effect/data" * * // Custom order for objects by age * const byAge: Order.Order<{ name: string, age: number }> = (self, that) => { @@ -55,7 +55,7 @@ export interface Order { * * @example * ```ts - * import { Order } from "effect" + * import { Order } from "effect/data" * * // OrderTypeLambda is used internally for type-level operations * type MyOrderType = Order.OrderTypeLambda @@ -74,7 +74,7 @@ export interface OrderTypeLambda extends TypeLambda { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const byAge = Order.make<{ name: string, age: number }>((self, that) => { * if (self.age < that.age) return -1 @@ -100,7 +100,7 @@ export const make = ( * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * assert.deepStrictEqual(Order.string("apple", "banana"), -1) * assert.deepStrictEqual(Order.string("banana", "apple"), 1) @@ -118,7 +118,7 @@ export const string: Order = make((self, that) => self < that ? -1 : 1) * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * assert.deepStrictEqual(Order.number(1, 2), -1) * assert.deepStrictEqual(Order.number(2, 1), 1) @@ -136,7 +136,7 @@ export const number: Order = make((self, that) => self < that ? -1 : 1) * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * assert.deepStrictEqual(Order.boolean(false, true), -1) * assert.deepStrictEqual(Order.boolean(true, false), 1) @@ -154,7 +154,7 @@ export const boolean: Order = make((self, that) => self < that ? -1 : 1 * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * assert.deepStrictEqual(Order.bigint(1n, 2n), -1) * assert.deepStrictEqual(Order.bigint(2n, 1n), 1) @@ -172,7 +172,7 @@ export const bigint: Order = make((self, that) => self < that ? -1 : 1) * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const reverseNumber = Order.reverse(Order.number) * @@ -193,7 +193,7 @@ export const reverse = (O: Order): Order => make((self, that) => O(that * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const byAge = Order.mapInput(Order.number, (person: { name: string, age: number }) => person.age) * const byName = Order.mapInput(Order.string, (person: { name: string, age: number }) => person.name) @@ -229,7 +229,7 @@ export const combine: { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const byAge = Order.mapInput(Order.number, (person: { name: string, age: number, city: string }) => person.age) * const byName = Order.mapInput(Order.string, (person: { name: string, age: number, city: string }) => person.name) @@ -270,7 +270,7 @@ export const combineMany: { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const emptyOrder = Order.empty() * @@ -291,7 +291,7 @@ export const empty = (): Order => make(() => 0) * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const byAge = Order.mapInput(Order.number, (person: { name: string, age: number }) => person.age) * const byName = Order.mapInput(Order.string, (person: { name: string, age: number }) => person.name) @@ -316,7 +316,7 @@ export const combineAll = (collection: Iterable>): Order => combi * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const byLength = Order.mapInput(Order.number, (s: string) => s.length) * @@ -342,7 +342,7 @@ export const mapInput: { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const date1 = new Date("2023-01-01") * const date2 = new Date("2023-01-02") @@ -364,7 +364,7 @@ export const Date: Order = mapInput(number, (date) => date.getTime()) * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const tupleOrder = Order.product(Order.number, Order.string) * @@ -392,7 +392,7 @@ export const product: { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const arrayOrder = Order.all([Order.number, Order.number]) * @@ -429,7 +429,7 @@ export const all = (collection: Iterable>): Order> * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const tupleOrder = Order.productMany(Order.number, [Order.number, Order.number]) * @@ -467,7 +467,7 @@ export const productMany: { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const tupleOrder = Order.tuple([Order.number, Order.number]) * @@ -492,7 +492,7 @@ export const tuple = >>( * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const arrayOrder = Order.array(Order.number) * @@ -526,7 +526,7 @@ export const array = (O: Order): Order> => * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const personOrder = Order.struct({ * name: Order.string, @@ -566,7 +566,7 @@ export const struct = }>( * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const lessThanNumber = Order.lessThan(Order.number) * @@ -589,7 +589,7 @@ export const lessThan = (O: Order): { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const greaterThanNumber = Order.greaterThan(Order.number) * @@ -612,7 +612,7 @@ export const greaterThan = (O: Order): { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const lessThanOrEqualToNumber = Order.lessThanOrEqualTo(Order.number) * @@ -635,7 +635,7 @@ export const lessThanOrEqualTo = (O: Order): { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const greaterThanOrEqualToNumber = Order.greaterThanOrEqualTo(Order.number) * @@ -658,7 +658,7 @@ export const greaterThanOrEqualTo = (O: Order): { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const minNumber = Order.min(Order.number) * @@ -681,7 +681,7 @@ export const min = (O: Order): { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const maxNumber = Order.max(Order.number) * @@ -704,9 +704,10 @@ export const max = (O: Order): { * @example * ```ts * import * as assert from "node:assert" - * import { Order, Number } from "effect" + * import { Order } from "effect/data" + * import * as N from "effect/primitives/Number" * - * const clamp = Order.clamp(Number.Order)({ minimum: 1, maximum: 5 }) + * const clamp = Order.clamp(N.Order)({ minimum: 1, maximum: 5 }) * * assert.equal(clamp(3), 3) * assert.equal(clamp(0), 1) @@ -740,7 +741,7 @@ export const clamp = (O: Order): { * @example * ```ts * import * as assert from "node:assert" - * import { Order } from "effect" + * import { Order } from "effect/data" * * const betweenNumber = Order.between(Order.number) * diff --git a/packages/effect/src/Ordering.ts b/packages/effect/src/data/Ordering.ts similarity index 96% rename from packages/effect/src/Ordering.ts rename to packages/effect/src/data/Ordering.ts index 9b2623c965..64d5f1a7c4 100644 --- a/packages/effect/src/Ordering.ts +++ b/packages/effect/src/data/Ordering.ts @@ -25,8 +25,8 @@ * @since 2.0.0 * @category utilities */ -import type { LazyArg } from "./Function.ts" -import { dual } from "./Function.ts" +import type { LazyArg } from "../Function.ts" +import { dual } from "../Function.ts" /** * Represents the result of comparing two values. @@ -37,7 +37,7 @@ import { dual } from "./Function.ts" * * @example * ```ts - * import { Ordering } from "effect" + * import { Ordering } from "effect/data" * * // Custom comparison function * const compareNumbers = (a: number, b: number): Ordering.Ordering => { @@ -67,7 +67,7 @@ export type Ordering = -1 | 0 | 1 * * @example * ```ts - * import { Ordering } from "effect" + * import { Ordering } from "effect/data" * * // Basic reversal * console.log(Ordering.reverse(1)) // -1 (greater becomes less) @@ -103,7 +103,7 @@ export const reverse = (o: Ordering): Ordering => (o === -1 ? 1 : o === 1 ? -1 : * @example * ```ts * import * as assert from "node:assert" - * import { Ordering } from "effect" + * import { Ordering } from "effect/data" * import { constant } from "effect/Function" * * const toMessage = Ordering.match({ @@ -152,7 +152,7 @@ export const match: { * * @example * ```ts - * import { Ordering } from "effect" + * import { Ordering } from "effect/data" * * // Basic combination * console.log(Ordering.combine(-1, 1)) // -1 (first is decisive) @@ -197,7 +197,7 @@ export const combine: { * * @example * ```ts - * import { Ordering } from "effect" + * import { Ordering } from "effect/data" * * // Basic usage * const result1 = Ordering.combineMany(-1, [1, 0, -1]) // -1 (initial is decisive) @@ -259,7 +259,7 @@ export const combineMany: { * * @example * ```ts - * import { Ordering } from "effect" + * import { Ordering } from "effect/data" * * // Basic usage * console.log(Ordering.combineAll([0, 0, 1])) // 1 (first non-zero) diff --git a/packages/effect/src/Predicate.ts b/packages/effect/src/data/Predicate.ts similarity index 92% rename from packages/effect/src/Predicate.ts rename to packages/effect/src/data/Predicate.ts index bd3daf8364..36d9598144 100644 --- a/packages/effect/src/Predicate.ts +++ b/packages/effect/src/data/Predicate.ts @@ -1,9 +1,9 @@ /** * @since 2.0.0 */ -import { dual, isFunction as isFunction_ } from "./Function.ts" -import type { TypeLambda } from "./HKT.ts" -import type { TupleOf, TupleOfAtLeast } from "./Types.ts" +import { dual, isFunction as isFunction_ } from "../Function.ts" +import type { TypeLambda } from "../types/HKT.ts" +import type { TupleOf, TupleOfAtLeast } from "../types/Types.ts" /** * A `Predicate` is a function that takes a value of type `A` and returns a boolean. @@ -11,7 +11,7 @@ import type { TupleOf, TupleOfAtLeast } from "./Types.ts" * * @example * ```ts - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isPositive: Predicate.Predicate = (n) => n > 0 * const isEven: Predicate.Predicate = (n) => n % 2 === 0 @@ -35,7 +35,7 @@ export interface Predicate { * * @example * ```ts - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * // Type lambda allows Predicate to work with higher-kinded type operations * // This is used internally by the Effect ecosystem for generic abstractions @@ -60,7 +60,7 @@ export interface PredicateTypeLambda extends TypeLambda { * * @example * ```ts - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * // A refinement that narrows string to non-empty string * const isNonEmpty: Predicate.Refinement = (s): s is string => s.length > 0 @@ -88,7 +88,7 @@ export interface Refinement { * * @example * ```ts - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * // Extract the input type from a predicate * type StringPredicate = Predicate.Predicate @@ -107,7 +107,7 @@ export declare namespace Predicate { * * @example * ```ts - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * type StringPredicate = Predicate.Predicate * type InputType = Predicate.Predicate.In // string @@ -126,7 +126,7 @@ export declare namespace Predicate { * * @example * ```ts - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * // A utility type for generic predicate operations * type AnyPredicate = Predicate.Predicate.Any @@ -152,7 +152,7 @@ export declare namespace Predicate { * * @example * ```ts - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * // Extract types from a refinement * type StringFromUnknown = Predicate.Refinement @@ -172,7 +172,7 @@ export declare namespace Refinement { * * @example * ```ts - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * type StringFromUnknown = Predicate.Refinement * type InputType = Predicate.Refinement.In // unknown @@ -190,7 +190,7 @@ export declare namespace Refinement { * * @example * ```ts - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * type StringFromUnknown = Predicate.Refinement * type OutputType = Predicate.Refinement.Out // string @@ -209,7 +209,7 @@ export declare namespace Refinement { * * @example * ```ts - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * // Function that composes any refinement with a predicate * const composeRefinement = ( @@ -236,9 +236,10 @@ export declare namespace Refinement { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate, Number } from "effect" + * import { Predicate } from "effect/data" + * import * as N from "effect/primitives/Number" * - * const minLength3 = Predicate.mapInput(Number.greaterThan(2), (s: string) => s.length) + * const minLength3 = Predicate.mapInput(N.greaterThan(2), (s: string) => s.length) * * assert.deepStrictEqual(minLength3("a"), false) * assert.deepStrictEqual(minLength3("aa"), false) @@ -262,7 +263,7 @@ export const mapInput: { * @example * ```ts * import * as assert from "node:assert" - * import { isTupleOf } from "effect/Predicate" + * import { isTupleOf } from "effect/data/Predicate" * * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true); * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false); @@ -291,7 +292,7 @@ export const isTupleOf: { * @example * ```ts * import * as assert from "node:assert" - * import { isTupleOfAtLeast } from "effect/Predicate" + * import { isTupleOfAtLeast } from "effect/data/Predicate" * * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true); * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true); @@ -318,7 +319,7 @@ export const isTupleOfAtLeast: { * @example * ```ts * import * as assert from "node:assert" - * import { isTruthy } from "effect/Predicate" + * import { isTruthy } from "effect/data/Predicate" * * assert.deepStrictEqual(isTruthy(1), true) * assert.deepStrictEqual(isTruthy(0), false) @@ -336,7 +337,7 @@ export const isTruthy = (input: unknown) => !!input * @example * ```ts * import * as assert from "node:assert" - * import { isSet } from "effect/Predicate" + * import { isSet } from "effect/data/Predicate" * * assert.deepStrictEqual(isSet(new Set([1, 2])), true) * assert.deepStrictEqual(isSet(new Set()), true) @@ -356,7 +357,7 @@ export const isSet = (input: unknown): input is Set => input instanceof * @example * ```ts * import * as assert from "node:assert" - * import { isMap } from "effect/Predicate" + * import { isMap } from "effect/data/Predicate" * * assert.deepStrictEqual(isMap(new Map()), true) * assert.deepStrictEqual(isMap({}), false) @@ -375,7 +376,7 @@ export const isMap = (input: unknown): input is Map => input i * @example * ```ts * import * as assert from "node:assert" - * import { isString } from "effect/Predicate" + * import { isString } from "effect/data/Predicate" * * assert.deepStrictEqual(isString("a"), true) * @@ -393,7 +394,7 @@ export const isString = (input: unknown): input is string => typeof input === "s * @example * ```ts * import * as assert from "node:assert" - * import { isNumber } from "effect/Predicate" + * import { isNumber } from "effect/data/Predicate" * * assert.deepStrictEqual(isNumber(2), true) * @@ -411,7 +412,7 @@ export const isNumber = (input: unknown): input is number => typeof input === "n * @example * ```ts * import * as assert from "node:assert" - * import { isBoolean } from "effect/Predicate" + * import { isBoolean } from "effect/data/Predicate" * * assert.deepStrictEqual(isBoolean(true), true) * @@ -429,7 +430,7 @@ export const isBoolean = (input: unknown): input is boolean => typeof input === * @example * ```ts * import * as assert from "node:assert" - * import { isBigInt } from "effect/Predicate" + * import { isBigInt } from "effect/data/Predicate" * * assert.deepStrictEqual(isBigInt(1n), true) * @@ -447,7 +448,7 @@ export const isBigInt = (input: unknown): input is bigint => typeof input === "b * @example * ```ts * import * as assert from "node:assert" - * import { isSymbol } from "effect/Predicate" + * import { isSymbol } from "effect/data/Predicate" * * assert.deepStrictEqual(isSymbol(Symbol.for("a")), true) * @@ -469,7 +470,7 @@ export const isPropertyKey = (u: unknown): u is PropertyKey => isString(u) || is * @example * ```ts * import * as assert from "node:assert" - * import { isFunction } from "effect/Predicate" + * import { isFunction } from "effect/data/Predicate" * * assert.deepStrictEqual(isFunction(isFunction), true) * @@ -487,7 +488,7 @@ export const isFunction: (input: unknown) => input is Function = isFunction_ * @example * ```ts * import * as assert from "node:assert" - * import { isUndefined } from "effect/Predicate" + * import { isUndefined } from "effect/data/Predicate" * * assert.deepStrictEqual(isUndefined(undefined), true) * @@ -506,7 +507,7 @@ export const isUndefined = (input: unknown): input is undefined => input === und * @example * ```ts * import * as assert from "node:assert" - * import { isNotUndefined } from "effect/Predicate" + * import { isNotUndefined } from "effect/data/Predicate" * * assert.deepStrictEqual(isNotUndefined(null), true) * assert.deepStrictEqual(isNotUndefined("undefined"), true) @@ -525,7 +526,7 @@ export const isNotUndefined = (input: A): input is Exclude => i * @example * ```ts * import * as assert from "node:assert" - * import { isNull } from "effect/Predicate" + * import { isNull } from "effect/data/Predicate" * * assert.deepStrictEqual(isNull(null), true) * @@ -544,7 +545,7 @@ export const isNull = (input: unknown): input is null => input === null * @example * ```ts * import * as assert from "node:assert" - * import { isNotNull } from "effect/Predicate" + * import { isNotNull } from "effect/data/Predicate" * * assert.deepStrictEqual(isNotNull(undefined), true) * assert.deepStrictEqual(isNotNull("null"), true) @@ -563,7 +564,7 @@ export const isNotNull = (input: A): input is Exclude => input !== n * @example * ```ts * import * as assert from "node:assert" - * import { isNullish } from "effect/Predicate" + * import { isNullish } from "effect/data/Predicate" * * assert.deepStrictEqual(isNullish(null), true) * assert.deepStrictEqual(isNullish(undefined), true) @@ -584,7 +585,7 @@ export const isNullish = (input: unknown): input is null | undefined => input == * @example * ```ts * import * as assert from "node:assert" - * import { isNotNullish } from "effect/Predicate" + * import { isNotNullish } from "effect/data/Predicate" * * assert.deepStrictEqual(isNotNullish(0), true) * assert.deepStrictEqual(isNotNullish(""), true) @@ -605,7 +606,7 @@ export const isNotNullish = (input: A): input is Exclude * @example * ```ts * import * as assert from "node:assert" - * import { isNever } from "effect/Predicate" + * import { isNever } from "effect/data/Predicate" * * assert.deepStrictEqual(isNever(null), false) * assert.deepStrictEqual(isNever(undefined), false) @@ -624,7 +625,7 @@ export const isNever: (input: unknown) => input is never = (_: unknown): _ is ne * @example * ```ts * import * as assert from "node:assert" - * import { isUnknown } from "effect/Predicate" + * import { isUnknown } from "effect/data/Predicate" * * assert.deepStrictEqual(isUnknown(null), true) * assert.deepStrictEqual(isUnknown(undefined), true) @@ -648,7 +649,7 @@ export const isRecordOrArray = (input: unknown): input is { [x: PropertyKey]: un * @example * ```ts * import * as assert from "node:assert" - * import { isObject } from "effect/Predicate" + * import { isObject } from "effect/data/Predicate" * * assert.deepStrictEqual(isObject({}), true) * assert.deepStrictEqual(isObject([]), true) @@ -669,7 +670,7 @@ export const isObject = (input: unknown): input is object => isRecordOrArray(inp * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const hasName = Predicate.hasProperty("name") * const hasAge = Predicate.hasProperty("age") @@ -708,7 +709,7 @@ export const hasProperty: { * @example * ```ts * import * as assert from "node:assert" - * import { isTagged } from "effect/Predicate" + * import { isTagged } from "effect/data/Predicate" * * assert.deepStrictEqual(isTagged(1, "a"), false) * assert.deepStrictEqual(isTagged(null, "a"), false) @@ -735,7 +736,7 @@ export const isTagged: { * @example * ```ts * import * as assert from "node:assert" - * import { isNullable } from "effect/Predicate" + * import { isNullable } from "effect/data/Predicate" * * assert.deepStrictEqual(isNullable(null), true) * assert.deepStrictEqual(isNullable(undefined), true) @@ -755,7 +756,7 @@ export const isNullable = (input: A): input is Extract = * @example * ```ts * import * as assert from "node:assert" - * import { isNotNullable } from "effect/Predicate" + * import { isNotNullable } from "effect/data/Predicate" * * assert.deepStrictEqual(isNotNullable({}), true) * assert.deepStrictEqual(isNotNullable([]), true) @@ -775,7 +776,7 @@ export const isNotNullable = (input: A): input is NonNullable => input !== * @example * ```ts * import * as assert from "node:assert" - * import { isError } from "effect/Predicate" + * import { isError } from "effect/data/Predicate" * * assert.deepStrictEqual(isError(new Error()), true) * @@ -794,7 +795,7 @@ export const isError = (input: unknown): input is Error => input instanceof Erro * @example * ```ts * import * as assert from "node:assert" - * import { isUint8Array } from "effect/Predicate" + * import { isUint8Array } from "effect/data/Predicate" * * assert.deepStrictEqual(isUint8Array(new Uint8Array()), true) * @@ -813,7 +814,7 @@ export const isUint8Array = (input: unknown): input is Uint8Array => input insta * @example * ```ts * import * as assert from "node:assert" - * import { isDate } from "effect/Predicate" + * import { isDate } from "effect/data/Predicate" * * assert.deepStrictEqual(isDate(new Date()), true) * @@ -832,7 +833,7 @@ export const isDate = (input: unknown): input is Date => input instanceof Date * @example * ```ts * import * as assert from "node:assert" - * import { isIterable } from "effect/Predicate" + * import { isIterable } from "effect/data/Predicate" * * assert.deepStrictEqual(isIterable([]), true) * assert.deepStrictEqual(isIterable(new Set()), true) @@ -852,7 +853,7 @@ export const isIterable = (input: unknown): input is Iterable => hasPro * @example * ```ts * import * as assert from "node:assert" - * import { isRecord } from "effect/Predicate" + * import { isRecord } from "effect/data/Predicate" * * assert.deepStrictEqual(isRecord({}), true) * assert.deepStrictEqual(isRecord({ a: 1 }), true) @@ -876,7 +877,7 @@ export const isRecord = (input: unknown): input is { [x: string | symbol]: unkno * @example * ```ts * import * as assert from "node:assert" - * import { isReadonlyRecord } from "effect/Predicate" + * import { isReadonlyRecord } from "effect/data/Predicate" * * assert.deepStrictEqual(isReadonlyRecord({}), true) * assert.deepStrictEqual(isReadonlyRecord({ a: 1 }), true) @@ -900,7 +901,7 @@ export const isReadonlyRecord: ( * @example * ```ts * import * as assert from "node:assert" - * import { isPromise } from "effect/Predicate" + * import { isPromise } from "effect/data/Predicate" * * assert.deepStrictEqual(isPromise({}), false) * assert.deepStrictEqual(isPromise(Promise.resolve("hello")), true) @@ -920,7 +921,7 @@ export const isPromise = ( * @example * ```ts * import * as assert from "node:assert" - * import { isPromiseLike } from "effect/Predicate" + * import { isPromiseLike } from "effect/data/Predicate" * * assert.deepStrictEqual(isPromiseLike(Promise.resolve("hello")), true) * assert.deepStrictEqual(isPromiseLike({ then: () => {} }), true) @@ -942,7 +943,7 @@ export const isPromiseLike = ( * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * assert.deepStrictEqual(Predicate.isRegExp(/a/), true) * assert.deepStrictEqual(Predicate.isRegExp("a"), false) @@ -960,7 +961,7 @@ export const isRegExp = (input: unknown): input is RegExp => input instanceof Re * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isPositive = (n: number): n is number => n > 0 * const isInteger = (n: number): n is number => Number.isInteger(n) @@ -991,7 +992,7 @@ export const compose: { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isPositive = (n: number) => n > 0 * const isLongString = (s: string) => s.length > 3 @@ -1015,7 +1016,7 @@ export const product = * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isPositive = (n: number) => n > 0 * const isEven = (n: number) => n % 2 === 0 @@ -1054,7 +1055,7 @@ export const all = ( * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isPositive = (n: number) => n > 0 * const isEven = (n: number) => n % 2 === 0 @@ -1083,7 +1084,7 @@ export const productMany = ( * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isPositive = (n: number) => n > 0 * const isString = (s: unknown): s is string => typeof s === "string" @@ -1113,7 +1114,7 @@ export const tuple: { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isPositive = (n: number) => n > 0 * const isString = (s: unknown): s is string => typeof s === "string" @@ -1154,9 +1155,10 @@ export const struct: { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate, Number } from "effect" + * import { Predicate } from "effect/data" + * import * as N from "effect/primitives/Number" * - * const isPositive = Predicate.not(Number.lessThan(0)) + * const isPositive = Predicate.not(N.lessThan(0)) * * assert.deepStrictEqual(isPositive(-1), false) * assert.deepStrictEqual(isPositive(0), true) @@ -1174,9 +1176,10 @@ export const not = (self: Predicate): Predicate => (a) => !self(a) * @example * ```ts * import * as assert from "node:assert" - * import { Predicate, Number } from "effect" + * import { Predicate } from "effect/data" + * import * as N from "effect/primitives/Number" * - * const nonZero = Predicate.or(Number.lessThan(0), Number.greaterThan(0)) + * const nonZero = Predicate.or(N.lessThan(0), N.greaterThan(0)) * * assert.deepStrictEqual(nonZero(-1), true) * assert.deepStrictEqual(nonZero(0), false) @@ -1199,7 +1202,7 @@ export const or: { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const minLength = (n: number) => (s: string) => s.length >= n * const maxLength = (n: number) => (s: string) => s.length <= n @@ -1227,7 +1230,7 @@ export const and: { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isEven = (n: number) => n % 2 === 0 * const isPositive = (n: number) => n > 0 @@ -1253,7 +1256,7 @@ export const xor: { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isEven = (n: number) => n % 2 === 0 * const isDivisibleBy2 = (n: number) => n % 2 === 0 @@ -1295,7 +1298,7 @@ export const eqv: { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * type Triple = { * readonly a: number @@ -1332,7 +1335,7 @@ export const implies: { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isEven = (n: number) => n % 2 === 0 * const isPositive = (n: number) => n > 0 @@ -1361,7 +1364,7 @@ export const nor: { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isEven = (n: number) => n % 2 === 0 * const isPositive = (n: number) => n > 0 @@ -1390,7 +1393,7 @@ export const nand: { * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isPositive = (n: number) => n > 0 * const isEven = (n: number) => n % 2 === 0 @@ -1420,7 +1423,7 @@ export const every = (collection: Iterable>): Predicate => (a * @example * ```ts * import * as assert from "node:assert" - * import { Predicate } from "effect" + * import { Predicate } from "effect/data" * * const isPositive = (n: number) => n > 0 * const isEven = (n: number) => n % 2 === 0 diff --git a/packages/effect/src/Record.ts b/packages/effect/src/data/Record.ts similarity index 86% rename from packages/effect/src/Record.ts rename to packages/effect/src/data/Record.ts index 94afcef2e2..0e75cb368d 100644 --- a/packages/effect/src/Record.ts +++ b/packages/effect/src/data/Record.ts @@ -4,14 +4,14 @@ * @since 2.0.0 */ -import * as Equal from "./Equal.ts" -import type { Equivalence } from "./Equivalence.ts" -import { dual, identity } from "./Function.ts" -import type { TypeLambda } from "./HKT.ts" -import * as Option from "./Option.ts" -import type { Result } from "./Result.ts" -import * as R from "./Result.ts" -import type { NoInfer } from "./Types.ts" +import type { Equivalence } from "../data/Equivalence.ts" +import * as Option from "../data/Option.ts" +import type { Result } from "../data/Result.ts" +import * as R from "../data/Result.ts" +import { dual, identity } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import type { TypeLambda } from "../types/HKT.ts" +import type { NoInfer } from "../types/Types.ts" /** * Represents a readonly record with keys of type `K` and values of type `A`. @@ -19,7 +19,7 @@ import type { NoInfer } from "./Types.ts" * * @example * ```ts - * import * as Record from "effect/Record" + * import { Record } from "effect/data" * * // Creating a readonly record type * type UserRecord = Record.ReadonlyRecord<"name" | "age", string | number> @@ -43,7 +43,7 @@ export type ReadonlyRecord = { * * @example * ```ts - * import * as Record from "effect/Record" + * import { Record } from "effect/data" * * // Using NonLiteralKey to convert literal keys to generic types * type GenericKey = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string @@ -67,7 +67,7 @@ export declare namespace ReadonlyRecord { * * @example * ```ts - * import * as Record from "effect/Record" + * import { Record } from "effect/data" * * // For literal string keys, this becomes 'string' * type Example1 = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string @@ -88,7 +88,7 @@ export declare namespace ReadonlyRecord { * * @example * ```ts - * import * as Record from "effect/Record" + * import { Record } from "effect/data" * * // Intersection of literal keys * type Example1 = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b" @@ -111,8 +111,8 @@ export declare namespace ReadonlyRecord { * * @example * ```ts - * import * as Record from "effect/Record" - * import type { TypeLambda } from "effect/HKT" + * import { Record } from "effect/data" + * import type { TypeLambda } from "effect/types/HKT" * * // The type lambda allows records to be used as higher-kinded types * type RecordTypeLambda = Record.ReadonlyRecordTypeLambda<"key1" | "key2"> @@ -133,7 +133,7 @@ export interface ReadonlyRecordTypeLambda extends Typ * * @example * ```ts - * import * as Record from "effect/Record" + * import { Record } from "effect/data" * * // Create an empty record * const emptyRecord = Record.empty() @@ -158,10 +158,10 @@ export const empty = (): Record< * @example * ```ts * import * as assert from "node:assert" - * import { isEmptyRecord } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(isEmptyRecord({}), true); - * assert.deepStrictEqual(isEmptyRecord({ a: 3 }), false); + * assert.deepStrictEqual(Record.isEmptyRecord({}), true); + * assert.deepStrictEqual(Record.isEmptyRecord({ a: 3 }), false); * ``` * * @category guards @@ -176,10 +176,10 @@ export const isEmptyRecord = (self: Record): self is * @example * ```ts * import * as assert from "node:assert" - * import { isEmptyReadonlyRecord } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(isEmptyReadonlyRecord({}), true); - * assert.deepStrictEqual(isEmptyReadonlyRecord({ a: 3 }), false); + * assert.deepStrictEqual(Record.isEmptyReadonlyRecord({}), true); + * assert.deepStrictEqual(Record.isEmptyReadonlyRecord({ a: 3 }), false); * ``` * * @category guards @@ -196,12 +196,12 @@ export const isEmptyReadonlyRecord: ( * @example * ```ts * import * as assert from "node:assert" - * import { fromIterableWith } from "effect/Record" + * import { Record } from "effect/data" * * const input = [1, 2, 3, 4] * * assert.deepStrictEqual( - * fromIterableWith(input, a => [String(a), a * 2]), + * Record.fromIterableWith(input, a => [String(a), a * 2]), * { '1': 2, '2': 4, '3': 6, '4': 8 } * ) * ``` @@ -238,7 +238,7 @@ export const fromIterableWith: { * @example * ```ts * import * as assert from "node:assert" - * import { fromIterableBy } from "effect/Record" + * import { Record } from "effect/data" * * const users = [ * { id: "2", name: "name2" }, @@ -246,7 +246,7 @@ export const fromIterableWith: { * ] * * assert.deepStrictEqual( - * fromIterableBy(users, user => user.id), + * Record.fromIterableBy(users, user => user.id), * { * "2": { id: "2", name: "name2" }, * "1": { id: "1", name: "name1" } @@ -271,11 +271,11 @@ export const fromIterableBy = ( * @example * ```ts * import * as assert from "node:assert" - * import { fromEntries } from "effect/Record" + * import { Record } from "effect/data" * * const input: Array<[string, number]> = [["a", 1], ["b", 2]] * - * assert.deepStrictEqual(fromEntries(input), { a: 1, b: 2 }) + * assert.deepStrictEqual(Record.fromEntries(input), { a: 1, b: 2 }) * ``` * * @since 2.0.0 @@ -291,10 +291,10 @@ export const fromEntries: ( * @example * ```ts * import * as assert from "node:assert" - * import { collect } from "effect/Record" + * import { Record } from "effect/data" * * const x = { a: 1, b: 2, c: 3 } - * assert.deepStrictEqual(collect(x, (key, n) => [key, n]), [["a", 1], ["b", 2], ["c", 3]]) + * assert.deepStrictEqual(Record.collect(x, (key, n) => [key, n]), [["a", 1], ["b", 2], ["c", 3]]) * ``` * * @category conversions @@ -320,10 +320,10 @@ export const collect: { * @example * ```ts * import * as assert from "node:assert" - * import { toEntries } from "effect/Record" + * import { Record } from "effect/data" * * const x = { a: 1, b: 2, c: 3 } - * assert.deepStrictEqual(toEntries(x), [["a", 1], ["b", 2], ["c", 3]]) + * assert.deepStrictEqual(Record.toEntries(x), [["a", 1], ["b", 2], ["c", 3]]) * ``` * * @category conversions @@ -340,9 +340,9 @@ export const toEntries: (self: ReadonlyRecord) => Arr * @example * ```ts * import * as assert from "node:assert" - * import { size } from "effect/Record"; + * import { Record } from "effect/data" * - * assert.deepStrictEqual(size({ a: "a", b: 1, c: true }), 3); + * assert.deepStrictEqual(Record.size({ a: "a", b: 1, c: true }), 3); * ``` * * @category getters @@ -356,10 +356,10 @@ export const size = (self: ReadonlyRecord): number => * @example * ```ts * import * as assert from "node:assert" - * import { empty, has } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(has({ a: 1, b: 2 }, "a"), true); - * assert.deepStrictEqual(has(empty(), "c"), false); + * assert.deepStrictEqual(Record.has({ a: 1, b: 2 }, "a"), true); + * assert.deepStrictEqual(Record.has(Record.empty(), "c"), false); * ``` * * @category guards @@ -387,7 +387,8 @@ export const has: { * @example * ```ts * import * as assert from "node:assert" - * import { Record as R, Option } from "effect" + * import { Record as R } from "effect/data" + * import { Option } from "effect/data" * * const person: Record = { name: "John Doe", age: 35 } * @@ -414,7 +415,7 @@ export const get: { * @example * ```ts * import * as assert from "node:assert" - * import { Record as R } from "effect" + * import { Record as R } from "effect/data" * * const f = (x: number) => x * 2 * @@ -454,7 +455,8 @@ export const modify: { * @example * ```ts * import * as assert from "node:assert" - * import { Record as R, Option } from "effect" + * import { Record as R } from "effect/data" + * import { Option } from "effect/data" * * const f = (x: number) => x * 2 * @@ -501,7 +503,8 @@ export const modifyOption: { * @example * ```ts * import * as assert from "node:assert" - * import { Record, Option } from "effect" + * import { Record } from "effect/data" + * import { Option } from "effect/data" * * assert.deepStrictEqual( * Record.replaceOption({ a: 1, b: 2, c: 3 }, 'a', 10), @@ -539,9 +542,9 @@ export const replaceOption: { * @example * ```ts * import * as assert from "node:assert" - * import { remove } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(remove({ a: 1, b: 2 }, "a"), { b: 2 }) + * assert.deepStrictEqual(Record.remove({ a: 1, b: 2 }, "a"), { b: 2 }) * ``` * * @category utils @@ -570,7 +573,8 @@ export const remove: { * @example * ```ts * import * as assert from "node:assert" - * import { Record as R, Option } from "effect" + * import { Record as R } from "effect/data" + * import { Option } from "effect/data" * * assert.deepStrictEqual(R.pop({ a: 1, b: 2 }, "a"), Option.some([1, { b: 2 }])) * assert.deepStrictEqual(R.pop({ a: 1, b: 2 } as Record, "c"), Option.none()) @@ -599,15 +603,15 @@ export const pop: { * @example * ```ts * import * as assert from "node:assert" - * import { map } from "effect/Record" + * import { Record } from "effect/data" * * const f = (n: number) => `-${n}` * - * assert.deepStrictEqual(map({ a: 3, b: 5 }, f), { a: "-3", b: "-5" }) + * assert.deepStrictEqual(Record.map({ a: 3, b: 5 }, f), { a: "-3", b: "-5" }) * * const g = (n: number, key: string) => `${key.toUpperCase()}-${n}` * - * assert.deepStrictEqual(map({ a: 3, b: 5 }, g), { a: "A-3", b: "B-5" }) + * assert.deepStrictEqual(Record.map({ a: 3, b: 5 }, g), { a: "A-3", b: "B-5" }) * ``` * * @category mapping @@ -633,9 +637,9 @@ export const map: { * @example * ```ts * import * as assert from "node:assert" - * import { mapKeys } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(mapKeys({ a: 3, b: 5 }, (key) => key.toUpperCase()), { A: 3, B: 5 }) + * assert.deepStrictEqual(Record.mapKeys({ a: 3, b: 5 }, (key) => key.toUpperCase()), { A: 3, B: 5 }) * ``` * * @category mapping @@ -670,9 +674,9 @@ export const mapKeys: { * @example * ```ts * import * as assert from "node:assert" - * import { mapEntries } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(mapEntries({ a: 3, b: 5 }, (a, key) => [key.toUpperCase(), a + 1]), { A: 4, B: 6 }) + * assert.deepStrictEqual(Record.mapEntries({ a: 3, b: 5 }, (a, key) => [key.toUpperCase(), a + 1]), { A: 4, B: 6 }) * ``` * * @category mapping @@ -708,7 +712,8 @@ export const mapEntries: { * @example * ```ts * import * as assert from "node:assert" - * import { Record, Option } from "effect" + * import { Record } from "effect/data" + * import { Option } from "effect/data" * * const x = { a: 1, b: 2, c: 3 } * const f = (a: number, key: string) => a > 2 ? Option.some(a * 2) : Option.none() @@ -749,10 +754,10 @@ export const filterMap: { * @example * ```ts * import * as assert from "node:assert" - * import { filter } from "effect/Record" + * import { Record } from "effect/data" * * const x = { a: 1, b: 2, c: 3, d: 4 } - * assert.deepStrictEqual(filter(x, (n) => n > 2), { c: 3, d: 4 }) + * assert.deepStrictEqual(Record.filter(x, (n) => n > 2), { c: 3, d: 4 }) * ``` * * @category filtering @@ -795,7 +800,8 @@ export const filter: { * @example * ```ts * import * as assert from "node:assert" - * import { Record, Option } from "effect" + * import { Record } from "effect/data" + * import { Option } from "effect/data" * * assert.deepStrictEqual( * Record.getSomes({ a: Option.some(1), b: Option.none(), c: Option.some(2) }), @@ -818,7 +824,8 @@ export const getSomes: ( * @example * ```ts * import * as assert from "node:assert" - * import { Record, Result } from "effect" + * import { Record } from "effect/data" + * import { Result } from "effect/data" * * assert.deepStrictEqual( * Record.getErrs({ a: Result.succeed(1), b: Result.fail("err"), c: Result.succeed(2) }), @@ -849,7 +856,8 @@ export const getErrs = ( * @example * ```ts * import * as assert from "node:assert" - * import { Record, Result } from "effect" + * import { Record } from "effect/data" + * import { Result } from "effect/data" * * assert.deepStrictEqual( * Record.getOks({ a: Result.succeed(1), b: Result.fail("err"), c: Result.succeed(2) }), @@ -880,7 +888,8 @@ export const getOks = ( * @example * ```ts * import * as assert from "node:assert" - * import { Record, Result } from "effect" + * import { Record } from "effect/data" + * import { Result } from "effect/data" * * const x = { a: 1, b: 2, c: 3 } * const f = (n: number) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)) @@ -927,7 +936,8 @@ export const partitionMap: { * @example * ```ts * import * as assert from "node:assert" - * import { Record, Result } from "effect" + * import { Record } from "effect/data" + * import { Result } from "effect/data" * * assert.deepStrictEqual( * Record.separate({ a: Result.fail("e"), b: Result.succeed(1) }), @@ -948,10 +958,10 @@ export const separate: ( * @example * ```ts * import * as assert from "node:assert" - * import { partition } from "effect/Record" + * import { Record } from "effect/data" * * assert.deepStrictEqual( - * partition({ a: 1, b: 3 }, (n) => n > 2), + * Record.partition({ a: 1, b: 3 }, (n) => n > 2), * [{ a: 1 }, { b: 3 }] * ) * ``` @@ -1007,9 +1017,9 @@ export const partition: { * @example * ```ts * import * as assert from "node:assert" - * import { keys } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(keys({ a: 1, b: 2, c: 3 }), ["a", "b", "c"]) + * assert.deepStrictEqual(Record.keys({ a: 1, b: 2, c: 3 }), ["a", "b", "c"]) * ``` * * @category getters @@ -1024,9 +1034,9 @@ export const keys = (self: ReadonlyRecord): * @example * ```ts * import * as assert from "node:assert" - * import { values } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(values({ a: 1, b: 2, c: 3 }), [1, 2, 3]) + * assert.deepStrictEqual(Record.values({ a: 1, b: 2, c: 3 }), [1, 2, 3]) * ``` * * @category getters @@ -1040,10 +1050,10 @@ export const values = (self: ReadonlyRecord): Array()) + * const isSubrecord = Record.isSubrecordBy(Equal.equivalence()) * - * assert.deepStrictEqual(isSubrecord({ a: 1 } as Record, { a: 1, b: 2 }), true) - * assert.deepStrictEqual(isSubrecord({ a: 1, b: 2 }, { a: 1 } as Record), false) + * assert.deepStrictEqual(Record.isSubrecord({ a: 1 } as Record, { a: 1, b: 2 }), true) + * assert.deepStrictEqual(Record.isSubrecord({ a: 1, b: 2 }, { a: 1 } as Record), false) * ``` * * @category predicates @@ -1138,10 +1148,10 @@ export const isSubrecordBy = (equivalence: Equivalence): { * @example * ```ts * import * as assert from "node:assert" - * import { isSubrecord } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(isSubrecord({ a: 1 } as Record, { a: 1, b: 2 }), true) - * assert.deepStrictEqual(isSubrecord({ a: 1, b: 2 }, { a: 1 } as Record), false) + * assert.deepStrictEqual(Record.isSubrecord({ a: 1 } as Record, { a: 1, b: 2 }), true) + * assert.deepStrictEqual(Record.isSubrecord({ a: 1, b: 2 }, { a: 1 } as Record), false) * ``` * * @category predicates @@ -1158,10 +1168,10 @@ export const isSubrecord: { * @example * ```ts * import * as assert from "node:assert" - * import { reduce } from "effect/Record" + * import { Record } from "effect/data" * * assert.deepStrictEqual( - * reduce({ a: 1, b: 2, c: 3 }, 0, (acc, value, key) => acc + value), + * Record.reduce({ a: 1, b: 2, c: 3 }, 0, (acc, value, key) => acc + value), * 6 * ) * ``` @@ -1196,10 +1206,10 @@ export const reduce: { * @example * ```ts * import * as assert from "node:assert" - * import { every } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(every({ a: 1, b: 2 }, (n) => n > 0), true) - * assert.deepStrictEqual(every({ a: 1, b: -1 }, (n) => n > 0), false) + * assert.deepStrictEqual(Record.every({ a: 1, b: 2 }, (n) => n > 0), true) + * assert.deepStrictEqual(Record.every({ a: 1, b: -1 }, (n) => n > 0), false) * ``` * * @category predicates @@ -1236,10 +1246,10 @@ export const every: { * @example * ```ts * import * as assert from "node:assert" - * import { some } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(some({ a: 1, b: 2 }, (n) => n > 1), true) - * assert.deepStrictEqual(some({ a: 1, b: 2 }, (n) => n > 2), false) + * assert.deepStrictEqual(Record.some({ a: 1, b: 2 }, (n) => n > 1), true) + * assert.deepStrictEqual(Record.some({ a: 1, b: 2 }, (n) => n > 2), false) * ``` * * @category predicates @@ -1267,10 +1277,10 @@ export const some: { * @example * ```ts * import * as assert from "node:assert" - * import { union } from "effect/Record" + * import { Record } from "effect/data" * * assert.deepStrictEqual( - * union({ a: 1, b: 2 }, { b: 3, c: 4 }, (a, b) => a + b), + * Record.union({ a: 1, b: 2 }, { b: 3, c: 4 }, (a, b) => a + b), * { a: 1, b: 5, c: 4 } * ) * ``` @@ -1325,10 +1335,10 @@ export const union: { * @example * ```ts * import * as assert from "node:assert" - * import { intersection } from "effect/Record" + * import { Record } from "effect/data" * * assert.deepStrictEqual( - * intersection({ a: 1, b: 2 }, { b: 3, c: 4 }, (a, b) => a + b), + * Record.intersection({ a: 1, b: 2 }, { b: 3, c: 4 }, (a, b) => a + b), * { b: 5 } * ) * ``` @@ -1373,10 +1383,10 @@ export const intersection: { * @example * ```ts * import * as assert from "node:assert" - * import { difference } from "effect/Record" + * import { Record } from "effect/data" * * assert.deepStrictEqual( - * difference({ a: 1, b: 2 }, { b: 3, c: 4 }), + * Record.difference({ a: 1, b: 2 }, { b: 3, c: 4 }), * { a: 1, c: 4 } * ) * ``` @@ -1423,10 +1433,10 @@ export const difference: { * @example * ```ts * import * as assert from "node:assert" - * import { getEquivalence } from "effect/Record" - * import { Equal } from "effect" + * import { Record } from "effect/data" + * import { Equal } from "effect/interfaces" * - * const recordEquivalence = getEquivalence(Equal.equivalence()) + * const recordEquivalence = Record.getEquivalence(Equal.equivalence()) * * assert.deepStrictEqual(recordEquivalence({ a: 1, b: 2 }, { a: 1, b: 2 }), true) * assert.deepStrictEqual(recordEquivalence({ a: 1, b: 2 }, { a: 1, b: 3 }), false) @@ -1448,9 +1458,9 @@ export const getEquivalence = ( * @example * ```ts * import * as assert from "node:assert" - * import { singleton } from "effect/Record" + * import { Record } from "effect/data" * - * assert.deepStrictEqual(singleton("a", 1), { a: 1 }) + * assert.deepStrictEqual(Record.singleton("a", 1), { a: 1 }) * ``` * * @category constructors diff --git a/packages/effect/src/Redacted.ts b/packages/effect/src/data/Redacted.ts similarity index 86% rename from packages/effect/src/Redacted.ts rename to packages/effect/src/data/Redacted.ts index 55fded23eb..15e46a199f 100644 --- a/packages/effect/src/Redacted.ts +++ b/packages/effect/src/data/Redacted.ts @@ -6,19 +6,19 @@ * * @since 3.3.0 */ -import * as Equal from "./Equal.ts" -import * as Equivalence from "./Equivalence.ts" -import * as Hash from "./Hash.ts" -import { PipeInspectableProto } from "./internal/core.ts" -import { redactedRegistry } from "./internal/redacted.ts" -import type { Pipeable } from "./Pipeable.ts" -import { hasProperty } from "./Predicate.ts" -import type { Covariant } from "./Types.ts" +import * as Equivalence from "../data/Equivalence.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { PipeInspectableProto } from "../internal/core.ts" +import { redactedRegistry } from "../internal/redacted.ts" +import type { Covariant } from "../types/Types.ts" /** * @example * ```ts - * import { Redacted } from "effect" + * import { Redacted } from "effect/data" * * // The TypeId is used internally for type identification * const secret = Redacted.make("my-secret") @@ -33,7 +33,7 @@ export const TypeId: TypeId = "~effect/Redacted" /** * @example * ```ts - * import { Redacted } from "effect" + * import { Redacted } from "effect/data" * * // TypeId type represents the unique identifier for Redacted instances * type RedactedTypeId = Redacted.TypeId // "~effect/Redacted" @@ -47,7 +47,7 @@ export type TypeId = "~effect/Redacted" /** * @example * ```ts - * import { Redacted } from "effect" + * import { Redacted } from "effect/data" * * // Create a redacted value to protect sensitive information * const apiKey = Redacted.make("secret-key") @@ -66,7 +66,7 @@ export interface Redacted extends Redacted.Variance, Equal.Eq /** * @example * ```ts - * import { Redacted } from "effect" + * import { Redacted } from "effect/data" * * // Use the Redacted namespace for type-level operations * const secret = Redacted.make("my-secret") @@ -82,7 +82,7 @@ export declare namespace Redacted { /** * @example * ```ts - * import { Redacted } from "effect" + * import { Redacted } from "effect/data" * * // Variance interface ensures type safety for covariant type parameter * const stringSecret = Redacted.make("secret") @@ -103,7 +103,7 @@ export declare namespace Redacted { /** * @example * ```ts - * import { Redacted } from "effect" + * import { Redacted } from "effect/data" * * // Extract the value type from a Redacted instance * const secret = Redacted.make("my-secret") @@ -119,7 +119,7 @@ export declare namespace Redacted { /** * @example * ```ts - * import { Redacted } from "effect" + * import { Redacted } from "effect/data" * * const secret = Redacted.make("my-secret") * const plainString = "not-secret" @@ -139,7 +139,7 @@ export const isRedacted = (u: unknown): u is Redacted => hasProperty(u, * * @example * ```ts - * import { Redacted } from "effect" + * import { Redacted } from "effect/data" * * const API_KEY = Redacted.make("1234567890") * ``` @@ -188,7 +188,7 @@ const Proto = { * @example * ```ts * import * as assert from "node:assert" - * import { Redacted } from "effect" + * import { Redacted } from "effect/data" * * const API_KEY = Redacted.make("1234567890") * @@ -214,7 +214,7 @@ export const value = (self: Redacted): T => { * @example * ```ts * import * as assert from "node:assert" - * import { Redacted } from "effect" + * import { Redacted } from "effect/data" * * const API_KEY = Redacted.make("1234567890") * @@ -238,7 +238,8 @@ export const unsafeWipe = (self: Redacted): boolean => redactedRegistry.de * @example * ```ts * import * as assert from "node:assert" - * import { Redacted, Equivalence } from "effect" + * import { Equivalence } from "effect/data" + * import { Redacted } from "effect/data" * * const API_KEY1 = Redacted.make("1234567890") * const API_KEY2 = Redacted.make("1-34567890") diff --git a/packages/effect/src/Result.ts b/packages/effect/src/data/Result.ts similarity index 91% rename from packages/effect/src/Result.ts rename to packages/effect/src/data/Result.ts index 49acc440a0..b7eec6d26a 100644 --- a/packages/effect/src/Result.ts +++ b/packages/effect/src/data/Result.ts @@ -2,29 +2,29 @@ * @since 4.0.0 */ -import type { Yieldable } from "./Effect.ts" -import * as Equivalence from "./Equivalence.ts" -import type { LazyArg } from "./Function.ts" -import { constNull, constUndefined, dual, identity } from "./Function.ts" -import type { TypeLambda } from "./HKT.ts" -import type { Inspectable } from "./Inspectable.ts" -import * as doNotation from "./internal/doNotation.ts" -import * as option_ from "./internal/option.ts" -import * as result from "./internal/result.ts" -import type { Option } from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import type { Predicate, Refinement } from "./Predicate.ts" -import { isFunction } from "./Predicate.ts" -import type { Covariant, NoInfer, NotFunction } from "./Types.ts" -import type * as Unify from "./Unify.ts" -import * as Gen from "./Utils.ts" +import * as Equivalence from "../data/Equivalence.ts" +import type { Option } from "../data/Option.ts" +import type { Predicate, Refinement } from "../data/Predicate.ts" +import { isFunction } from "../data/Predicate.ts" +import type { Yieldable } from "../Effect.ts" +import type { LazyArg } from "../Function.ts" +import { constNull, constUndefined, dual, identity } from "../Function.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import * as doNotation from "../internal/doNotation.ts" +import * as option_ from "../internal/option.ts" +import * as result from "../internal/result.ts" +import type { TypeLambda } from "../types/HKT.ts" +import type { Covariant, NoInfer, NotFunction } from "../types/Types.ts" +import type * as Unify from "../types/Unify.ts" +import * as Gen from "../Utils.ts" /** * Represents a computation that can either succeed with a value of type `A` or fail with an error of type `E`. * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * // Create a successful result * const success = Result.succeed(42) @@ -49,7 +49,7 @@ export type Result = Success | Failure * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * const result = Result.succeed(42) * console.log(result[Result.TypeId]) // Access the type identifier @@ -65,7 +65,7 @@ export const TypeId: TypeId = "~effect/Result" * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * type MyResultType = Result.TypeId * // This type equals "~effect/Result" @@ -81,7 +81,7 @@ export type TypeId = "~effect/Result" * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * const failure = Result.fail("Network error") * @@ -111,7 +111,7 @@ export interface Failure extends Pipeable, Inspectable, Yieldable< * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * const success = Result.succeed(42) * @@ -141,7 +141,7 @@ export interface Success extends Pipeable, Inspectable, Yieldable< * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * // This interface helps TypeScript unify different Result types * const stringResult = Result.succeed("hello") @@ -161,7 +161,7 @@ export interface ResultUnify { * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * // This interface is used internally by the type system * // to control when Result types should not be unified @@ -178,7 +178,7 @@ export interface ResultUnifyIgnore {} * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * // This interface allows Result to work with higher-kinded type utilities * declare const resultTypeLambda: Result.ResultTypeLambda @@ -197,7 +197,7 @@ export interface ResultTypeLambda extends TypeLambda { * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * // This namespace contains type-level utilities * const stringResult = Result.succeed("hello") @@ -214,7 +214,7 @@ export declare namespace Result { * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * // This type utility extracts the failure type * const errorResult = Result.fail("error") @@ -230,7 +230,7 @@ export declare namespace Result { * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * // This type utility extracts the success type * const successResult = Result.succeed(42) @@ -248,7 +248,7 @@ export declare namespace Result { * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * const result = Result.succeed(42) * @@ -268,7 +268,7 @@ export const succeed: (right: A) => Result = result.succeed * * @example * ```ts - * import { Result } from "effect" + * import { Result } from "effect/data" * * const result = Result.fail("Something went wrong") * @@ -291,7 +291,7 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * const result = Result.void * assert.deepStrictEqual(result, Result.succeed(undefined)) @@ -311,7 +311,7 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * assert.deepStrictEqual(Result.fromNullable(1, () => 'fallback'), Result.succeed(1)) * assert.deepStrictEqual(Result.fromNullable(null, () => 'fallback'), Result.fail('fallback')) @@ -333,7 +333,8 @@ export const fromNullable: { * @example * ```ts * import * as assert from "node:assert" - * import { Result, Option } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * assert.deepStrictEqual(Result.fromOption(Option.some(1), () => 'error'), Result.succeed(1)) * assert.deepStrictEqual(Result.fromOption(Option.none(), () => 'error'), Result.fail('error')) @@ -384,7 +385,7 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * const success = Result.try(() => JSON.parse('{"name": "John"}')) * assert.deepStrictEqual(success, Result.succeed({ name: "John" })) @@ -405,7 +406,7 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * assert.deepStrictEqual(Result.isResult(Result.succeed(1)), true) * assert.deepStrictEqual(Result.isResult(Result.fail("a")), true) @@ -423,7 +424,7 @@ export const isResult: (input: unknown) => input is Result = r * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * assert.deepStrictEqual(Result.isFailure(Result.succeed(1)), false) * assert.deepStrictEqual(Result.isFailure(Result.fail("a")), true) @@ -440,7 +441,7 @@ export const isFailure: (self: Result) => self is Failure = re * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * assert.deepStrictEqual(Result.isSuccess(Result.succeed(1)), true) * assert.deepStrictEqual(Result.isSuccess(Result.fail("a")), false) @@ -457,7 +458,8 @@ export const isSuccess: (self: Result) => self is Success = re * @example * ```ts * import * as assert from "node:assert" - * import { Result, Option } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * assert.deepStrictEqual(Result.getSuccess(Result.succeed('ok')), Option.some('ok')) * assert.deepStrictEqual(Result.getSuccess(Result.fail('err')), Option.none()) @@ -474,7 +476,8 @@ export const getSuccess: (self: Result) => Option = result.getSuc * @example * ```ts * import * as assert from "node:assert" - * import { Result, Option } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * assert.deepStrictEqual(Result.getFailure(Result.succeed('ok')), Option.none()) * assert.deepStrictEqual(Result.getFailure(Result.fail('err')), Option.some('err')) @@ -491,7 +494,8 @@ export const getFailure: (self: Result) => Option = result.getFai * @example * ```ts * import * as assert from "node:assert" - * import { Result, Equivalence } from "effect" + * import { Result } from "effect/data" + * import { Equivalence } from "effect/data" * * const stringEquivalence = Equivalence.string * const numberEquivalence = Equivalence.number @@ -526,7 +530,8 @@ export const getEquivalence = ({ failure, success }: { * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const success = pipe( * Result.succeed(1), @@ -573,7 +578,8 @@ export const mapBoth: { * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const success = pipe( * Result.succeed(1), @@ -606,7 +612,8 @@ export const mapError: { * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const success = pipe( * Result.succeed(1), @@ -641,7 +648,8 @@ export const map: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, Result } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const onFailure = (strings: ReadonlyArray): string => `strings: ${strings.join(', ')}` * @@ -681,7 +689,8 @@ export const match: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, Result } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const isPositive = (n: number): boolean => n > 0 * @@ -733,7 +742,8 @@ export const liftPredicate: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, Result } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const isPositive = (n: number): boolean => n > 0 * @@ -783,7 +793,7 @@ export const filterOrFail: { * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * const success = Result.succeed(42) * assert.deepStrictEqual(Result.merge(success), 42) @@ -803,7 +813,7 @@ export const merge: (self: Result) => E | A = match({ onFailure: ide * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * assert.deepStrictEqual(Result.getOrElse(Result.succeed(1), (error) => error + "!"), 1) * assert.deepStrictEqual(Result.getOrElse(Result.fail("not a number"), (error) => error + "!"), "not a number!") @@ -827,7 +837,7 @@ export const getOrElse: { * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * assert.deepStrictEqual(Result.getOrNull(Result.succeed(1)), 1) * assert.deepStrictEqual(Result.getOrNull(Result.fail("a")), null) @@ -844,7 +854,7 @@ export const getOrNull: (self: Result) => A | null = getOrElse(const * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * assert.deepStrictEqual(Result.getOrUndefined(Result.succeed(1)), 1) * assert.deepStrictEqual(Result.getOrUndefined(Result.fail("a")), undefined) @@ -863,7 +873,7 @@ export const getOrUndefined: (self: Result) => A | undefined = getOr * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * assert.deepStrictEqual( * Result.getOrThrowWith(Result.succeed(1), () => new Error('Unexpected Err')), @@ -891,7 +901,7 @@ export const getOrThrowWith: { * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * assert.deepStrictEqual(Result.getOrThrow(Result.succeed(1)), 1) * assert.throws(() => Result.getOrThrow(Result.fail("error"))) @@ -910,7 +920,8 @@ export const getOrThrow: (self: Result) => A = getOrThrowWith(identi * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const success = pipe( * Result.succeed(1), @@ -943,7 +954,8 @@ export const orElse: { * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const parseAndDouble = (s: string) => * pipe( @@ -973,7 +985,8 @@ export const flatMap: { * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const success = pipe( * Result.succeed(1), @@ -1022,7 +1035,7 @@ export const andThen: { * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * assert.deepStrictEqual(Result.all([Result.succeed(1), Result.succeed(2)]), Result.succeed([1, 2])) * assert.deepStrictEqual(Result.all({ right: Result.succeed(1), b: Result.succeed("hello") }), Result.succeed({ right: 1, b: "hello" })) @@ -1075,7 +1088,7 @@ export const all: > | Record() * @example * ```ts * import * as assert from "node:assert" - * import { Result } from "effect" + * import { Result } from "effect/data" * * const program = Result.gen(function* () { * const a = yield* Result.succeed(1) @@ -1149,7 +1162,8 @@ export const gen: Gen.Gen> = (.. * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const result = pipe( * Result.Do, @@ -1182,7 +1196,8 @@ export const Do: Result<{}> = succeed({}) * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const result = pipe( * Result.Do, @@ -1225,7 +1240,8 @@ export const bind: { * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const result = pipe( * Result.Do, @@ -1274,7 +1290,8 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * const result = pipe( * Result.Do, @@ -1303,7 +1320,9 @@ export { * * @example * ```ts - * import { Effect, Result, Option } from "effect" + * import { Effect } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * // ┌─── Option> * // ▼ @@ -1328,7 +1347,8 @@ export const transposeOption = ( * * @example * ```ts - * import { Result, Option } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * const parseNumber = (s: string) => * isNaN(Number(s)) ? Result.fail("Invalid number") : Result.succeed(Number(s)) @@ -1365,7 +1385,8 @@ export const transposeMapOption = dual< * @example * ```ts * import * as assert from "node:assert" - * import { Result, Option } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * const result = Result.succeedNone * assert.deepStrictEqual(result, Result.succeed(Option.none())) @@ -1382,7 +1403,8 @@ export const succeedNone = succeed(option_.none) * @example * ```ts * import * as assert from "node:assert" - * import { Result, Option } from "effect" + * import { Result } from "effect/data" + * import { Option } from "effect/data" * * const result = Result.succeedSome(42) * assert.deepStrictEqual(result, Result.succeed(Option.some(42))) @@ -1399,7 +1421,8 @@ export const succeedSome = (a: A): Result, E> => succeed * @example * ```ts * import * as assert from "node:assert" - * import { Result, pipe } from "effect" + * import { pipe } from "effect" + * import { Result } from "effect/data" * * let sideEffect = 0 * const success = pipe( diff --git a/packages/effect/src/Struct.ts b/packages/effect/src/data/Struct.ts similarity index 90% rename from packages/effect/src/Struct.ts rename to packages/effect/src/data/Struct.ts index 561bf7e143..d2f08d8dfd 100644 --- a/packages/effect/src/Struct.ts +++ b/packages/effect/src/data/Struct.ts @@ -4,16 +4,16 @@ * @since 2.0.0 */ -import * as Equivalence from "./Equivalence.ts" -import { dual } from "./Function.ts" -import * as order from "./Order.ts" +import * as Equivalence from "../data/Equivalence.ts" +import * as order from "../data/Order.ts" +import { dual } from "../Function.ts" /** * A utility type that simplifies the appearance of a type by flattening intersection types. * * @example * ```ts - * import type { Struct } from "effect" + * import type { Struct } from "effect/data" * * type Original = { a: string } & { b: number } * type Simplified = Struct.Simplify @@ -30,7 +30,7 @@ export type Simplify = { [K in keyof T]: T[K] } & {} * * @example * ```ts - * import type { Struct } from "effect" + * import type { Struct } from "effect/data" * * type ReadOnly = { readonly a: string; readonly b: number } * type Mutable = Struct.Mutable @@ -47,7 +47,7 @@ export type Mutable = { -readonly [K in keyof T]: T[K] } & {} * * @example * ```ts - * import type { Struct } from "effect" + * import type { Struct } from "effect/data" * * type A = { a: string; b: number } * type B = { b: boolean; c: string } @@ -65,7 +65,8 @@ export type Merge = keyof T & keyof U extends never ? T & U : Omit(self: S): Array<(keyof S) & string> => * * @example * ```ts - * import { pipe, Struct } from "effect" + * import { pipe } from "effect" + * import { Struct } from "effect/data" * * console.log(pipe({ a: "a", b: 1, c: true }, Struct.pick(["a", "b"]))) * // { a: "a", b: 1 } @@ -133,7 +135,8 @@ export const pick: { * * @example * ```ts - * import { pipe, Struct } from "effect" + * import { pipe } from "effect" + * import { Struct } from "effect/data" * * console.log(pipe({ a: "a", b: 1, c: true }, Struct.omit(["c"]))) * // { a: "a", b: 1 } @@ -159,7 +162,8 @@ export const omit: { * * @example * ```ts - * import { pipe, Struct } from "effect" + * import { pipe } from "effect" + * import { Struct } from "effect/data" * * console.log(pipe({ a: "a", b: 1 }, Struct.merge({ b: 2, c: 3 }))) * // { a: "a", b: 2, c: 3 } @@ -191,7 +195,8 @@ type Evolved = Simplify< * * @example * ```ts - * import { pipe, Struct } from "effect" + * import { pipe } from "effect" + * import { Struct } from "effect/data" * * console.log( * pipe( @@ -229,7 +234,8 @@ type KeyEvolved = Simplify< * * @example * ```ts - * import { pipe, Struct } from "effect" + * import { pipe } from "effect" + * import { Struct } from "effect/data" * * const result = pipe( * { a: 1, b: 2 }, @@ -272,7 +278,8 @@ type EntryEvolved = { * * @example * ```ts - * import { pipe, Struct } from "effect" + * import { pipe } from "effect" + * import { Struct } from "effect/data" * * const result = pipe( * { a: 1, b: 2 }, @@ -303,7 +310,8 @@ export const evolveEntries: { * * @example * ```ts - * import { pipe, Struct } from "effect" + * import { pipe } from "effect" + * import { Struct } from "effect/data" * * const result = pipe( * { a: 1, b: 2, c: 3 }, @@ -336,11 +344,13 @@ export const renameKeys: { * * @example * ```ts - * import { Struct, String, Number } from "effect" + * import { Struct } from "effect/data" + * import * as S from "effect/primitives/String" + * import * as N from "effect/primitives/Number" * * const PersonEquivalence = Struct.getEquivalence({ - * name: String.Equivalence, - * age: Number.Equivalence + * name: S.Equivalence, + * age: N.Equivalence * }) * * console.log(PersonEquivalence({ name: "John", age: 25 }, { name: "John", age: 25 })) @@ -362,11 +372,13 @@ export const getEquivalence = Equivalence.struct * * @example * ```ts - * import { Struct, String, Number } from "effect" + * import { Struct } from "effect/data" + * import * as S from "effect/primitives/String" + * import * as N from "effect/primitives/Number" * * const PersonOrder = Struct.getOrder({ - * name: String.Order, - * age: Number.Order + * name: S.Order, + * age: N.Order * }) * * const person1 = { name: "Alice", age: 30 } @@ -386,7 +398,7 @@ export const getOrder = order.struct * * @example * ```ts - * import { Struct } from "effect" + * import { Struct } from "effect/data" * * // Lambda is used internally for type-level operations * type MyLambda = Struct.Lambda @@ -405,7 +417,7 @@ export interface Lambda { * * @example * ```ts - * import type { Struct } from "effect" + * import type { Struct } from "effect/data" * * // Applied to a concrete lambda type * type StringToNumber = Struct.Lambda & { @@ -426,7 +438,7 @@ export type Apply = (L & { readonly "~lambda.in": V })["~la * * @example * ```ts - * import { Struct } from "effect" + * import { Struct } from "effect/data" * * const toString = (n: number) => n.toString() * const lambdaFn = Struct.lambda(toString) @@ -444,7 +456,7 @@ export const lambda = any>( * * @example * ```ts - * import { Struct } from "effect" + * import { Struct } from "effect/data" * * // Used with lambda functions for type-level operations * const struct = { a: 1, b: 2, c: 3 } @@ -474,7 +486,7 @@ export const map: { * * @example * ```ts - * import { Struct } from "effect" + * import { Struct } from "effect/data" * * // Used with lambda functions for selective transformation * const struct = { a: 1, b: 2, c: 3 } @@ -513,7 +525,7 @@ export const mapPick: { * * @example * ```ts - * import { Struct } from "effect" + * import { Struct } from "effect/data" * * // Used with lambda functions for selective omission * const struct = { a: 1, b: 2, c: 3 } diff --git a/packages/effect/src/Tuple.ts b/packages/effect/src/data/Tuple.ts similarity index 90% rename from packages/effect/src/Tuple.ts rename to packages/effect/src/data/Tuple.ts index 8fe07fa37e..0bb2a266aa 100644 --- a/packages/effect/src/Tuple.ts +++ b/packages/effect/src/data/Tuple.ts @@ -3,18 +3,18 @@ * * @since 2.0.0 */ -import * as Equivalence from "./Equivalence.ts" -import { dual } from "./Function.ts" -import type { TypeLambda } from "./HKT.ts" -import * as order from "./Order.ts" -import type { Apply, Lambda } from "./Struct.ts" +import * as Equivalence from "../data/Equivalence.ts" +import * as order from "../data/Order.ts" +import type { Apply, Lambda } from "../data/Struct.ts" +import { dual } from "../Function.ts" +import type { TypeLambda } from "../types/HKT.ts" /** * A type lambda for tuples with two elements, useful for higher-kinded type operations. * * @example * ```ts - * import type { Tuple } from "effect" + * import type { Tuple } from "effect/data" * * // Used internally for type-level operations on 2-tuples * type Example = Tuple.Tuple2TypeLambda @@ -33,7 +33,7 @@ export interface Tuple2TypeLambda extends TypeLambda { * @example * ```ts * import * as assert from "node:assert" - * import { make } from "effect/Tuple" + * import { make } from "effect/data/Tuple" * * assert.deepStrictEqual(make(1, 'hello', true), [1, 'hello', true]) * ``` @@ -50,7 +50,7 @@ type Indices> = Exclude["length"], T * * @example * ```ts - * import { Tuple } from "effect" + * import { Tuple } from "effect/data" * * console.log(Tuple.get([1, true, 'hello'], 2)) * // 'hello' @@ -85,7 +85,7 @@ type PickTuple, K> = _BuildTuple * * @example * ```ts - * import { Tuple } from "effect" + * import { Tuple } from "effect/data" * * const result = Tuple.pick(["a", "b", "c", "d"], [0, 2, 3]) * console.log(result) @@ -120,7 +120,7 @@ type OmitTuple, K> = _BuildTuple(self: readonly [L, R]): L => self[0] * @example * ```ts * import * as assert from "node:assert" - * import { getSecond } from "effect/Tuple" + * import { getSecond } from "effect/data/Tuple" * * assert.deepStrictEqual(getSecond(["hello", 42]), 42) * ``` @@ -186,7 +186,7 @@ export const getSecond = (self: readonly [L, R]): R => self[1] * * @example * ```ts - * import { Tuple } from "effect" + * import { Tuple } from "effect/data" * * const result = Tuple.appendElement([1, 2], 3) * console.log(result) @@ -206,7 +206,7 @@ export const appendElement: { * * @example * ```ts - * import { Tuple } from "effect" + * import { Tuple } from "effect/data" * * const result = Tuple.appendElements([1, 2], [3, 4]) * console.log(result) @@ -239,7 +239,7 @@ type Evolved = { [I in keyof T]: I extends keyof E ? (E[I] extends (...a: * * @example * ```ts - * import { Tuple } from "effect" + * import { Tuple } from "effect/data" * * // Transform specific elements by index * const original = ["hello", 42, true] @@ -268,7 +268,7 @@ export const evolve: { * * @example * ```ts - * import { Tuple } from "effect" + * import { Tuple } from "effect/data" * * // Example demonstrates index remapping concept * const original = ["a", "b", "c"] @@ -302,7 +302,7 @@ export const renameIndices: { * * @example * ```ts - * import { Tuple } from "effect" + * import { Tuple } from "effect/data" * * // Used with lambda functions for transforming all elements * const tuple = [1, 2, 3] as const @@ -334,7 +334,7 @@ export const map: { * * @example * ```ts - * import { Tuple } from "effect" + * import { Tuple } from "effect/data" * * // Transform only elements at specified indices * const tuple = [1, 2, 3] as const @@ -374,7 +374,7 @@ export const mapPick: { * * @example * ```ts - * import { Tuple } from "effect" + * import { Tuple } from "effect/data" * * // Transform all elements except those at specified indices * const tuple = [1, 2, 3] as const @@ -415,7 +415,7 @@ export const mapOmit: { * @example * ```ts * import * as assert from "node:assert" - * import { mapBoth } from "effect/Tuple" + * import { mapBoth } from "effect/data/Tuple" * * assert.deepStrictEqual( * mapBoth(["hello", 42], { onFirst: s => s.toUpperCase(), onSecond: n => n.toString() }), @@ -452,7 +452,7 @@ export const mapBoth: { * @example * ```ts * import * as assert from "node:assert" - * import { mapFirst } from "effect/Tuple" + * import { mapFirst } from "effect/data/Tuple" * * assert.deepStrictEqual( * mapFirst(["hello", 42], s => s.toUpperCase()), @@ -474,7 +474,7 @@ export const mapFirst: { * @example * ```ts * import * as assert from "node:assert" - * import { mapSecond } from "effect/Tuple" + * import { mapSecond } from "effect/data/Tuple" * * assert.deepStrictEqual( * mapSecond(["hello", 42], n => n.toString()), @@ -496,7 +496,7 @@ export const mapSecond: { * @example * ```ts * import * as assert from "node:assert" - * import { flip } from "effect/Tuple" + * import { flip } from "effect/data/Tuple" * * assert.deepStrictEqual(flip(["hello", 42]), [42, "hello"]) * ``` @@ -511,10 +511,12 @@ export const flip = (self: readonly [L, R]): [R, L] => [self[1], self[0]] * * @example * ```ts - * import { Tuple, String, Number } from "effect" + * import { Tuple } from "effect/data" + * import * as S from "effect/primitives/String" + * import * as N from "effect/primitives/Number" * * // Creates an equivalence for tuples with string and number elements - * const equivalence = Tuple.getEquivalence([String.Equivalence, Number.Equivalence]) + * const equivalence = Tuple.getEquivalence([S.Equivalence, N.Equivalence]) * ``` * * @category Equivalence @@ -527,10 +529,12 @@ export const getEquivalence = Equivalence.tuple * * @example * ```ts - * import { Tuple, String, Number } from "effect" + * import { Tuple } from "effect/data" + * import * as S from "effect/primitives/String" + * import * as N from "effect/primitives/Number" * * // Creates an order for tuples with string and number elements - * const tupleOrder = Tuple.getOrder([String.Order, Number.Order]) + * const tupleOrder = Tuple.getOrder([S.Order, N.Order]) * ``` * * @category Ordering @@ -547,7 +551,7 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { isTupleOf } from "effect/Tuple" + * import { isTupleOf } from "effect/data/Tuple" * * assert.deepStrictEqual(isTupleOf([1, 2, 3], 3), true); * assert.deepStrictEqual(isTupleOf([1, 2, 3], 2), false); @@ -572,7 +576,7 @@ export { * @example * ```ts * import * as assert from "node:assert" - * import { isTupleOfAtLeast } from "effect/Tuple" + * import { isTupleOfAtLeast } from "effect/data/Tuple" * * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 3), true); * assert.deepStrictEqual(isTupleOfAtLeast([1, 2, 3], 2), true); diff --git a/packages/effect/src/data/index.ts b/packages/effect/src/data/index.ts new file mode 100644 index 0000000000..32c3b3fc76 --- /dev/null +++ b/packages/effect/src/data/index.ts @@ -0,0 +1,212 @@ +/** + * @since 4.0.0 + */ + +/** + * This module provides types and utility functions to create and work with branded types, + * which are TypeScript types with an added type tag to prevent accidental usage of a value in the wrong context. + * + * The `refined` and `nominal` functions are both used to create branded types in TypeScript. + * The main difference between them is that `refined` allows for validation of the data, while `nominal` does not. + * + * The `nominal` function is used to create a new branded type that has the same underlying type as the input, but with a different name. + * This is useful when you want to distinguish between two values of the same type that have different meanings. + * The `nominal` function does not perform any validation of the input data. + * + * On the other hand, the `refined` function is used to create a new branded type that has the same underlying type as the input, + * but with a different name, and it also allows for validation of the input data. + * The `refined` function takes a predicate that is used to validate the input data. + * If the input data fails the validation, a `BrandErrors` is returned, which provides information about the specific validation failure. + * + * @since 2.0.0 + */ +export * as Brand from "./Brand.ts" + +/** + * This module provides utilities for creating data types with structural equality + * semantics. Unlike regular JavaScript objects, `Data` types support value-based + * equality comparison using the `Equal` module. + * + * The main benefits of using `Data` types are: + * - **Structural equality**: Two `Data` objects are equal if their contents are equal + * - **Immutability**: `Data` types are designed to be immutable + * - **Type safety**: Constructors ensure type safety and consistency + * - **Effect integration**: Error types work seamlessly with Effect's error handling + * + * @example + * ```ts + * import { Equal } from "effect/interfaces" + * import { Data } from "effect/data" + * + * // Basic struct usage + * const person1 = Data.struct({ name: "Alice", age: 30 }) + * const person2 = Data.struct({ name: "Alice", age: 30 }) + * + * console.log(Equal.equals(person1, person2)) // true + * console.log(person1 === person2) // false (different references) + * + * // Regular objects don't have structural equality + * const obj1 = { name: "Alice", age: 30 } + * const obj2 = { name: "Alice", age: 30 } + * console.log(Equal.equals(obj1, obj2)) // false + * + * // Tagged enums for discriminated unions + * const { Success, Failure, $match } = Data.taggedEnum< + * | { _tag: "Success"; value: number } + * | { _tag: "Failure"; error: string } + * >() + * + * const result1 = Success({ value: 42 }) + * const result2 = Failure({ error: "Not found" }) + * + * // Pattern matching + * const message = $match(result1, { + * Success: ({ value }) => `Got value: ${value}`, + * Failure: ({ error }) => `Error: ${error}` + * }) + * ``` + * + * @since 2.0.0 + */ +export * as Data from "./Data.ts" + +/** + * This module provides utilities for working with equivalence relations - binary relations that are + * reflexive, symmetric, and transitive. Equivalence relations define when two values of the same type + * should be considered equivalent, which is fundamental for comparing, deduplicating, and organizing data. + * + * An equivalence relation must satisfy three properties: + * - **Reflexive**: Every value is equivalent to itself + * - **Symmetric**: If `a` is equivalent to `b`, then `b` is equivalent to `a` + * - **Transitive**: If `a` is equivalent to `b` and `b` is equivalent to `c`, then `a` is equivalent to `c` + * + * @example + * ```ts + * import { Equivalence } from "effect/data" + * import { Array } from "effect/collections" + * + * // Case-insensitive string equivalence + * const caseInsensitive = Equivalence.make((a, b) => + * a.toLowerCase() === b.toLowerCase() + * ) + * + * // Use with array deduplication + * const strings = ["Hello", "world", "HELLO", "World"] + * const deduplicated = Array.dedupeWith(strings, caseInsensitive) + * console.log(deduplicated) // ["Hello", "world"] + * + * // Product type equivalence + * interface Person { + * name: string + * age: number + * } + * + * const personEquivalence = Equivalence.struct({ + * name: caseInsensitive, + * age: Equivalence.number + * }) + * ``` + * + * @since 2.0.0 + */ +export * as Equivalence from "./Equivalence.ts" + +/** + * @since 4.0.0 + */ +export * as Filter from "./Filter.ts" + +/** + * @since 2.0.0 + */ +export * as Option from "./Option.ts" + +/** + * This module provides an implementation of the `Order` type class which is used to define a total ordering on some type `A`. + * An order is defined by a relation `<=`, which obeys the following laws: + * + * - either `x <= y` or `y <= x` (totality) + * - if `x <= y` and `y <= x`, then `x == y` (antisymmetry) + * - if `x <= y` and `y <= z`, then `x <= z` (transitivity) + * + * The truth table for compare is defined as follows: + * + * | `x <= y` | `x >= y` | Ordering | | + * | -------- | -------- | -------- | --------------------- | + * | `true` | `true` | `0` | corresponds to x == y | + * | `true` | `false` | `< 0` | corresponds to x < y | + * | `false` | `true` | `> 0` | corresponds to x > y | + * + * @since 2.0.0 + */ +export * as Order from "./Order.ts" + +/** + * @fileoverview + * The Ordering module provides utilities for working with comparison results and ordering operations. + * An Ordering represents the result of comparing two values, expressing whether the first value is + * less than (-1), equal to (0), or greater than (1) the second value. + * + * This module is fundamental for building comparison functions, sorting algorithms, and implementing + * ordered data structures. It provides composable operations for combining multiple comparison results + * and pattern matching on ordering outcomes. + * + * Key Features: + * - Type-safe representation of comparison results (-1, 0, 1) + * - Composable operations for combining multiple orderings + * - Pattern matching utilities for handling different ordering cases + * - Ordering reversal and combination functions + * - Integration with Effect's functional programming patterns + * + * Common Use Cases: + * - Implementing custom comparison functions + * - Building complex sorting criteria + * - Combining multiple comparison results + * - Creating ordered data structures + * - Pattern matching on comparison outcomes + * + * @since 2.0.0 + * @category utilities + */ +export * as Ordering from "./Ordering.ts" + +/** + * @since 2.0.0 + */ +export * as Predicate from "./Predicate.ts" + +/** + * This module provides utility functions for working with records in TypeScript. + * + * @since 2.0.0 + */ +export * as Record from "./Record.ts" + +/** + * The Redacted module provides functionality for handling sensitive information + * securely within your application. By using the `Redacted` data type, you can + * ensure that sensitive values are not accidentally exposed in logs or error + * messages. + * + * @since 3.3.0 + */ +export * as Redacted from "./Redacted.ts" + +/** + * @since 4.0.0 + */ +export * as Result from "./Result.ts" + +/** + * This module provides utility functions for working with structs in TypeScript. + * + * @since 2.0.0 + */ +export * as Struct from "./Struct.ts" + +/** + * This module provides utility functions for working with tuples in TypeScript. + * + * @since 2.0.0 + */ +export * as Tuple from "./Tuple.ts" diff --git a/packages/effect/src/data/index.ts.tpl b/packages/effect/src/data/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/data/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/Encoding.ts b/packages/effect/src/encoding/Encoding.ts similarity index 84% rename from packages/effect/src/Encoding.ts rename to packages/effect/src/encoding/Encoding.ts index a33a3b28cb..95eef5f16f 100644 --- a/packages/effect/src/Encoding.ts +++ b/packages/effect/src/encoding/Encoding.ts @@ -7,18 +7,18 @@ * * @since 2.0.0 */ -import * as Base64 from "./internal/encoding/base64.ts" -import * as Base64Url from "./internal/encoding/base64Url.ts" -import * as Common from "./internal/encoding/common.ts" -import * as Hex from "./internal/encoding/hex.ts" -import * as Result from "./Result.ts" +import * as Result from "../data/Result.ts" +import * as Base64 from "../internal/encoding/base64.ts" +import * as Base64Url from "../internal/encoding/base64Url.ts" +import * as Common from "../internal/encoding/common.ts" +import * as Hex from "../internal/encoding/hex.ts" /** * Encodes the given value into a base64 (RFC4648) `string`. * * @example * ```ts - * import { Encoding } from "effect" + * import { Encoding } from "effect/encoding" * * // Encode a string * console.log(Encoding.encodeBase64("hello")) // "aGVsbG8=" @@ -39,7 +39,8 @@ export const encodeBase64: (input: Uint8Array | string) => string = (input) => * * @example * ```ts - * import { Encoding, Result } from "effect" + * import { Encoding } from "effect/encoding" + * import { Result } from "effect/data" * * const result = Encoding.decodeBase64("SGVsbG8=") * if (Result.isSuccess(result)) { @@ -57,7 +58,8 @@ export const decodeBase64 = (str: string): Result.Result Result.map(decodeBase64(str), * * @example * ```ts - * import { Encoding } from "effect" + * import { Encoding } from "effect/encoding" * * // URL-safe base64 encoding (uses - and _ instead of + and /) * console.log(Encoding.encodeBase64Url("hello?")) // "aGVsbG8_" @@ -95,7 +97,8 @@ export const encodeBase64Url: (input: Uint8Array | string) => string = (input) = * * @example * ```ts - * import { Encoding, Result } from "effect" + * import { Encoding } from "effect/encoding" + * import { Result } from "effect/data" * * const result = Encoding.decodeBase64Url("SGVsbG8_") * if (Result.isSuccess(result)) { @@ -113,7 +116,8 @@ export const decodeBase64Url = (str: string): Result.Result Result.map(decodeBase64Url * * @example * ```ts - * import { Encoding } from "effect" + * import { Encoding } from "effect/encoding" * * // Encode a string to hex * console.log(Encoding.encodeHex("hello")) // "68656c6c6f" @@ -152,7 +156,8 @@ export const encodeHex: (input: Uint8Array | string) => string = (input) => * * @example * ```ts - * import { Encoding, Result } from "effect" + * import { Encoding } from "effect/encoding" + * import { Result } from "effect/data" * * const result = Encoding.decodeHex("48656c6c6f") * if (Result.isSuccess(result)) { @@ -170,7 +175,8 @@ export const decodeHex = (str: string): Result.Result Result.map(decodeHex(str), (_) = * * @example * ```ts - * import { Encoding } from "effect" + * import { Encoding } from "effect/encoding" * * const error = Encoding.DecodeException("invalid input") * console.log(error[Encoding.DecodeExceptionTypeId]) // Symbol present @@ -204,7 +210,7 @@ export const DecodeExceptionTypeId: unique symbol = Common.DecodeExceptionTypeId * * @example * ```ts - * import { Encoding } from "effect" + * import { Encoding } from "effect/encoding" * * type ExceptionType = Encoding.DecodeExceptionTypeId * const error = Encoding.DecodeException("invalid input") @@ -221,7 +227,8 @@ export type DecodeExceptionTypeId = typeof DecodeExceptionTypeId * * @example * ```ts - * import { Encoding, Result } from "effect" + * import { Encoding } from "effect/encoding" + * import { Result } from "effect/data" * * const result = Encoding.decodeBase64("invalid-base64") * if (Result.isFailure(result)) { @@ -247,7 +254,7 @@ export interface DecodeException { * * @example * ```ts - * import { Encoding } from "effect" + * import { Encoding } from "effect/encoding" * * const error = Encoding.DecodeException("invalid-base64", "Invalid base64 character") * console.log(error._tag) // "DecodeException" @@ -265,7 +272,7 @@ export const DecodeException: (input: string, message?: string) => DecodeExcepti * * @example * ```ts - * import { Encoding } from "effect" + * import { Encoding } from "effect/encoding" * * const error = Encoding.DecodeException("invalid input") * console.log(Encoding.isDecodeException(error)) // true diff --git a/packages/effect/src/encoding/index.ts b/packages/effect/src/encoding/index.ts new file mode 100644 index 0000000000..bcc7ff608b --- /dev/null +++ b/packages/effect/src/encoding/index.ts @@ -0,0 +1,14 @@ +/** + * @since 4.0.0 + */ + +/** + * This module provides encoding & decoding functionality for: + * + * - base64 (RFC4648) + * - base64 (URL) + * - hex + * + * @since 2.0.0 + */ +export * as Encoding from "./Encoding.ts" diff --git a/packages/effect/src/encoding/index.ts.tpl b/packages/effect/src/encoding/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/encoding/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/index.ts b/packages/effect/src/index.ts index f061e98f9d..5124b271ba 100644 --- a/packages/effect/src/index.ts +++ b/packages/effect/src/index.ts @@ -29,68 +29,6 @@ export { unsafeCoerce } from "./Function.ts" -/** - * This module provides utility functions for working with arrays in TypeScript. - * - * @since 2.0.0 - */ -export * as Array from "./Array.ts" - -/** - * This module provides utility functions and type class instances for working with the `BigDecimal` type in TypeScript. - * It includes functions for basic arithmetic operations, as well as type class instances for `Equivalence` and `Order`. - * - * A `BigDecimal` allows storing any real number to arbitrary precision; which avoids common floating point errors - * (such as 0.1 + 0.2 ≠ 0.3) at the cost of complexity. - * - * Internally, `BigDecimal` uses a `BigInt` object, paired with a 64-bit integer which determines the position of the - * decimal point. Therefore, the precision *is not* actually arbitrary, but limited to 263 decimal places. - * - * It is not recommended to convert a floating point number to a decimal directly, as the floating point representation - * may be unexpected. - * - * @since 2.0.0 - */ -export * as BigDecimal from "./BigDecimal.ts" - -/** - * This module provides utility functions and type class instances for working with the `bigint` type in TypeScript. - * It includes functions for basic arithmetic operations, as well as type class instances for - * `Equivalence` and `Order`. - * - * @since 2.0.0 - */ -export * as BigInt from "./BigInt.ts" - -/** - * This module provides utility functions and type class instances for working with the `boolean` type in TypeScript. - * It includes functions for basic boolean operations, as well as type class instances for - * `Equivalence` and `Order`. - * - * @since 2.0.0 - */ -export * as Boolean from "./Boolean.ts" - -/** - * This module provides types and utility functions to create and work with branded types, - * which are TypeScript types with an added type tag to prevent accidental usage of a value in the wrong context. - * - * The `refined` and `nominal` functions are both used to create branded types in TypeScript. - * The main difference between them is that `refined` allows for validation of the data, while `nominal` does not. - * - * The `nominal` function is used to create a new branded type that has the same underlying type as the input, but with a different name. - * This is useful when you want to distinguish between two values of the same type that have different meanings. - * The `nominal` function does not perform any validation of the input data. - * - * On the other hand, the `refined` function is used to create a new branded type that has the same underlying type as the input, - * but with a different name, and it also allows for validation of the input data. - * The `refined` function takes a predicate that is used to validate the input data. - * If the input data fails the validation, a `BrandErrors` is returned, which provides information about the specific validation failure. - * - * @since 2.0.0 - */ -export * as Brand from "./Brand.ts" - /** * This module provides utilities for working with `Cause`, a data type that represents * the different ways an `Effect` can fail. It includes structured error handling with @@ -134,447 +72,6 @@ export * as Brand from "./Brand.ts" */ export * as Cause from "./Cause.ts" -/** - * The `Channel` module provides a powerful abstraction for bi-directional communication - * and streaming operations. A `Channel` is a nexus of I/O operations that supports both - * reading and writing, forming the foundation for Effect's Stream and Sink abstractions. - * - * ## What is a Channel? - * - * A `Channel` represents: - * - **OutElem**: The type of elements the channel outputs - * - **OutErr**: The type of errors the channel can produce - * - **OutDone**: The type of the final value when the channel completes - * - **InElem**: The type of elements the channel reads - * - **InErr**: The type of errors the channel can receive - * - **InDone**: The type of the final value from upstream - * - **Env**: The environment/context required by the channel - * - * ## Key Features - * - * - **Bi-directional**: Channels can both read and write - * - **Composable**: Channels can be piped, sequenced, and concatenated - * - **Resource-safe**: Automatic cleanup and resource management - * - **Error-handling**: Built-in error propagation and handling - * - **Concurrent**: Support for concurrent operations - * - * ## Composition Patterns - * - * 1. **Piping**: Connect channels where output of one becomes input of another - * 2. **Sequencing**: Use the result of one channel to create another - * 3. **Concatenating**: Combine multiple channels into a single channel - * - * @example - * ```ts - * import { Channel, Effect } from "effect" - * - * // Simple channel that outputs numbers - * const numberChannel = Channel.succeed(42) - * - * // Transform channel that doubles values - * const doubleChannel = Channel.map(numberChannel, (n) => n * 2) - * - * // Running the channel would output: 84 - * ``` - * - * @example - * ```ts - * import { Channel, Effect } from "effect" - * - * // Channel from an array of values - * const arrayChannel = Channel.fromArray([1, 2, 3, 4, 5]) - * - * // Transform the channel by mapping over values - * const transformedChannel = Channel.map(arrayChannel, (n) => n * 2) - * - * // This channel will output: 2, 4, 6, 8, 10 - * ``` - * - * @since 2.0.0 - */ -export * as Channel from "./Channel.ts" - -/** - * The `Chunk` module provides an immutable, high-performance sequence data structure - * optimized for functional programming patterns. A `Chunk` is a persistent data structure - * that supports efficient append, prepend, and concatenation operations. - * - * ## What is a Chunk? - * - * A `Chunk` is an immutable sequence of elements of type `A` that provides: - * - **O(1) append and prepend operations** - * - **Efficient concatenation** through tree-like structure - * - **Memory efficiency** with structural sharing - * - **Rich API** with functional programming operations - * - **Type safety** with full TypeScript integration - * - * ## Key Features - * - * - **Immutable**: All operations return new chunks without modifying the original - * - **Efficient**: Optimized data structure with logarithmic complexity for most operations - * - **Functional**: Rich set of transformation and combination operators - * - **Lazy evaluation**: Many operations are deferred until needed - * - **Interoperable**: Easy conversion to/from arrays and other collections - * - * ## Performance Characteristics - * - * - **Append/Prepend**: O(1) amortized - * - **Random Access**: O(log n) - * - **Concatenation**: O(log min(m, n)) - * - **Iteration**: O(n) - * - **Memory**: Structural sharing minimizes allocation - * - * @example - * ```ts - * import { Chunk } from "effect" - * - * // Creating chunks - * const chunk1 = Chunk.fromIterable([1, 2, 3]) - * const chunk2 = Chunk.fromIterable([4, 5, 6]) - * const empty = Chunk.empty() - * - * // Combining chunks - * const combined = Chunk.appendAll(chunk1, chunk2) - * console.log(Chunk.toReadonlyArray(combined)) // [1, 2, 3, 4, 5, 6] - * ``` - * - * @example - * ```ts - * import { Chunk } from "effect" - * - * // Functional transformations - * const numbers = Chunk.range(1, 5) // [1, 2, 3, 4, 5] - * const doubled = Chunk.map(numbers, (n) => n * 2) // [2, 4, 6, 8, 10] - * const evens = Chunk.filter(doubled, (n) => n % 4 === 0) // [4, 8] - * const sum = Chunk.reduce(evens, 0, (acc, n) => acc + n) // 12 - * ``` - * - * @example - * ```ts - * import { Chunk, Effect } from "effect" - * - * // Working with Effects - * const processChunk = (chunk: Chunk.Chunk) => - * Effect.gen(function* () { - * const mapped = Chunk.map(chunk, (n) => n * 2) - * const filtered = Chunk.filter(mapped, (n) => n > 5) - * return Chunk.toReadonlyArray(filtered) - * }) - * ``` - * - * @since 2.0.0 - */ -export * as Chunk from "./Chunk.ts" - -/** - * The `Clock` module provides functionality for time-based operations in Effect applications. - * It offers precise time measurements, scheduling capabilities, and controlled time management - * for testing scenarios. - * - * The Clock service is a core component of the Effect runtime, providing: - * - Current time access in milliseconds and nanoseconds - * - Sleep operations for delaying execution - * - Time-based scheduling primitives - * - Testable time control through `TestClock` - * - * ## Key Features - * - * - **Precise timing**: Access to both millisecond and nanosecond precision - * - **Sleep operations**: Non-blocking sleep with proper interruption handling - * - **Service integration**: Seamless integration with Effect's dependency injection - * - **Testable**: Mock time control for deterministic testing - * - **Resource-safe**: Automatic cleanup of time-based resources - * - * @example - * ```ts - * import { Clock, Effect } from "effect" - * - * // Get current time in milliseconds - * const getCurrentTime = Clock.currentTimeMillis - * - * // Sleep for 1 second - * const sleep1Second = Effect.sleep("1 seconds") - * - * // Measure execution time - * const measureTime = Effect.gen(function* () { - * const start = yield* Clock.currentTimeMillis - * yield* Effect.sleep("100 millis") - * const end = yield* Clock.currentTimeMillis - * return end - start - * }) - * ``` - * - * @example - * ```ts - * import { Clock, Effect } from "effect" - * - * // Using Clock service directly - * const program = Effect.gen(function* () { - * const clock = yield* Clock.Clock - * const currentTime = yield* clock.currentTimeMillis - * console.log(`Current time: ${currentTime}`) - * - * // Sleep for 500ms - * yield* Effect.sleep("500 millis") - * - * const afterSleep = yield* clock.currentTimeMillis - * console.log(`After sleep: ${afterSleep}`) - * }) - * ``` - * - * @since 2.0.0 - */ -export * as Clock from "./Clock.ts" - -/** - * The `Console` module provides a functional interface for console operations within - * the Effect ecosystem. It offers type-safe logging, debugging, and console manipulation - * capabilities with built-in support for testing and environment isolation. - * - * ## Key Features - * - * - **Type-safe logging**: All console operations return Effects for composability - * - **Testable**: Mock console output for testing scenarios - * - **Service-based**: Integrated with Effect's dependency injection system - * - **Environment isolation**: Different console implementations per environment - * - **Rich API**: Support for all standard console methods (log, error, debug, etc.) - * - **Performance tracking**: Built-in timing and profiling capabilities - * - * ## Core Operations - * - * - **Basic logging**: `log`, `error`, `warn`, `info`, `debug` - * - **Assertions**: `assert` for conditional logging - * - **Grouping**: `group`, `groupCollapsed`, `groupEnd` for organized output - * - **Timing**: `time`, `timeEnd`, `timeLog` for performance measurement - * - **Data display**: `table`, `dir`, `dirxml` for structured data visualization - * - **Utilities**: `clear`, `count`, `countReset`, `trace` - * - * @example - * ```ts - * import { Console, Effect } from "effect" - * - * // Basic logging - * const program = Effect.gen(function* () { - * yield* Console.log("Hello, World!") - * yield* Console.error("Something went wrong") - * yield* Console.warn("This is a warning") - * yield* Console.info("Information message") - * }) - * ``` - * - * @example - * ```ts - * import { Console, Effect } from "effect" - * - * // Grouped logging with timing - * const debugProgram = Console.withGroup( - * Effect.gen(function* () { - * yield* Console.log("Step 1: Loading...") - * yield* Effect.sleep("100 millis") - * - * yield* Console.log("Step 2: Processing...") - * yield* Effect.sleep("200 millis") - * }), - * { label: "Processing Data" } - * ) - * ``` - * - * @example - * ```ts - * import { Console, Effect } from "effect" - * - * // Data visualization and debugging - * const dataProgram = Effect.gen(function* () { - * const users = [ - * { id: 1, name: "Alice", age: 30 }, - * { id: 2, name: "Bob", age: 25 } - * ] - * - * yield* Console.table(users) - * yield* Console.dir(users[0], { depth: 2 }) - * yield* Console.assert(users.length > 0, "Users array should not be empty") - * }) - * ``` - * - * @since 2.0.0 - */ -export * as Console from "./Console.ts" - -/** - * @since 2.0.0 - */ -export * as Cron from "./Cron.ts" - -/** - * This module provides utilities for creating data types with structural equality - * semantics. Unlike regular JavaScript objects, `Data` types support value-based - * equality comparison using the `Equal` module. - * - * The main benefits of using `Data` types are: - * - **Structural equality**: Two `Data` objects are equal if their contents are equal - * - **Immutability**: `Data` types are designed to be immutable - * - **Type safety**: Constructors ensure type safety and consistency - * - **Effect integration**: Error types work seamlessly with Effect's error handling - * - * @example - * ```ts - * import { Data, Equal } from "effect" - * - * // Basic struct usage - * const person1 = Data.struct({ name: "Alice", age: 30 }) - * const person2 = Data.struct({ name: "Alice", age: 30 }) - * - * console.log(Equal.equals(person1, person2)) // true - * console.log(person1 === person2) // false (different references) - * - * // Regular objects don't have structural equality - * const obj1 = { name: "Alice", age: 30 } - * const obj2 = { name: "Alice", age: 30 } - * console.log(Equal.equals(obj1, obj2)) // false - * - * // Tagged enums for discriminated unions - * const { Success, Failure, $match } = Data.taggedEnum< - * | { _tag: "Success"; value: number } - * | { _tag: "Failure"; error: string } - * >() - * - * const result1 = Success({ value: 42 }) - * const result2 = Failure({ error: "Not found" }) - * - * // Pattern matching - * const message = $match(result1, { - * Success: ({ value }) => `Got value: ${value}`, - * Failure: ({ error }) => `Error: ${error}` - * }) - * ``` - * - * @since 2.0.0 - */ -export * as Data from "./Data.ts" - -/** - * @since 3.6.0 - */ -export * as DateTime from "./DateTime.ts" - -/** - * This module provides utilities for working with `Deferred`, a powerful concurrency - * primitive that represents an asynchronous variable that can be set exactly once. - * Multiple fibers can await the same `Deferred` and will all be notified when it - * completes. - * - * A `Deferred` can be: - * - **Completed successfully** with a value of type `A` - * - **Failed** with an error of type `E` - * - **Interrupted** if the fiber setting it is interrupted - * - * Key characteristics: - * - **Single assignment**: Can only be completed once - * - **Multiple waiters**: Many fibers can await the same `Deferred` - * - **Fiber-safe**: Thread-safe operations across concurrent fibers - * - **Composable**: Works seamlessly with other Effect operations - * - * @example - * ```ts - * import { Deferred, Effect, Fiber } from "effect" - * - * // Basic usage: coordinate between fibers - * const program = Effect.gen(function* () { - * const deferred = yield* Deferred.make() - * - * // Fiber 1: waits for the value - * const waiter = yield* Effect.fork( - * Effect.gen(function* () { - * const value = yield* Deferred.await(deferred) - * console.log("Received:", value) - * return value - * }) - * ) - * - * // Fiber 2: sets the value after a delay - * const setter = yield* Effect.fork( - * Effect.gen(function* () { - * yield* Effect.sleep("1 second") - * yield* Deferred.succeed(deferred, "Hello from setter!") - * }) - * ) - * - * // Wait for both fibers - * yield* Fiber.join(waiter) - * yield* Fiber.join(setter) - * }) - * - * // Producer-consumer pattern - * const producerConsumer = Effect.gen(function* () { - * const buffer = yield* Deferred.make() - * - * const producer = Effect.gen(function* () { - * const data = [1, 2, 3, 4, 5] - * yield* Deferred.succeed(buffer, data) - * }) - * - * const consumer = Effect.gen(function* () { - * const data = yield* Deferred.await(buffer) - * return data.reduce((sum, n) => sum + n, 0) - * }) - * - * const [, result] = yield* Effect.all([producer, consumer]) - * return result // 15 - * }) - * ``` - * - * @since 2.0.0 - */ -export * as Deferred from "./Deferred.ts" - -/** - * This module provides utilities for working with durations of time. A `Duration` - * is an immutable data type that represents a span of time with high precision, - * supporting operations from nanoseconds to weeks. - * - * Durations support: - * - **High precision**: Nanosecond-level accuracy using BigInt - * - **Multiple formats**: Numbers (millis), BigInt (nanos), tuples, strings - * - **Arithmetic operations**: Add, subtract, multiply, divide - * - **Comparisons**: Equal, less than, greater than - * - **Conversions**: Between different time units - * - **Human-readable formatting**: Pretty printing and parsing - * - * @example - * ```ts - * import { Duration, Effect } from "effect" - * - * // Creating durations - * const oneSecond = Duration.seconds(1) - * const fiveMinutes = Duration.minutes(5) - * const oneHour = Duration.decode("1 hour") - * const precise = Duration.nanos(BigInt(123456789)) - * - * // Arithmetic operations - * const total = Duration.sum(Duration.sum(oneSecond, fiveMinutes), oneHour) - * const double = Duration.times(oneSecond, 2) - * const half = Duration.divide(oneSecond, 2) - * - * // Comparisons - * const isLonger = Duration.greaterThan(fiveMinutes, oneSecond) // true - * const isEqual = Duration.equals(oneSecond, Duration.millis(1000)) // true - * - * // Converting and formatting - * console.log(Duration.toMillis(oneSecond)) // 1000 - * console.log(Duration.format(fiveMinutes)) // "5m" - * - * // Using with Effects - * const program = Effect.gen(function* () { - * console.log("Starting...") - * yield* Effect.sleep(Duration.seconds(2)) - * console.log("Done!") - * }) - * ``` - * - * @since 2.0.0 - */ -export * as Duration from "./Duration.ts" - /** * The `Effect` module is the core of the Effect library, providing a powerful and expressive * way to model and compose asynchronous, concurrent, and effectful computations. @@ -599,7 +96,8 @@ export * as Duration from "./Duration.ts" * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * // Creating a simple effect * const hello = Effect.succeed("Hello, World!") @@ -645,66 +143,6 @@ export * as Duration from "./Duration.ts" */ export * as Effect from "./Effect.ts" -/** - * This module provides encoding & decoding functionality for: - * - * - base64 (RFC4648) - * - base64 (URL) - * - hex - * - * @since 2.0.0 - */ -export * as Encoding from "./Encoding.ts" - -/** - * This module provides functionality for defining and working with equality between values. - * It includes the `Equal` interface for types that can determine equality with other values - * of the same type, and utilities for comparing values. - * - * @since 2.0.0 - */ -export * as Equal from "./Equal.ts" - -/** - * This module provides utilities for working with equivalence relations - binary relations that are - * reflexive, symmetric, and transitive. Equivalence relations define when two values of the same type - * should be considered equivalent, which is fundamental for comparing, deduplicating, and organizing data. - * - * An equivalence relation must satisfy three properties: - * - **Reflexive**: Every value is equivalent to itself - * - **Symmetric**: If `a` is equivalent to `b`, then `b` is equivalent to `a` - * - **Transitive**: If `a` is equivalent to `b` and `b` is equivalent to `c`, then `a` is equivalent to `c` - * - * @example - * ```ts - * import { Equivalence, Array } from "effect" - * - * // Case-insensitive string equivalence - * const caseInsensitive = Equivalence.make((a, b) => - * a.toLowerCase() === b.toLowerCase() - * ) - * - * // Use with array deduplication - * const strings = ["Hello", "world", "HELLO", "World"] - * const deduplicated = Array.dedupeWith(strings, caseInsensitive) - * console.log(deduplicated) // ["Hello", "world"] - * - * // Product type equivalence - * interface Person { - * name: string - * age: number - * } - * - * const personEquivalence = Equivalence.struct({ - * name: caseInsensitive, - * age: Equivalence.number - * }) - * ``` - * - * @since 2.0.0 - */ -export * as Equivalence from "./Equivalence.ts" - /** * The `Exit` type represents the result of running an Effect computation. * An `Exit` can either be: @@ -718,1379 +156,11 @@ export * as Equivalence from "./Equivalence.ts" */ export * as Exit from "./Exit.ts" -/** - * This module provides a re-export of the fast-check library for property-based testing. - * Fast-check is a property-based testing framework that generates random test cases - * to validate that properties hold true for a wide range of inputs. - * - * Property-based testing is a testing methodology where you specify properties that - * should hold true for your functions, and the framework generates many random test - * cases to try to find counterexamples. - * - * @since 3.10.0 - */ -export * as FastCheck from "./FastCheck.ts" - -/** - * This module provides utilities for working with `Fiber`, the fundamental unit of - * concurrency in Effect. Fibers are lightweight, user-space threads that allow - * multiple Effects to run concurrently with structured concurrency guarantees. - * - * Key characteristics of Fibers: - * - **Lightweight**: Much lighter than OS threads, you can create millions - * - **Structured concurrency**: Parent fibers manage child fiber lifecycles - * - **Cancellation safety**: Proper resource cleanup when interrupted - * - **Cooperative**: Fibers yield control at effect boundaries - * - **Traceable**: Each fiber has an ID for debugging and monitoring - * - * Common patterns: - * - **Fork and join**: Start concurrent work and wait for results - * - **Race conditions**: Run multiple effects, take the first to complete - * - **Supervision**: Monitor and restart failed fibers - * - **Resource management**: Ensure proper cleanup on interruption - * - * @example - * ```ts - * import { Effect, Fiber, Console } from "effect" - * - * // Basic fiber operations - * const basicExample = Effect.gen(function* () { - * // Fork an effect to run concurrently - * const fiber = yield* Effect.fork( - * Effect.gen(function* () { - * yield* Effect.sleep("2 seconds") - * yield* Console.log("Background task completed") - * return "background result" - * }) - * ) - * - * // Do other work while the fiber runs - * yield* Console.log("Doing other work...") - * yield* Effect.sleep("1 second") - * - * // Wait for the fiber to complete - * const result = yield* Fiber.join(fiber) - * yield* Console.log(`Fiber result: ${result}`) - * }) - * - * // Joining multiple fibers - * const joinExample = Effect.gen(function* () { - * const task1 = Effect.delay(Effect.succeed("task1"), "1 second") - * const task2 = Effect.delay(Effect.succeed("task2"), "2 seconds") - * - * // Start both effects as fibers - * const fiber1 = yield* Effect.fork(task1) - * const fiber2 = yield* Effect.fork(task2) - * - * // Wait for both to complete - * const result1 = yield* Fiber.join(fiber1) - * const result2 = yield* Fiber.join(fiber2) - * return [result1, result2] // ["task1", "task2"] - * }) - * - * // Parallel execution with structured concurrency - * const parallelExample = Effect.gen(function* () { - * const tasks = [1, 2, 3, 4, 5].map(n => - * Effect.gen(function* () { - * yield* Effect.sleep(`${n * 100} millis`) - * return n * n - * }) - * ) - * - * // Run all tasks in parallel, wait for all to complete - * const results = yield* Effect.all(tasks, { concurrency: "unbounded" }) - * return results // [1, 4, 9, 16, 25] - * }) - * ``` - * - * @since 2.0.0 - */ -export * as Fiber from "./Fiber.ts" - -/** - * @since 2.0.0 - */ -export * as FiberHandle from "./FiberHandle.ts" - -/** - * @since 2.0.0 - */ -export * as FiberMap from "./FiberMap.ts" - -/** - * @since 2.0.0 - */ -export * as FiberSet from "./FiberSet.ts" - -/** - * @since 4.0.0 - */ -export * as Filter from "./Filter.ts" - /** * @since 2.0.0 */ export * as Function from "./Function.ts" -/** - * @since 4.0.0 - */ -export * as Graph from "./Graph.ts" - -/** - * This module provides utilities for hashing values in TypeScript. - * - * Hashing is the process of converting data into a fixed-size numeric value, - * typically used for data structures like hash tables, equality comparisons, - * and efficient data storage. - * - * @since 2.0.0 - */ -export * as Hash from "./Hash.ts" - -/** - * @since 2.0.0 - */ -export * as HashMap from "./HashMap.ts" - -/** - * @since 2.0.0 - */ -export * as HashSet from "./HashSet.ts" - -/** - * This module provides utilities for Higher-Kinded Types (HKT) in TypeScript. - * - * Higher-Kinded Types are types that take other types as parameters, similar to how - * functions take values as parameters. They enable generic programming over type - * constructors, allowing you to write code that works with any container type - * (like Array, Option, Effect, etc.) in a uniform way. - * - * The HKT system in Effect uses TypeLambdas to encode type-level functions that - * can represent complex type relationships with multiple type parameters, including - * contravariant, covariant, and invariant positions. - * - * @example - * ```ts - * import { HKT } from "effect" - * - * // Define a TypeLambda for Array - * interface ArrayTypeLambda extends HKT.TypeLambda { - * readonly type: Array - * } - * - * // Use Kind to get the concrete type - * type MyArray = HKT.Kind - * // MyArray is Array - * - * // Define a TypeClass that works with any HKT - * interface Functor extends HKT.TypeClass { - * map(fa: HKT.Kind, f: (a: A) => B): HKT.Kind - * } - * ``` - * - * @since 2.0.0 - */ -export * as HKT from "./HKT.ts" - -/** - * This module provides utilities for making values inspectable and debuggable in TypeScript. - * - * The Inspectable interface provides a standard way to implement custom string representations - * for objects, making them easier to debug and inspect. It includes support for JSON - * serialization, Node.js inspection, and safe circular reference handling. - * - * The module also includes redaction capabilities for sensitive data, allowing objects - * to provide different representations based on the current execution context. - * - * @example - * ```ts - * import { Inspectable } from "effect" - * - * class User extends Inspectable.Class { - * constructor( - * public readonly name: string, - * public readonly email: string - * ) { - * super() - * } - * - * toJSON() { - * return { - * _tag: "User", - * name: this.name, - * email: this.email - * } - * } - * } - * - * const user = new User("Alice", "alice@example.com") - * console.log(user.toString()) // Pretty printed JSON - * console.log(Inspectable.format(user)) // Same as toString() - * ``` - * - * @since 2.0.0 - */ -export * as Inspectable from "./Inspectable.ts" - -/** - * This module provides utility functions for working with Iterables in TypeScript. - * - * Iterables are objects that implement the iterator protocol, allowing them to be - * consumed with `for...of` loops, spread syntax, and other iteration constructs. - * This module provides a comprehensive set of functions for creating, transforming, - * and working with iterables in a functional programming style. - * - * Unlike arrays, iterables can be lazy and potentially infinite, making them suitable - * for stream processing and memory-efficient data manipulation. All functions in this - * module preserve the lazy nature of iterables where possible. - * - * @example - * ```ts - * import { Iterable, Option } from "effect" - * - * // Create iterables - * const numbers = Iterable.range(1, 5) - * const doubled = Iterable.map(numbers, x => x * 2) - * const filtered = Iterable.filter(doubled, x => x > 5) - * - * console.log(Array.from(filtered)) // [6, 8, 10] - * - * // Infinite iterables - * const fibonacci = Iterable.unfold([0, 1], ([a, b]) => Option.some([a, [b, a + b]])) - * const first10 = Iterable.take(fibonacci, 10) - * console.log(Array.from(first10)) // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] - * ``` - * - * @since 2.0.0 - */ -export * as Iterable from "./Iterable.ts" - -/** - * A `Layer` describes how to build one or more services in your - * application. Services can be injected into effects via - * `Effect.provideService`. Effects can require services via `Effect.service`. - * - * Layer can be thought of as recipes for producing bundles of services, given - * their dependencies (other services). - * - * Construction of services can be effectful and utilize resources that must be - * acquired and safely released when the services are done being utilized. - * - * By default layers are shared, meaning that if the same layer is used twice - * the layer will only be allocated a single time. - * - * Because of their excellent composition properties, layers are the idiomatic - * way in Effect-TS to create services that depend on other services. - * - * @since 2.0.0 - */ -export * as Layer from "./Layer.ts" - -/** - * @since 3.14.0 - * @experimental - */ -export * as LayerMap from "./LayerMap.ts" - -/** - * @since 2.0.0 - * - * The `Logger` module provides a robust and flexible logging system for Effect applications. - * It offers structured logging, multiple output formats, and seamless integration with the - * Effect runtime's tracing and context management. - * - * ## Key Features - * - * - **Structured Logging**: Built-in support for structured log messages with metadata - * - **Multiple Formats**: JSON, LogFmt, Pretty, and custom formatting options - * - **Context Integration**: Automatic capture of fiber context, spans, and annotations - * - **Batching**: Efficient log aggregation and batch processing - * - **File Output**: Direct file writing with configurable batch windows - * - **Composable**: Transform and compose loggers using functional patterns - * - * ## Basic Usage - * - * ```ts - * import { Effect, Logger } from "effect" - * - * // Basic logging - * const program = Effect.gen(function* () { - * yield* Effect.log("Application started") - * yield* Effect.logInfo("Processing user request") - * yield* Effect.logWarning("Resource limit approaching") - * yield* Effect.logError("Database connection failed") - * }) - * - * // With structured data - * const structuredLog = Effect.gen(function* () { - * yield* Effect.log("User action", { userId: 123, action: "login" }) - * yield* Effect.logInfo("Request processed", { duration: 150, statusCode: 200 }) - * }) - * ``` - * - * ## Custom Loggers - * - * ```ts - * import { Effect, Logger, LogLevel } from "effect" - * - * // Create a custom logger - * const customLogger = Logger.make((options) => { - * console.log(`[${options.logLevel}] ${options.message}`) - * }) - * - * // Use JSON format for production - * const jsonLogger = Logger.consoleJson - * - * // Pretty format for development - * const prettyLogger = Logger.consolePretty() - * - * const program = Effect.log("Hello World").pipe( - * Effect.provide(Logger.layer([jsonLogger])) - * ) - * ``` - * - * ## Multiple Loggers - * - * ```ts - * import { Effect, Logger, Layer } from "effect" - * - * // Combine multiple loggers - * const CombinedLoggerLive = Logger.layer([ - * Logger.consoleJson, - * Logger.consolePretty() - * ]) - * - * const program = Effect.log("Application event").pipe( - * Effect.provide(CombinedLoggerLive) - * ) - * ``` - * - * ## Batched Logging - * - * ```ts - * import { Effect, Logger, Duration } from "effect" - * - * const batchedLogger = Logger.batched(Logger.formatJson, { - * window: Duration.seconds(5), - * flush: (messages) => Effect.sync(() => { - * // Process batch of log messages - * console.log("Flushing", messages.length, "log entries") - * }) - * }) - * - * const program = Effect.gen(function* () { - * const logger = yield* batchedLogger - * yield* Effect.provide( - * Effect.all([ - * Effect.log("Event 1"), - * Effect.log("Event 2"), - * Effect.log("Event 3") - * ]), - * Logger.layer([logger]) - * ) - * }) - * ``` - */ -export * as Logger from "./Logger.ts" - -/** - * @since 2.0.0 - * - * The `LogLevel` module provides utilities for managing log levels in Effect applications. - * It defines a hierarchy of log levels and provides functions for comparing and filtering logs - * based on their severity. - * - * ## Log Level Hierarchy - * - * The log levels are ordered from most severe to least severe: - * - * 1. **All** - Special level that allows all messages - * 2. **Fatal** - System is unusable, immediate attention required - * 3. **Error** - Error conditions that should be investigated - * 4. **Warn** - Warning conditions that may indicate problems - * 5. **Info** - Informational messages about normal operation - * 6. **Debug** - Debug information useful during development - * 7. **Trace** - Very detailed trace information - * 8. **None** - Special level that suppresses all messages - * - * ## Basic Usage - * - * ```ts - * import { LogLevel, Effect } from "effect" - * - * // Basic log level usage - * const program = Effect.gen(function* () { - * yield* Effect.logFatal("System is shutting down") - * yield* Effect.logError("Database connection failed") - * yield* Effect.logWarning("Memory usage is high") - * yield* Effect.logInfo("User logged in") - * yield* Effect.logDebug("Processing request") - * yield* Effect.logTrace("Variable value: xyz") - * }) - * ``` - * - * ## Level Comparison - * - * ```ts - * import { LogLevel } from "effect" - * - * // Check if one level is more severe than another - * console.log(LogLevel.greaterThan("Error", "Info")) // true - * console.log(LogLevel.greaterThan("Debug", "Error")) // false - * - * // Check if level meets minimum threshold - * console.log(LogLevel.greaterThanOrEqualTo("Info", "Debug")) // true - * console.log(LogLevel.lessThan("Trace", "Info")) // true - * ``` - * - * ## Filtering by Level - * - * ```ts - * import { LogLevel, Effect, Logger } from "effect" - * - * // Create a logger that only logs Error and above - * const errorLogger = Logger.make((options) => { - * if (LogLevel.greaterThanOrEqualTo(options.logLevel, "Error")) { - * console.log(`[${options.logLevel}] ${options.message}`) - * } - * }) - * - * // Production logger - Info and above - * const productionLogger = Logger.make((options) => { - * if (LogLevel.greaterThanOrEqualTo(options.logLevel, "Info")) { - * console.log(`${options.date.toISOString()} [${options.logLevel}] ${options.message}`) - * } - * }) - * - * // Development logger - Debug and above - * const devLogger = Logger.make((options) => { - * if (LogLevel.greaterThanOrEqualTo(options.logLevel, "Debug")) { - * console.log(`[${options.logLevel}] ${options.message}`) - * } - * }) - * ``` - * - * ## Runtime Configuration - * - * ```ts - * import { LogLevel, Effect, Logger, Config } from "effect" - * - * // Configure log level from environment - * const logLevelConfig = Config.string("LOG_LEVEL").pipe( - * Config.withDefault("Info") - * ) - * - * const configurableLogger = Effect.gen(function* () { - * const minLevel = yield* logLevelConfig - * - * return Logger.make((options) => { - * if (LogLevel.greaterThanOrEqualTo(options.logLevel, minLevel)) { - * console.log(`[${options.logLevel}] ${options.message}`) - * } - * }) - * }) - * ``` - */ -export * as LogLevel from "./LogLevel.ts" - -/** - * @since 2.0.0 - */ -export * as ManagedRuntime from "./ManagedRuntime.ts" - -/** - * The `effect/match` module provides a type-safe pattern matching system for - * TypeScript. Inspired by functional programming, it simplifies conditional - * logic by replacing verbose if/else or switch statements with a structured and - * expressive API. - * - * This module supports matching against types, values, and discriminated unions - * while enforcing exhaustiveness checking to ensure all cases are handled. - * - * Although pattern matching is not yet a native JavaScript feature, - * `effect/match` offers a reliable implementation that is available today. - * - * **How Pattern Matching Works** - * - * Pattern matching follows a structured process: - * - * - **Creating a matcher**: Define a `Matcher` that operates on either a - * specific `Match.type` or `Match.value`. - * - * - **Defining patterns**: Use combinators such as `Match.when`, `Match.not`, - * and `Match.tag` to specify matching conditions. - * - * - **Completing the match**: Apply a finalizer such as `Match.exhaustive`, - * `Match.orElse`, or `Match.option` to determine how unmatched cases should - * be handled. - * - * @since 4.0.0 - */ -export * as Match from "./Match.ts" - -/** - * @since 2.0.0 - * - * The `Metric` module provides a comprehensive system for collecting, aggregating, and observing - * application metrics in Effect applications. It offers type-safe, concurrent metrics that can - * be used to monitor performance, track business metrics, and gain insights into application behavior. - * - * ## Key Features - * - * - **Five Metric Types**: Counters, Gauges, Frequencies, Histograms, and Summaries - * - **Type Safety**: Fully typed metrics with compile-time guarantees - * - **Concurrency Safe**: Thread-safe metrics that work with Effect's concurrency model - * - **Attributes**: Tag metrics with key-value attributes for filtering and grouping - * - **Snapshots**: Take point-in-time snapshots of all metrics for reporting - * - **Runtime Integration**: Automatic fiber runtime metrics collection - * - * ## Metric Types - * - * ### Counter - * Tracks cumulative values that only increase or can be reset to zero. - * Perfect for counting events, requests, errors, etc. - * - * ### Gauge - * Represents a single numerical value that can go up or down. - * Ideal for current resource usage, temperature, queue sizes, etc. - * - * ### Frequency - * Counts occurrences of discrete string values. - * Useful for tracking categorical data like HTTP status codes, user actions, etc. - * - * ### Histogram - * Records observations in configurable buckets to analyze distribution. - * Great for response times, request sizes, and other measured values. - * - * ### Summary - * Calculates quantiles over a sliding time window. - * Provides statistical insights into value distributions over time. - * - * ## Basic Usage - * - * ```ts - * import { Effect, Metric } from "effect" - * - * // Create metrics - * const requestCount = Metric.counter("http_requests_total", { - * description: "Total number of HTTP requests" - * }) - * - * const responseTime = Metric.histogram("http_response_time", { - * description: "HTTP response time in milliseconds", - * boundaries: Metric.linearBoundaries({ start: 0, width: 50, count: 20 }) - * }) - * - * // Use metrics in your application - * const handleRequest = Effect.gen(function* () { - * yield* Metric.update(requestCount, 1) - * - * const startTime = yield* Effect.clockWith(clock => clock.currentTimeMillis) - * - * // Process request... - * yield* Effect.sleep("100 millis") - * - * const endTime = yield* Effect.clockWith(clock => clock.currentTimeMillis) - * yield* Metric.update(responseTime, endTime - startTime) - * }) - * ``` - * - * ## Attributes and Tagging - * - * ```ts - * import { Effect, Metric } from "effect" - * - * const requestCount = Metric.counter("requests", { - * description: "Number of requests by endpoint and method" - * }) - * - * const program = Effect.gen(function* () { - * // Add attributes to metrics - * yield* Metric.update( - * Metric.withAttributes(requestCount, { - * endpoint: "/api/users", - * method: "GET" - * }), - * 1 - * ) - * - * // Or use withAttributes for compile-time attributes - * const taggedCounter = Metric.withAttributes(requestCount, { - * endpoint: "/api/posts", - * method: "POST" - * }) - * yield* Metric.update(taggedCounter, 1) - * }) - * ``` - * - * ## Advanced Examples - * - * ```ts - * import { Effect, Metric, Schedule } from "effect" - * - * // Business metrics - * const userSignups = Metric.counter("user_signups_total") - * const activeUsers = Metric.gauge("active_users_current") - * const featureUsage = Metric.frequency("feature_usage") - * - * // Performance metrics - * const dbQueryTime = Metric.summary("db_query_duration", { - * maxAge: "5 minutes", - * maxSize: 1000, - * quantiles: [0.5, 0.9, 0.95, 0.99] - * }) - * - * const program = Effect.gen(function* () { - * // Track user signup - * yield* Metric.update(userSignups, 1) - * - * // Update active user count - * yield* Metric.update(activeUsers, 1250) - * - * // Record feature usage - * yield* Metric.update(featureUsage, "dashboard_view") - * - * // Measure database query time - * yield* Effect.timed(performDatabaseQuery).pipe( - * Effect.tap(([duration]) => Metric.update(dbQueryTime, duration)) - * ) - * }) - * - * // Get metric snapshots - * const getMetrics = Effect.gen(function* () { - * const snapshots = yield* Metric.snapshot - * - * for (const metric of snapshots) { - * console.log(`${metric.id}: ${JSON.stringify(metric.state)}`) - * } - * }) - * ``` - */ -export * as Metric from "./Metric.ts" - -/** - * @fileoverview - * MutableHashMap is a high-performance, mutable hash map implementation designed for efficient key-value storage - * with support for both structural and referential equality. It provides O(1) average-case performance for - * basic operations and integrates seamlessly with Effect's Equal and Hash interfaces. - * - * The implementation uses a hybrid approach: - * - Referential keys (without Equal implementation) are stored in a native Map - * - Structural keys (with Equal implementation) are stored in hash buckets with collision handling - * - * Key Features: - * - Mutable operations for performance-critical scenarios - * - Supports both structural and referential equality - * - Efficient collision handling through bucketing - * - Iterable interface for easy traversal - * - Memory-efficient storage with automatic bucket management - * - * Performance Characteristics: - * - Get/Set/Has: O(1) average, O(n) worst case (hash collisions) - * - Remove: O(1) average, O(n) worst case - * - Clear: O(1) - * - Size: O(1) - * - Iteration: O(n) - * - * @since 2.0.0 - * @category data-structures - */ -export * as MutableHashMap from "./MutableHashMap.ts" - -/** - * @fileoverview - * MutableHashSet is a high-performance, mutable set implementation that provides efficient storage - * and retrieval of unique values. Built on top of MutableHashMap, it inherits the same performance - * characteristics and support for both structural and referential equality. - * - * The implementation uses a MutableHashMap internally where each value is stored as a key with a - * boolean flag, providing O(1) average-case performance for all operations. - * - * Key Features: - * - Mutable operations for performance-critical scenarios - * - Supports both structural and referential equality - * - Efficient duplicate detection and removal - * - Iterable interface for easy traversal - * - Memory-efficient storage with automatic deduplication - * - Seamless integration with Effect's Equal and Hash interfaces - * - * Performance Characteristics: - * - Add/Has/Remove: O(1) average, O(n) worst case (hash collisions) - * - Clear: O(1) - * - Size: O(1) - * - Iteration: O(n) - * - * @since 2.0.0 - * @category data-structures - */ -export * as MutableHashSet from "./MutableHashSet.ts" - -/** - * @fileoverview - * MutableList is an efficient, mutable linked list implementation optimized for high-throughput - * scenarios like logging, queuing, and streaming. It uses a bucket-based architecture where - * elements are stored in arrays (buckets) linked together, providing optimal performance for - * both append and prepend operations. - * - * The implementation uses a sophisticated bucket system: - * - Each bucket contains an array of elements with an offset pointer - * - Buckets can be marked as mutable or immutable for optimization - * - Elements are taken from the head and added to the tail - * - Memory is efficiently managed through bucket reuse and cleanup - * - * Key Features: - * - Highly optimized for high-frequency append/prepend operations - * - Memory efficient with automatic cleanup of consumed elements - * - Support for bulk operations (appendAll, prependAll, takeN) - * - Filtering and removal operations - * - Zero-copy optimizations for certain scenarios - * - * Performance Characteristics: - * - Append/Prepend: O(1) amortized - * - Take/TakeN: O(1) per element taken - * - Length: O(1) - * - Clear: O(1) - * - Filter: O(n) - * - * Ideal Use Cases: - * - High-throughput logging systems - * - Producer-consumer queues - * - Streaming data buffers - * - Real-time data processing pipelines - * - * @since 4.0.0 - * @category data-structures - */ -export * as MutableList from "./MutableList.ts" - -/** - * @fileoverview - * MutableRef provides a mutable reference container that allows safe mutation of values - * in functional programming contexts. It serves as a bridge between functional and imperative - * programming paradigms, offering atomic operations for state management. - * - * Unlike regular variables, MutableRef encapsulates mutable state and provides controlled - * access through a standardized API. It supports atomic compare-and-set operations for - * thread-safe updates and integrates seamlessly with Effect's ecosystem. - * - * Key Features: - * - Mutable reference semantics with functional API - * - Atomic compare-and-set operations for safe concurrent updates - * - Specialized operations for numeric and boolean values - * - Chainable operations that return the reference or the value - * - Integration with Effect's Equal interface for value comparison - * - * Common Use Cases: - * - State containers in functional applications - * - Counters and accumulators - * - Configuration that needs to be updated at runtime - * - Caching and memoization scenarios - * - Inter-module communication via shared references - * - * Performance Characteristics: - * - Get/Set: O(1) - * - Compare-and-set: O(1) - * - All operations: O(1) - * - * @since 2.0.0 - * @category data-structures - */ -export * as MutableRef from "./MutableRef.ts" - -/** - * @since 2.0.0 - * - * The `NonEmptyIterable` module provides types and utilities for working with iterables - * that are guaranteed to contain at least one element. This provides compile-time - * safety when working with collections that must not be empty. - * - * ## Key Features - * - * - **Type Safety**: Compile-time guarantee that the iterable contains at least one element - * - **Iterator Protocol**: Fully compatible with JavaScript's built-in iteration protocol - * - **Functional Operations**: Safe operations that preserve the non-empty property - * - **Lightweight**: Minimal overhead with maximum type safety - * - * ## Why NonEmptyIterable? - * - * Many operations require non-empty collections to be meaningful: - * - Finding the maximum or minimum value - * - Getting the first or last element - * - Reducing without an initial value - * - Operations that would otherwise need runtime checks - * - * ## Basic Usage - * - * ```ts - * import { NonEmptyIterable } from "effect" - * - * // NonEmptyIterable is a type that represents any iterable with at least one element - * function processNonEmpty(data: NonEmptyIterable.NonEmptyIterable): A { - * // Safe to get the first element - guaranteed to exist - * const [first] = NonEmptyIterable.unprepend(data) - * return first - * } - * - * // Using Array.make to create non-empty arrays - * const numbers = Array.make(1, 2, 3, 4, 5) as unknown as NonEmptyIterable.NonEmptyIterable - * const firstNumber = processNonEmpty(numbers) // number - * - * // Regular arrays can be asserted as NonEmptyIterable when known to be non-empty - * const values = [1, 2, 3] as unknown as NonEmptyIterable.NonEmptyIterable - * const firstValue = processNonEmpty(values) // number - * - * // Custom iterables that are guaranteed non-empty - * function* generateNumbers(): NonEmptyIterable.NonEmptyIterable { - * yield 1 - * yield 2 - * yield 3 - * } - * - * const firstGenerated = processNonEmpty(generateNumbers()) // number - * ``` - * - * ## Working with Different Iterable Types - * - * ```ts - * import { NonEmptyIterable, Array, Chunk, pipe } from "effect" - * - * // Creating non-empty arrays - * const nonEmptyArray = Array.make(1, 2, 3) as unknown as NonEmptyIterable.NonEmptyIterable - * - * // Working with strings (assert as NonEmptyIterable when known to be non-empty) - * const nonEmptyString = "hello" as unknown as NonEmptyIterable.NonEmptyIterable - * const [firstChar] = NonEmptyIterable.unprepend(nonEmptyString) - * console.log(firstChar) // "h" - * - * // Working with Maps (assert when known to be non-empty) - * const nonEmptyMap = new Map([ - * ["key1", "value1"], - * ["key2", "value2"] - * ]) as unknown as NonEmptyIterable.NonEmptyIterable<[string, string]> - * const [firstEntry] = NonEmptyIterable.unprepend(nonEmptyMap) - * console.log(firstEntry) // ["key1", "value1"] - * - * // Custom generator functions - * function* fibonacci(): NonEmptyIterable.NonEmptyIterable { - * let a = 1, b = 1 - * yield a - * while (true) { - * yield b - * const next = a + b - * a = b - * b = next - * } - * } - * - * const [firstFib, restFib] = NonEmptyIterable.unprepend(fibonacci() as unknown as NonEmptyIterable.NonEmptyIterable) - * console.log(firstFib) // 1 - * ``` - * - * ## Integration with Effect Arrays - * - * ```ts - * import { NonEmptyIterable, Array, Chunk, pipe } from "effect" - * - * // Many Array functions work with NonEmptyIterable - * declare const nonEmptyData: NonEmptyIterable.NonEmptyIterable - * - * const processData = pipe( - * nonEmptyData, - * Array.fromIterable, - * Array.map(x => x * 2), - * Array.filter(x => x > 5), - * // Result is a regular array since filtering might make it empty - * ) - * - * // Safe operations that preserve non-emptiness - * const doubledData = pipe( - * nonEmptyData, - * Array.fromIterable, - * Array.map(x => x * 2) - * // This would still be non-empty if the source was non-empty - * ) - * ``` - */ -export * as NonEmptyIterable from "./NonEmptyIterable.ts" - -/** - * This module provides utility functions and type class instances for working with the `number` type in TypeScript. - * It includes functions for basic arithmetic operations, as well as type class instances for - * `Equivalence` and `Order`. - * - * @since 2.0.0 - */ -export * as Number from "./Number.ts" - -/** - * @since 2.0.0 - */ -export * as Option from "./Option.ts" - -/** - * This module provides an implementation of the `Order` type class which is used to define a total ordering on some type `A`. - * An order is defined by a relation `<=`, which obeys the following laws: - * - * - either `x <= y` or `y <= x` (totality) - * - if `x <= y` and `y <= x`, then `x == y` (antisymmetry) - * - if `x <= y` and `y <= z`, then `x <= z` (transitivity) - * - * The truth table for compare is defined as follows: - * - * | `x <= y` | `x >= y` | Ordering | | - * | -------- | -------- | -------- | --------------------- | - * | `true` | `true` | `0` | corresponds to x == y | - * | `true` | `false` | `< 0` | corresponds to x < y | - * | `false` | `true` | `> 0` | corresponds to x > y | - * - * @since 2.0.0 - */ -export * as Order from "./Order.ts" - -/** - * @fileoverview - * The Ordering module provides utilities for working with comparison results and ordering operations. - * An Ordering represents the result of comparing two values, expressing whether the first value is - * less than (-1), equal to (0), or greater than (1) the second value. - * - * This module is fundamental for building comparison functions, sorting algorithms, and implementing - * ordered data structures. It provides composable operations for combining multiple comparison results - * and pattern matching on ordering outcomes. - * - * Key Features: - * - Type-safe representation of comparison results (-1, 0, 1) - * - Composable operations for combining multiple orderings - * - Pattern matching utilities for handling different ordering cases - * - Ordering reversal and combination functions - * - Integration with Effect's functional programming patterns - * - * Common Use Cases: - * - Implementing custom comparison functions - * - Building complex sorting criteria - * - Combining multiple comparison results - * - Creating ordered data structures - * - Pattern matching on comparison outcomes - * - * @since 2.0.0 - * @category utilities - */ -export * as Ordering from "./Ordering.ts" - -/** - * @since 2.0.0 - */ -export * as Pipeable from "./Pipeable.ts" - -/** - * @since 2.0.0 - */ -export * as Predicate from "./Predicate.ts" - -/** - * This module provides functionality for working with primary keys. - * A `PrimaryKey` is a simple interface that represents a unique identifier - * that can be converted to a string representation. - * - * Primary keys are useful for creating unique identifiers for objects, - * database records, cache keys, or any scenario where you need a - * string-based unique identifier. - * - * @since 2.0.0 - */ -export * as PrimaryKey from "./PrimaryKey.ts" - -/** - * This module provides utilities for working with publish-subscribe (PubSub) systems. - * - * A PubSub is an asynchronous message hub where publishers can publish messages and subscribers - * can subscribe to receive those messages. PubSub supports various backpressure strategies, - * message replay, and concurrent access from multiple producers and consumers. - * - * @example - * ```ts - * import { Effect, PubSub, Scope } from "effect" - * - * const program = Effect.gen(function*() { - * const pubsub = yield* PubSub.bounded(10) - * - * // Publisher - * yield* PubSub.publish(pubsub, "Hello") - * yield* PubSub.publish(pubsub, "World") - * - * // Subscriber - * yield* Effect.scoped(Effect.gen(function*() { - * const subscription = yield* PubSub.subscribe(pubsub) - * const message1 = yield* PubSub.take(subscription) - * const message2 = yield* PubSub.take(subscription) - * console.log(message1, message2) // "Hello", "World" - * })) - * }) - * ``` - * - * @since 2.0.0 - */ -export * as PubSub from "./PubSub.ts" - -/** - * @since 4.0.0 - */ -export * as Pull from "./Pull.ts" - -/** - * This module provides utilities for working with asynchronous queues that support various backpressure strategies. - * - * A Queue is a data structure that allows producers to add elements and consumers to take elements - * in a thread-safe manner. The queue supports different strategies for handling backpressure when - * the queue reaches capacity. - * - * @example - * ```ts - * import { Effect, Queue } from "effect" - * - * // Creating a bounded queue with capacity 10 - * const program = Effect.gen(function*() { - * const queue = yield* Queue.bounded(10) - * - * // Producer: add items to queue - * yield* Queue.offer(queue, 1) - * yield* Queue.offer(queue, 2) - * yield* Queue.offerAll(queue, [3, 4, 5]) - * - * // Consumer: take items from queue - * const item1 = yield* Queue.take(queue) - * const item2 = yield* Queue.take(queue) - * const remaining = yield* Queue.takeAll(queue) - * - * console.log({ item1, item2, remaining }) // { item1: 1, item2: 2, remaining: [3, 4, 5] } - * - * // Signal completion - * yield* Queue.end(queue) - * }) - * ``` - * - * @since 3.8.0 - */ -export * as Queue from "./Queue.ts" - -/** - * @since 3.5.0 - */ -export * as RcMap from "./RcMap.ts" - -/** - * @since 3.5.0 - */ -export * as RcRef from "./RcRef.ts" - -/** - * This module provides utility functions for working with records in TypeScript. - * - * @since 2.0.0 - */ -export * as Record from "./Record.ts" - -/** - * The Redacted module provides functionality for handling sensitive information - * securely within your application. By using the `Redacted` data type, you can - * ensure that sensitive values are not accidentally exposed in logs or error - * messages. - * - * @since 3.3.0 - */ -export * as Redacted from "./Redacted.ts" - -/** - * This module provides utilities for working with mutable references in a functional context. - * - * A Ref is a mutable reference that can be read, written, and atomically modified. Unlike plain - * mutable variables, Refs are thread-safe and work seamlessly with Effect's concurrency model. - * They provide atomic operations for safe state management in concurrent programs. - * - * @example - * ```ts - * import { Effect, Ref } from "effect" - * - * const program = Effect.gen(function*() { - * // Create a ref with initial value - * const counter = yield* Ref.make(0) - * - * // Atomic operations - * yield* Ref.update(counter, n => n + 1) - * yield* Ref.update(counter, n => n * 2) - * - * const value = yield* Ref.get(counter) - * console.log(value) // 2 - * - * // Atomic modify with return value - * const previous = yield* Ref.getAndSet(counter, 100) - * console.log(previous) // 2 - * }) - * ``` - * - * @since 2.0.0 - */ -export * as Ref from "./Ref.ts" - -/** - * This module provides a collection of reference implementations for commonly used - * Effect runtime configuration values. These references allow you to access and - * modify runtime behavior such as concurrency limits, scheduling policies, - * tracing configuration, and logging settings. - * - * References are special service instances that can be dynamically updated - * during runtime, making them ideal for configuration that may need to change - * based on application state or external conditions. - * - * @since 4.0.0 - */ -export * as References from "./References.ts" - -/** - * This module provides utility functions for working with RegExp in TypeScript. - * - * @since 2.0.0 - */ -export * as RegExp from "./RegExp.ts" - -/** - * @since 4.0.0 - */ -export * as Result from "./Result.ts" - -/** - * This module provides utilities for running Effect programs and managing their execution lifecycle. - * - * The Runtime module contains functions for creating main program runners that handle process - * teardown, error reporting, and exit code management. These utilities are particularly useful - * for creating CLI applications and server processes that need to manage their lifecycle properly. - * - * @example - * ```ts - * import { Effect, Runtime, Fiber } from "effect" - * - * // Create a main runner for Node.js - * const runMain = Runtime.makeRunMain((options) => { - * process.on('SIGINT', () => Effect.runFork(Fiber.interrupt(options.fiber))) - * process.on('SIGTERM', () => Effect.runFork(Fiber.interrupt(options.fiber))) - * - * options.fiber.addObserver((exit) => { - * options.teardown(exit, (code) => process.exit(code)) - * }) - * }) - * - * // Use the runner - * const program = Effect.log("Hello, World!") - * runMain(program) - * ``` - * - * @since 4.0.0 - */ -export * as Runtime from "./Runtime.ts" - -/** - * This module provides utilities for creating and composing schedules for retrying operations, - * repeating effects, and implementing various timing strategies. - * - * A Schedule is a function that takes an input and returns a decision whether to continue or halt, - * along with a delay duration. Schedules can be combined, transformed, and used to implement - * sophisticated retry and repetition logic. - * - * @example - * ```ts - * import { Effect, Schedule, Duration } from "effect" - * - * // Retry with exponential backoff - * const retryPolicy = Schedule.exponential("100 millis", 2.0) - * .pipe(Schedule.compose(Schedule.recurs(3))) - * - * const program = Effect.gen(function*() { - * // This will retry up to 3 times with exponential backoff - * const result = yield* Effect.retry( - * Effect.fail("Network error"), - * retryPolicy - * ) - * }) - * - * // Repeat on a fixed schedule - * const heartbeat = Effect.log("heartbeat") - * .pipe(Effect.repeat(Schedule.spaced("30 seconds"))) - * ``` - * - * @since 2.0.0 - */ -export * as Schedule from "./Schedule.ts" - -/** - * @since 2.0.0 - */ -export * as Scheduler from "./Scheduler.ts" - -/** - * The `Scope` module provides functionality for managing resource lifecycles - * and cleanup operations in a functional and composable manner. - * - * A `Scope` represents a context where resources can be acquired and automatically - * cleaned up when the scope is closed. This is essential for managing resources - * like file handles, database connections, or any other resources that need - * proper cleanup. - * - * Scopes support both sequential and parallel finalization strategies: - * - Sequential: Finalizers run one after another in reverse order of registration - * - Parallel: Finalizers run concurrently for better performance - * - * @since 2.0.0 - */ -export * as Scope from "./Scope.ts" - -/** - * This module provides a data structure called `ServiceMap` that can be used for dependency injection in effectful - * programs. It is essentially a table mapping `Keys`s to their implementations (called `Service`s), and can be used to - * manage dependencies in a type-safe way. The `ServiceMap` data structure is essentially a way of providing access to a set - * of related services that can be passed around as a single unit. This module provides functions to create, modify, and - * query the contents of a `ServiceMap`, as well as a number of utility types for working with keys and services. - * - * @since 4.0.0 - */ -export * as ServiceMap from "./ServiceMap.ts" - -/** - * @since 2.0.0 - */ -export * as Sink from "./Sink.ts" - -/** - * @since 2.0.0 - */ -export * as Stream from "./Stream.ts" - -/** - * This module provides utility functions and type class instances for working with the `string` type in TypeScript. - * It includes functions for basic string manipulation, as well as type class instances for - * `Equivalence` and `Order`. - * - * @since 2.0.0 - */ -export * as String from "./String.ts" - -/** - * This module provides utility functions for working with structs in TypeScript. - * - * @since 2.0.0 - */ -export * as Struct from "./Struct.ts" - -/** - * @since 2.0.0 - */ -export * as Symbol from "./Symbol.ts" - -/** - * @since 2.0.0 - */ -export * as TestClock from "./TestClock.ts" - -/** - * @since 4.0.0 - */ -export * as TestConsole from "./TestConsole.ts" - -/** - * @since 2.0.0 - */ -export * as Tracer from "./Tracer.ts" - -/** - * A `Trie` is used for locating specific `string` keys from within a set. - * - * It works similar to `HashMap`, but with keys required to be `string`. - * This constraint unlocks some performance optimizations and new methods to get string prefixes (e.g. `keysWithPrefix`, `longestPrefixOf`). - * - * Prefix search is also the main feature that makes a `Trie` more suited than `HashMap` for certain usecases. - * - * A `Trie` is often used to store a dictionary (list of words) that can be searched - * in a manner that allows for efficient generation of completion lists - * (e.g. predict the rest of a word a user is typing). - * - * A `Trie` has O(n) lookup time where `n` is the size of the key, - * or even less than `n` on search misses. - * - * @since 2.0.0 - */ -export * as Trie from "./Trie.ts" - -/** - * This module provides utility functions for working with tuples in TypeScript. - * - * @since 2.0.0 - */ -export * as Tuple from "./Tuple.ts" - -/** - * TxChunk is a transactional chunk data structure that provides Software Transactional Memory (STM) - * semantics for chunk operations. It uses a `TxRef>` internally to ensure all operations - * are performed atomically within transactions. - * - * Accessed values are tracked by the transaction in order to detect conflicts and to track changes. - * A transaction will retry whenever a conflict is detected or whenever the transaction explicitly - * calls `Effect.retryTransaction` and any of the accessed TxChunk values change. - * - * @since 4.0.0 - */ -export * as TxChunk from "./TxChunk.ts" - -/** - * @since 2.0.0 - */ -export * as TxHashMap from "./TxHashMap.ts" - -/** - * @since 2.0.0 - */ -export * as TxHashSet from "./TxHashSet.ts" - -/** - * TxQueue is a transactional queue data structure that provides Software Transactional Memory (STM) - * semantics for queue operations. It uses TxRef for transactional state management and supports - * multiple queue strategies: bounded, unbounded, dropping, and sliding. - * - * Accessed values are tracked by the transaction in order to detect conflicts and to track changes. - * A transaction will retry whenever a conflict is detected or whenever the transaction explicitly - * calls `Effect.retryTransaction` and any of the accessed TxQueue values change. - * - * @since 4.0.0 - */ -export * as TxQueue from "./TxQueue.ts" - -/** - * TxRef is a transactional value, it can be read and modified within the body of a transaction. - * - * Accessed values are tracked by the transaction in order to detect conflicts and in order to - * track changes, a transaction will retry whenever a conflict is detected or whenever the - * transaction explicitely calls to `Effect.retryTransaction` and any of the accessed TxRef values - * change. - * - * @since 4.0.0 - */ -export * as TxRef from "./TxRef.ts" - -/** - * @since 4.0.0 - */ -export * as TxSemaphore from "./TxSemaphore.ts" - -/** - * A collection of types that are commonly used types. - * - * @since 2.0.0 - */ -export * as Types from "./Types.ts" - -/** - * @since 2.0.0 - */ -export * as Unify from "./Unify.ts" - /** * @since 2.0.0 */ diff --git a/packages/effect/src/Equal.ts b/packages/effect/src/interfaces/Equal.ts similarity index 90% rename from packages/effect/src/Equal.ts rename to packages/effect/src/interfaces/Equal.ts index 15c23967eb..c953337b0a 100644 --- a/packages/effect/src/Equal.ts +++ b/packages/effect/src/interfaces/Equal.ts @@ -5,16 +5,16 @@ * * @since 2.0.0 */ -import type { Equivalence } from "./Equivalence.ts" -import * as Hash from "./Hash.ts" -import { hasProperty } from "./Predicate.ts" +import type { Equivalence } from "../data/Equivalence.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Hash from "../interfaces/Hash.ts" /** * The unique symbol used to identify objects that implement the `Equal` interface. * * @example * ```ts - * import { Equal, Hash } from "effect" + * import { Equal, Hash } from "effect/interfaces" * * class Person implements Equal.Equal { * constructor(private name: string, private age: number) {} @@ -42,7 +42,7 @@ export const symbol: "~effect/Equal" = "~effect/Equal" as const * * @example * ```ts - * import { Equal, Hash } from "effect" + * import { Equal, Hash } from "effect/interfaces" * * class Coordinate implements Equal.Equal { * constructor(readonly x: number, readonly y: number) {} @@ -75,7 +75,7 @@ export interface Equal extends Hash.Hash { * * @example * ```ts - * import { Equal } from "effect" + * import { Equal } from "effect/interfaces" * * // Basic equality * console.log(Equal.equals(1, 1)) // true @@ -129,7 +129,7 @@ function compareBoth(self: unknown, that: unknown): boolean { * * @example * ```ts - * import { Equal, Hash } from "effect" + * import { Equal, Hash } from "effect/interfaces" * * class MyClass implements Equal.Equal { * [Equal.symbol](that: Equal.Equal): boolean { @@ -157,7 +157,8 @@ export const isEqual = (u: unknown): u is Equal => hasProperty(u, symbol) * * @example * ```ts - * import { Equal, Array } from "effect" + * import { Equal } from "effect/interfaces" + * import { Array } from "effect/collections" * * const eq = Equal.equivalence() * const result = Array.dedupeWith([1, 2, 2, 3, 1], eq) diff --git a/packages/effect/src/Hash.ts b/packages/effect/src/interfaces/Hash.ts similarity index 94% rename from packages/effect/src/Hash.ts rename to packages/effect/src/interfaces/Hash.ts index eb76bbe620..6d82dd2617 100644 --- a/packages/effect/src/Hash.ts +++ b/packages/effect/src/interfaces/Hash.ts @@ -7,8 +7,8 @@ * * @since 2.0.0 */ -import { pipe } from "./Function.ts" -import { hasProperty } from "./Predicate.ts" +import { hasProperty } from "../data/Predicate.ts" +import { pipe } from "../Function.ts" /** @internal */ const randomHashCache = new WeakMap() @@ -18,7 +18,7 @@ const randomHashCache = new WeakMap() * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * console.log(Hash.symbol) // "~effect/Hash" * ``` @@ -36,7 +36,7 @@ export const symbol: "~effect/Hash" = "~effect/Hash" as const * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * class MyClass implements Hash.Hash { * constructor(private value: number) {} @@ -66,7 +66,7 @@ export interface Hash { * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * // Hash primitive values * console.log(Hash.hash(42)) // numeric hash @@ -124,7 +124,7 @@ export const hash: (self: A) => number = (self: A) => { * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * const obj1 = { a: 1 } * const obj2 = { a: 1 } @@ -155,7 +155,7 @@ export const random: (self: A) => number = (self) => { * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * const hash1 = Hash.hash("hello") * const hash2 = Hash.hash("world") @@ -182,7 +182,7 @@ export const combine: (b: number) => (self: number) => number = (b) => (self) => * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * const rawHash = 1234567890 * const optimizedHash = Hash.optimize(rawHash) @@ -205,7 +205,7 @@ export const optimize = (n: number): number => (n & 0xbfffffff) | ((n >>> 1) & 0 * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * class MyHashable implements Hash.Hash { * [Hash.symbol]() { @@ -233,7 +233,7 @@ export const isHash = (u: unknown): u is Hash => hasProperty(u, symbol) * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * console.log(Hash.number(42)) // hash of 42 * console.log(Hash.number(3.14)) // hash of 3.14 @@ -270,7 +270,7 @@ export const number = (n: number) => { * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * console.log(Hash.string("hello")) // hash of "hello" * console.log(Hash.string("world")) // hash of "world" @@ -300,7 +300,7 @@ export const string = (str: string) => { * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * const person = { name: "John", age: 30, city: "New York" } * @@ -337,7 +337,7 @@ export const structureKeys = (o: A, keys: ReadonlyArray(o: A) => * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * const arr1 = [1, 2, 3] * const arr2 = [1, 2, 3] @@ -403,7 +403,7 @@ const hashCache = new WeakMap() * * @example * ```ts - * import { Hash } from "effect" + * import { Hash } from "effect/interfaces" * * const obj = { complex: "data structure" } * diff --git a/packages/effect/src/Inspectable.ts b/packages/effect/src/interfaces/Inspectable.ts similarity index 93% rename from packages/effect/src/Inspectable.ts rename to packages/effect/src/interfaces/Inspectable.ts index c2548f3d3d..187323f686 100644 --- a/packages/effect/src/Inspectable.ts +++ b/packages/effect/src/interfaces/Inspectable.ts @@ -10,7 +10,7 @@ * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * class User extends Inspectable.Class { * constructor( @@ -36,9 +36,9 @@ * * @since 2.0.0 */ -import { pipeArguments } from "./Pipeable.ts" -import { hasProperty, isFunction } from "./Predicate.ts" -import type * as ServiceMap from "./ServiceMap.ts" +import { hasProperty, isFunction } from "../data/Predicate.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import type * as ServiceMap from "../services/ServiceMap.ts" /** * Symbol used by Node.js for custom object inspection. @@ -49,7 +49,7 @@ import type * as ServiceMap from "./ServiceMap.ts" * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * class CustomObject { * constructor(private value: string) {} @@ -75,7 +75,7 @@ export const NodeInspectSymbol = Symbol.for("nodejs.util.inspect.custom") * * @example * ```ts - * import * as Inspectable from "effect/Inspectable" + * import { Inspectable } from "effect/interfaces" * * class CustomObject { * constructor(private value: string) {} @@ -103,7 +103,7 @@ export type NodeInspectSymbol = typeof NodeInspectSymbol * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * class Result implements Inspectable.Inspectable { * constructor( @@ -147,7 +147,7 @@ export interface Inspectable { * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * class Person { * constructor( @@ -198,7 +198,7 @@ export const toJSON = (x: unknown): unknown => { * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * const data = { * name: "Alice", @@ -235,7 +235,7 @@ export const format = (x: unknown): string => JSON.stringify(x, null, 2) * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * // Use as prototype * const myObject = Object.create(Inspectable.BaseProto) @@ -276,7 +276,7 @@ export const BaseProto: Inspectable = { * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * class User extends Inspectable.Class { * constructor( @@ -345,7 +345,7 @@ export abstract class Class { * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * // Simple values * console.log(Inspectable.toStringUnknown("hello")) // "hello" @@ -392,7 +392,7 @@ export const toStringUnknown = ( * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * // Normal object * const simple = { name: "Alice", age: 30 } @@ -444,7 +444,8 @@ export const stringifyCircular = ( * * @example * ```ts - * import { Inspectable, ServiceMap } from "effect" + * import { Inspectable } from "effect/interfaces" + * import { ServiceMap } from "effect/services" * * class SensitiveData implements Inspectable.Redactable { * constructor(private secret: string) {} @@ -475,7 +476,7 @@ export interface Redactable { * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * class APIKey { * constructor(private key: string) {} @@ -504,7 +505,7 @@ export const symbolRedactable: unique symbol = Symbol.for("effect/Inspectable/re * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * class RedactableSecret { * [Inspectable.symbolRedactable]() { @@ -539,7 +540,7 @@ const currentFiberUri = "effect/Fiber/currentFiber" * * @example * ```ts - * import { Inspectable } from "effect" + * import { Inspectable } from "effect/interfaces" * * class CreditCard { * constructor(private number: string) {} diff --git a/packages/effect/src/Pipeable.ts b/packages/effect/src/interfaces/Pipeable.ts similarity index 99% rename from packages/effect/src/Pipeable.ts rename to packages/effect/src/interfaces/Pipeable.ts index 841afbab1b..ad367ed12a 100644 --- a/packages/effect/src/Pipeable.ts +++ b/packages/effect/src/interfaces/Pipeable.ts @@ -504,7 +504,7 @@ export interface Pipeable { * @category utilities * @example * ```ts - * import { Pipeable } from "effect" + * import { Pipeable } from "effect/interfaces" * * // pipeArguments is used internally to implement efficient piping * function customPipe(self: A, ...fns: Array<(a: any) => any>): unknown { diff --git a/packages/effect/src/PrimaryKey.ts b/packages/effect/src/interfaces/PrimaryKey.ts similarity index 93% rename from packages/effect/src/PrimaryKey.ts rename to packages/effect/src/interfaces/PrimaryKey.ts index 4fdd606b4b..1b6d4c78ff 100644 --- a/packages/effect/src/PrimaryKey.ts +++ b/packages/effect/src/interfaces/PrimaryKey.ts @@ -15,7 +15,7 @@ * * @example * ```ts - * import { PrimaryKey } from "effect" + * import { PrimaryKey } from "effect/interfaces" * * class UserId implements PrimaryKey.PrimaryKey { * constructor(private id: string) {} @@ -42,7 +42,7 @@ export const symbol: "~effect/PrimaryKey" = "~effect/PrimaryKey" as const * * @example * ```ts - * import { PrimaryKey } from "effect" + * import { PrimaryKey } from "effect/interfaces" * * class ProductId implements PrimaryKey.PrimaryKey { * constructor(private category: string, private id: number) {} @@ -68,7 +68,7 @@ export interface PrimaryKey { * * @example * ```ts - * import { PrimaryKey } from "effect" + * import { PrimaryKey } from "effect/interfaces" * * class OrderId implements PrimaryKey.PrimaryKey { * constructor(private timestamp: number, private sequence: number) {} diff --git a/packages/effect/src/interfaces/index.ts b/packages/effect/src/interfaces/index.ts new file mode 100644 index 0000000000..c06f0fb98d --- /dev/null +++ b/packages/effect/src/interfaces/index.ts @@ -0,0 +1,81 @@ +/** + * @since 4.0.0 + */ + +/** + * This module provides functionality for defining and working with equality between values. + * It includes the `Equal` interface for types that can determine equality with other values + * of the same type, and utilities for comparing values. + * + * @since 2.0.0 + */ +export * as Equal from "./Equal.ts" + +/** + * This module provides utilities for hashing values in TypeScript. + * + * Hashing is the process of converting data into a fixed-size numeric value, + * typically used for data structures like hash tables, equality comparisons, + * and efficient data storage. + * + * @since 2.0.0 + */ +export * as Hash from "./Hash.ts" + +/** + * This module provides utilities for making values inspectable and debuggable in TypeScript. + * + * The Inspectable interface provides a standard way to implement custom string representations + * for objects, making them easier to debug and inspect. It includes support for JSON + * serialization, Node.js inspection, and safe circular reference handling. + * + * The module also includes redaction capabilities for sensitive data, allowing objects + * to provide different representations based on the current execution context. + * + * @example + * ```ts + * import { Inspectable } from "effect/interfaces" + * + * class User extends Inspectable.Class { + * constructor( + * public readonly name: string, + * public readonly email: string + * ) { + * super() + * } + * + * toJSON() { + * return { + * _tag: "User", + * name: this.name, + * email: this.email + * } + * } + * } + * + * const user = new User("Alice", "alice@example.com") + * console.log(user.toString()) // Pretty printed JSON + * console.log(Inspectable.format(user)) // Same as toString() + * ``` + * + * @since 2.0.0 + */ +export * as Inspectable from "./Inspectable.ts" + +/** + * @since 2.0.0 + */ +export * as Pipeable from "./Pipeable.ts" + +/** + * This module provides functionality for working with primary keys. + * A `PrimaryKey` is a simple interface that represents a unique identifier + * that can be converted to a string representation. + * + * Primary keys are useful for creating unique identifiers for objects, + * database records, cache keys, or any scenario where you need a + * string-based unique identifier. + * + * @since 2.0.0 + */ +export * as PrimaryKey from "./PrimaryKey.ts" diff --git a/packages/effect/src/interfaces/index.ts.tpl b/packages/effect/src/interfaces/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/interfaces/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/internal/array.ts b/packages/effect/src/internal/array.ts index 62513cb7d6..3ab53631e2 100644 --- a/packages/effect/src/internal/array.ts +++ b/packages/effect/src/internal/array.ts @@ -2,7 +2,7 @@ * @since 2.0.0 */ -import type { NonEmptyArray } from "../Array.ts" +import type { NonEmptyArray } from "../collections/Array.ts" /** @internal */ export const isNonEmptyArray = (self: ReadonlyArray): self is NonEmptyArray => self.length > 0 diff --git a/packages/effect/src/internal/concurrency.ts b/packages/effect/src/internal/concurrency.ts index 7820c9f45b..c3cbef70c0 100644 --- a/packages/effect/src/internal/concurrency.ts +++ b/packages/effect/src/internal/concurrency.ts @@ -1,6 +1,6 @@ import type { Effect } from "../Effect.ts" -import { CurrentConcurrency } from "../References.ts" -import type { Concurrency } from "../Types.ts" +import { CurrentConcurrency } from "../services/References.ts" +import type { Concurrency } from "../types/Types.ts" import * as effect from "./effect.ts" /** @internal */ diff --git a/packages/effect/src/internal/core.ts b/packages/effect/src/internal/core.ts index 58d704766c..f0475c1a3b 100644 --- a/packages/effect/src/internal/core.ts +++ b/packages/effect/src/internal/core.ts @@ -1,15 +1,15 @@ import type * as Cause from "../Cause.ts" +import { hasProperty, isObject } from "../data/Predicate.ts" import type * as Effect from "../Effect.ts" -import * as Equal from "../Equal.ts" import type * as Exit from "../Exit.ts" import { dual, identity } from "../Function.ts" -import * as Hash from "../Hash.ts" -import { format, NodeInspectSymbol } from "../Inspectable.ts" -import { pipeArguments } from "../Pipeable.ts" -import { hasProperty, isObject } from "../Predicate.ts" -import type * as ServiceMap from "../ServiceMap.ts" -import type { Span } from "../Tracer.ts" -import type { Equals, NoInfer } from "../Types.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import { format, NodeInspectSymbol } from "../interfaces/Inspectable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import type { Span } from "../observability/Tracer.ts" +import type * as ServiceMap from "../services/ServiceMap.ts" +import type { Equals, NoInfer } from "../types/Types.ts" import { SingleShotGen, YieldWrap } from "../Utils.ts" import type { FiberImpl } from "./effect.ts" import { version } from "./version.ts" diff --git a/packages/effect/src/internal/data.ts b/packages/effect/src/internal/data.ts index 4289ded1ab..5b046be9af 100644 --- a/packages/effect/src/internal/data.ts +++ b/packages/effect/src/internal/data.ts @@ -1,6 +1,6 @@ -import * as Equal from "../Equal.ts" -import * as Hash from "../Hash.ts" -import type * as Types from "../Types.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import type * as Types from "../types/Types.ts" import { StructuralPrototype } from "./core.ts" /** @internal */ diff --git a/packages/effect/src/internal/dateTime.ts b/packages/effect/src/internal/dateTime.ts index a72eec5f71..8fca85f8f1 100644 --- a/packages/effect/src/internal/dateTime.ts +++ b/packages/effect/src/internal/dateTime.ts @@ -1,20 +1,20 @@ import { IllegalArgumentError } from "../Cause.ts" -import * as Clock from "../Clock.ts" -import type * as DateTime from "../DateTime.ts" -import * as Duration from "../Duration.ts" +import * as equivalence from "../data/Equivalence.ts" +import * as Option from "../data/Option.ts" +import * as order from "../data/Order.ts" +import * as Predicate from "../data/Predicate.ts" +import * as Result from "../data/Result.ts" import type * as Effect from "../Effect.ts" -import * as Equal from "../Equal.ts" -import * as equivalence from "../Equivalence.ts" import type { LazyArg } from "../Function.ts" import { dual, pipe } from "../Function.ts" -import * as Hash from "../Hash.ts" -import * as Inspectable from "../Inspectable.ts" -import * as Option from "../Option.ts" -import * as order from "../Order.ts" -import { pipeArguments } from "../Pipeable.ts" -import * as Predicate from "../Predicate.ts" -import * as Result from "../Result.ts" -import type { Mutable } from "../Types.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import * as Inspectable from "../interfaces/Inspectable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import * as Clock from "../time/Clock.ts" +import type * as DateTime from "../time/DateTime.ts" +import * as Duration from "../time/Duration.ts" +import type { Mutable } from "../types/Types.ts" import * as effect from "./effect.ts" /** @internal */ diff --git a/packages/effect/src/internal/doNotation.ts b/packages/effect/src/internal/doNotation.ts index 7c6e3c919b..0bdca7b431 100644 --- a/packages/effect/src/internal/doNotation.ts +++ b/packages/effect/src/internal/doNotation.ts @@ -1,6 +1,6 @@ import { dual } from "../Function.ts" -import type { Kind, TypeLambda } from "../HKT.ts" -import type { NoInfer } from "../Types.ts" +import type { Kind, TypeLambda } from "../types/HKT.ts" +import type { NoInfer } from "../types/Types.ts" interface Map { ( diff --git a/packages/effect/src/internal/effect.ts b/packages/effect/src/internal/effect.ts index f948e83a9b..23955eee9c 100644 --- a/packages/effect/src/internal/effect.ts +++ b/packages/effect/src/internal/effect.ts @@ -1,24 +1,26 @@ -import * as Arr from "../Array.ts" import type * as Cause from "../Cause.ts" -import type * as Clock from "../Clock.ts" -import type * as Console from "../Console.ts" -import * as Duration from "../Duration.ts" +import * as Arr from "../collections/Array.ts" +import * as Filter from "../data/Filter.ts" +import * as Option from "../data/Option.ts" +import * as Order from "../data/Order.ts" +import { hasProperty, isIterable, isString, isTagged } from "../data/Predicate.ts" +import * as Result from "../data/Result.ts" import type * as Effect from "../Effect.ts" -import * as Equal from "../Equal.ts" import type * as Exit from "../Exit.ts" -import type * as Fiber from "../Fiber.ts" -import * as Filter from "../Filter.ts" import type { LazyArg } from "../Function.ts" import { constant, constTrue, constVoid, dual, identity } from "../Function.ts" -import * as Hash from "../Hash.ts" -import { redact, stringifyCircular, toJSON } from "../Inspectable.ts" -import type * as Logger from "../Logger.ts" -import type * as LogLevel from "../LogLevel.ts" -import type * as Metric from "../Metric.ts" -import * as Option from "../Option.ts" -import * as Order from "../Order.ts" -import { pipeArguments } from "../Pipeable.ts" -import { hasProperty, isIterable, isString, isTagged } from "../Predicate.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import { redact, stringifyCircular, toJSON } from "../interfaces/Inspectable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import type * as Console from "../logging/Console.ts" +import type * as Logger from "../logging/Logger.ts" +import type * as LogLevel from "../logging/LogLevel.ts" +import type * as Metric from "../observability/Metric.ts" +import * as Tracer from "../observability/Tracer.ts" +import type * as Scope from "../resources/Scope.ts" +import type * as Fiber from "../runtime/Fiber.ts" +import * as Scheduler from "../runtime/Scheduler.ts" import { CurrentConcurrency, CurrentLogAnnotations, @@ -28,13 +30,11 @@ import { TracerEnabled, TracerSpanAnnotations, TracerSpanLinks -} from "../References.ts" -import * as Result from "../Result.ts" -import * as Scheduler from "../Scheduler.ts" -import type * as Scope from "../Scope.ts" -import * as ServiceMap from "../ServiceMap.ts" -import * as Tracer from "../Tracer.ts" -import type { Concurrency, ExcludeTag, ExtractTag, NoInfer, NotFunction, Simplify, Tags } from "../Types.ts" +} from "../services/References.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import type * as Clock from "../time/Clock.ts" +import * as Duration from "../time/Duration.ts" +import type { Concurrency, ExcludeTag, ExtractTag, NoInfer, NotFunction, Simplify, Tags } from "../types/Types.ts" import type { YieldWrap } from "../Utils.ts" import { internalCall, yieldWrapGet } from "../Utils.ts" import type { Primitive } from "./core.ts" diff --git a/packages/effect/src/internal/encoding/base64.ts b/packages/effect/src/internal/encoding/base64.ts index f8faddf228..c94b61f1cc 100644 --- a/packages/effect/src/internal/encoding/base64.ts +++ b/packages/effect/src/internal/encoding/base64.ts @@ -1,5 +1,5 @@ -import type * as Encoding from "../../Encoding.ts" -import * as Result from "../../Result.ts" +import * as Result from "../../data/Result.ts" +import type * as Encoding from "../../encoding/Encoding.ts" import { DecodeException } from "./common.ts" /** @internal */ diff --git a/packages/effect/src/internal/encoding/base64Url.ts b/packages/effect/src/internal/encoding/base64Url.ts index adc132db2b..fefbd354ab 100644 --- a/packages/effect/src/internal/encoding/base64Url.ts +++ b/packages/effect/src/internal/encoding/base64Url.ts @@ -1,5 +1,5 @@ -import type * as Encoding from "../../Encoding.ts" -import * as Result from "../../Result.ts" +import * as Result from "../../data/Result.ts" +import type * as Encoding from "../../encoding/Encoding.ts" import * as Base64 from "./base64.ts" import { DecodeException } from "./common.ts" diff --git a/packages/effect/src/internal/encoding/common.ts b/packages/effect/src/internal/encoding/common.ts index a031c798cc..18e174c0f0 100644 --- a/packages/effect/src/internal/encoding/common.ts +++ b/packages/effect/src/internal/encoding/common.ts @@ -1,6 +1,6 @@ -import type * as Encoding from "../../Encoding.ts" -import { hasProperty, isString } from "../../Predicate.ts" -import type { Mutable } from "../../Types.ts" +import { hasProperty, isString } from "../../data/Predicate.ts" +import type * as Encoding from "../../encoding/Encoding.ts" +import type { Mutable } from "../../types/Types.ts" /** @internal */ export const DecodeExceptionTypeId: Encoding.DecodeExceptionTypeId = Symbol.for( diff --git a/packages/effect/src/internal/encoding/hex.ts b/packages/effect/src/internal/encoding/hex.ts index 865e22811f..76fde2d270 100644 --- a/packages/effect/src/internal/encoding/hex.ts +++ b/packages/effect/src/internal/encoding/hex.ts @@ -1,5 +1,5 @@ -import type * as Encoding from "../../Encoding.ts" -import * as Result from "../../Result.ts" +import * as Result from "../../data/Result.ts" +import type * as Encoding from "../../encoding/Encoding.ts" import { DecodeException } from "./common.ts" /** @internal */ diff --git a/packages/effect/src/internal/hashMap.ts b/packages/effect/src/internal/hashMap.ts index bf7d3c4379..c55fb63791 100644 --- a/packages/effect/src/internal/hashMap.ts +++ b/packages/effect/src/internal/hashMap.ts @@ -2,16 +2,16 @@ * @since 2.0.0 */ -import * as Equal_ from "../Equal.ts" +import * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" import { dual, pipe } from "../Function.ts" -import * as Hash from "../Hash.ts" -import type { Inspectable } from "../Inspectable.ts" -import { format, NodeInspectSymbol, toJSON } from "../Inspectable.ts" -import * as Option from "../Option.ts" -import type { Pipeable } from "../Pipeable.ts" -import { pipeArguments } from "../Pipeable.ts" -import { hasProperty } from "../Predicate.ts" -import type { NoInfer } from "../Types.ts" +import * as Equal_ from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import { format, NodeInspectSymbol, toJSON } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import type { NoInfer } from "../types/Types.ts" /** @internal */ export const HashMapTypeId: "~effect/HashMap" = "~effect/HashMap" as const diff --git a/packages/effect/src/internal/hashSet.ts b/packages/effect/src/internal/hashSet.ts index b0ad5637cf..d3db466db7 100644 --- a/packages/effect/src/internal/hashSet.ts +++ b/packages/effect/src/internal/hashSet.ts @@ -2,13 +2,13 @@ * @since 2.0.0 */ -import * as Equal from "../Equal.ts" -import * as Hash from "../Hash.ts" -import type { Inspectable } from "../Inspectable.ts" -import { format, NodeInspectSymbol, toJSON } from "../Inspectable.ts" -import type { Pipeable } from "../Pipeable.ts" -import { pipeArguments } from "../Pipeable.ts" -import { hasProperty } from "../Predicate.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import { format, NodeInspectSymbol, toJSON } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" import * as HashMap from "./hashMap.ts" /** @internal */ diff --git a/packages/effect/src/internal/layer.ts b/packages/effect/src/internal/layer.ts index 5dfb3f2fdf..52da96bf7b 100644 --- a/packages/effect/src/internal/layer.ts +++ b/packages/effect/src/internal/layer.ts @@ -1,7 +1,7 @@ import type { Effect } from "../Effect.ts" import { dual } from "../Function.ts" -import * as Layer from "../Layer.ts" -import * as ServiceMap from "../ServiceMap.ts" +import * as Layer from "../services/Layer.ts" +import * as ServiceMap from "../services/ServiceMap.ts" import * as effect from "./effect.ts" const provideLayer = ( diff --git a/packages/effect/src/internal/matcher.ts b/packages/effect/src/internal/matcher.ts index a22ca078a0..dc090f5307 100644 --- a/packages/effect/src/internal/matcher.ts +++ b/packages/effect/src/internal/matcher.ts @@ -1,4 +1,8 @@ +import * as Option from "../data/Option.ts" +import type * as Predicate from "../data/Predicate.ts" +import * as Result from "../data/Result.ts" import { dual, identity } from "../Function.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" import type { Case, Matcher, @@ -9,12 +13,8 @@ import type { Types, ValueMatcher, When -} from "../Match.ts" -import * as Option from "../Option.ts" -import { pipeArguments } from "../Pipeable.ts" -import type * as Predicate from "../Predicate.ts" -import * as Result from "../Result.ts" -import type { Unify } from "../Unify.ts" +} from "../match/Match.ts" +import type { Unify } from "../types/Unify.ts" /** @internal */ export const TypeId: MatcherTypeId = "~effect/Match/Matcher" diff --git a/packages/effect/src/internal/option.ts b/packages/effect/src/internal/option.ts index 23198f5771..665747b2a6 100644 --- a/packages/effect/src/internal/option.ts +++ b/packages/effect/src/internal/option.ts @@ -1,11 +1,11 @@ /** * @since 2.0.0 */ -import * as Equal from "../Equal.ts" -import * as Hash from "../Hash.ts" -import { toJSON } from "../Inspectable.ts" -import type * as Option from "../Option.ts" -import { hasProperty } from "../Predicate.ts" +import type * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import { toJSON } from "../interfaces/Inspectable.ts" import { exitFail, exitSucceed, NoSuchElementError, PipeInspectableProto, YieldableProto } from "./core.ts" const TypeId: Option.TypeId = "~effect/Option" diff --git a/packages/effect/src/internal/rcRef.ts b/packages/effect/src/internal/rcRef.ts index c850f9bf82..27fcd41a6c 100644 --- a/packages/effect/src/internal/rcRef.ts +++ b/packages/effect/src/internal/rcRef.ts @@ -1,11 +1,11 @@ -import * as Duration from "../Duration.ts" import * as Effect from "../Effect.ts" import * as Exit from "../Exit.ts" -import * as Fiber from "../Fiber.ts" import { identity } from "../Function.ts" -import type * as RcRef from "../RcRef.ts" -import * as Scope from "../Scope.ts" -import * as ServiceMap from "../ServiceMap.ts" +import type * as RcRef from "../resources/RcRef.ts" +import * as Scope from "../resources/Scope.ts" +import * as Fiber from "../runtime/Fiber.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import * as Duration from "../time/Duration.ts" /** @internal */ export const TypeId: RcRef.TypeId = "~effect/RcRef" diff --git a/packages/effect/src/internal/redacted.ts b/packages/effect/src/internal/redacted.ts index 6043e1f99c..d3ada0d05f 100644 --- a/packages/effect/src/internal/redacted.ts +++ b/packages/effect/src/internal/redacted.ts @@ -1,4 +1,4 @@ -import type * as Redacted from "../Redacted.ts" +import type * as Redacted from "../data/Redacted.ts" /** @internal */ export const redactedRegistry = new WeakMap, any>() diff --git a/packages/effect/src/internal/request.ts b/packages/effect/src/internal/request.ts index 5d40da7c44..eef217e6b0 100644 --- a/packages/effect/src/internal/request.ts +++ b/packages/effect/src/internal/request.ts @@ -1,10 +1,10 @@ -import type { NonEmptyArray } from "../Array.ts" import type * as Request from "../batching/Request.ts" import { makeEntry } from "../batching/Request.ts" import type { RequestResolver } from "../batching/RequestResolver.ts" +import type { NonEmptyArray } from "../collections/Array.ts" import type { Effect } from "../Effect.ts" -import type { Fiber } from "../Fiber.ts" import { dual } from "../Function.ts" +import type { Fiber } from "../runtime/Fiber.ts" import { exitDie, isEffect } from "./core.ts" import * as effect from "./effect.ts" diff --git a/packages/effect/src/internal/result.ts b/packages/effect/src/internal/result.ts index 1115366a03..6cdfbb47d8 100644 --- a/packages/effect/src/internal/result.ts +++ b/packages/effect/src/internal/result.ts @@ -1,10 +1,10 @@ -import * as Equal from "../Equal.ts" +import type { Option } from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" +import type * as Result from "../data/Result.ts" import { dual } from "../Function.ts" -import * as Hash from "../Hash.ts" -import { toJSON } from "../Inspectable.ts" -import type { Option } from "../Option.ts" -import { hasProperty } from "../Predicate.ts" -import type * as Result from "../Result.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import { toJSON } from "../interfaces/Inspectable.ts" import { exitFail, exitSucceed, PipeInspectableProto, YieldableProto } from "./core.ts" import * as option from "./option.ts" diff --git a/packages/effect/src/internal/schedule.ts b/packages/effect/src/internal/schedule.ts index 0848147db4..86712648f0 100644 --- a/packages/effect/src/internal/schedule.ts +++ b/packages/effect/src/internal/schedule.ts @@ -1,9 +1,9 @@ +import * as Option from "../data/Option.ts" import type { Effect, Repeat, Retry } from "../Effect.ts" import { dual } from "../Function.ts" -import * as Option from "../Option.ts" -import * as Pull from "../Pull.ts" -import * as Schedule from "../Schedule.ts" -import type { NoInfer } from "../Types.ts" +import * as Schedule from "../scheduling/Schedule.ts" +import * as Pull from "../stream/Pull.ts" +import type { NoInfer } from "../types/Types.ts" import { internalCall } from "../Utils.ts" import * as effect from "./effect.ts" diff --git a/packages/effect/src/internal/schema/util.ts b/packages/effect/src/internal/schema/util.ts index bb827adb00..abbd7583d2 100644 --- a/packages/effect/src/internal/schema/util.ts +++ b/packages/effect/src/internal/schema/util.ts @@ -1,6 +1,6 @@ -import type { Pipeable } from "../../Pipeable.ts" -import { pipeArguments } from "../../Pipeable.ts" -import * as Predicate from "../../Predicate.ts" +import * as Predicate from "../../data/Predicate.ts" +import type { Pipeable } from "../../interfaces/Pipeable.ts" +import { pipeArguments } from "../../interfaces/Pipeable.ts" import type * as AST from "../../schema/AST.ts" /** diff --git a/packages/effect/src/internal/tracer.ts b/packages/effect/src/internal/tracer.ts index d39f0b38d3..fb96c3d949 100644 --- a/packages/effect/src/internal/tracer.ts +++ b/packages/effect/src/internal/tracer.ts @@ -1,4 +1,4 @@ -import type * as Tracer from "../Tracer.ts" +import type * as Tracer from "../observability/Tracer.ts" export interface ErrorWithStackTraceLimit { stackTraceLimit?: number | undefined diff --git a/packages/effect/src/internal/tracing/otlpExporter.ts b/packages/effect/src/internal/tracing/otlpExporter.ts index 49b81a8249..05687e8c41 100644 --- a/packages/effect/src/internal/tracing/otlpExporter.ts +++ b/packages/effect/src/internal/tracing/otlpExporter.ts @@ -1,10 +1,10 @@ -import * as Duration from "../../Duration.ts" +import * as Option from "../../data/Option.ts" import * as Effect from "../../Effect.ts" -import * as Fiber from "../../Fiber.ts" -import * as Num from "../../Number.ts" -import * as Option from "../../Option.ts" -import * as Schedule from "../../Schedule.ts" -import * as Scope from "../../Scope.ts" +import * as Num from "../../primitives/Number.ts" +import * as Scope from "../../resources/Scope.ts" +import * as Fiber from "../../runtime/Fiber.ts" +import * as Schedule from "../../scheduling/Schedule.ts" +import * as Duration from "../../time/Duration.ts" import * as Headers from "../../unstable/http/Headers.ts" import * as HttpClient from "../../unstable/http/HttpClient.ts" import * as HttpClientError from "../../unstable/http/HttpClientError.ts" diff --git a/packages/effect/src/internal/trie.ts b/packages/effect/src/internal/trie.ts index 583cf0b626..6219f26838 100644 --- a/packages/effect/src/internal/trie.ts +++ b/packages/effect/src/internal/trie.ts @@ -1,13 +1,13 @@ -import * as Equal from "../Equal.ts" +import type * as TR from "../collections/Trie.ts" +import * as Option from "../data/Option.ts" +import type * as Ordering from "../data/Ordering.ts" +import { hasProperty } from "../data/Predicate.ts" import { dual, identity, pipe } from "../Function.ts" -import * as Hash from "../Hash.ts" -import { format, NodeInspectSymbol, toJSON } from "../Inspectable.ts" -import * as Option from "../Option.ts" -import type * as Ordering from "../Ordering.ts" -import { pipeArguments } from "../Pipeable.ts" -import { hasProperty } from "../Predicate.ts" -import type * as TR from "../Trie.ts" -import type { NoInfer } from "../Types.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import { format, NodeInspectSymbol, toJSON } from "../interfaces/Inspectable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import type { NoInfer } from "../types/Types.ts" /** @internal */ export const TrieTypeId: TR.TypeId = "~effect/Trie" diff --git a/packages/effect/src/Console.ts b/packages/effect/src/logging/Console.ts similarity index 89% rename from packages/effect/src/Console.ts rename to packages/effect/src/logging/Console.ts index 29add97b59..a318a142b4 100644 --- a/packages/effect/src/Console.ts +++ b/packages/effect/src/logging/Console.ts @@ -23,7 +23,8 @@ * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * // Basic logging * const program = Effect.gen(function* () { @@ -36,7 +37,8 @@ * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * // Grouped logging with timing * const debugProgram = Console.withGroup( @@ -53,7 +55,8 @@ * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * // Data visualization and debugging * const dataProgram = Effect.gen(function* () { @@ -70,12 +73,12 @@ * * @since 2.0.0 */ -import type * as Effect from "./Effect.ts" -import { dual } from "./Function.ts" -import * as core from "./internal/core.ts" -import * as effect from "./internal/effect.ts" -import type { Scope } from "./Scope.ts" -import type * as ServiceMap from "./ServiceMap.ts" +import type * as Effect from "../Effect.ts" +import { dual } from "../Function.ts" +import * as core from "../internal/core.ts" +import * as effect from "../internal/effect.ts" +import type { Scope } from "../resources/Scope.ts" +import type * as ServiceMap from "../services/ServiceMap.ts" /** * Represents a console interface for logging and debugging operations. @@ -85,7 +88,7 @@ import type * as ServiceMap from "./ServiceMap.ts" * * @example * ```ts - * import { Console } from "effect" + * import { Console } from "effect/logging" * * // The Console interface defines all console methods * // It's typically implemented by the runtime @@ -145,7 +148,8 @@ export interface Console { * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Console.consoleWith((console) => * Effect.sync(() => { @@ -167,7 +171,8 @@ export const Console: ServiceMap.Reference = effect.ConsoleRef * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Console.consoleWith((console) => * Effect.sync(() => { @@ -191,7 +196,8 @@ export const consoleWith = (f: (console: Console) => Effect.Effect): Effect. * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.log("This will be cleared") @@ -242,7 +249,8 @@ export const clear: Effect.Effect = consoleWith((console) => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.count("my-counter") @@ -269,7 +277,8 @@ export const count = (label?: string): Effect.Effect => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.count("my-counter") @@ -297,7 +306,8 @@ export const countReset = (label?: string): Effect.Effect => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.debug("Debug info:", { userId: 123, action: "login" }) @@ -323,7 +333,8 @@ export const debug = (...args: ReadonlyArray): Effect.Effect => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * const obj = { name: "John", age: 30, nested: { city: "New York" } } @@ -349,7 +360,8 @@ export const dir = (item: any, options?: any): Effect.Effect => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * // In a browser environment @@ -376,7 +388,8 @@ export const dirxml = (...args: ReadonlyArray): Effect.Effect => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.error("Something went wrong!") @@ -402,7 +415,8 @@ export const error = (...args: ReadonlyArray): Effect.Effect => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Effect.scoped( @@ -446,7 +460,8 @@ export const group = ( * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.info("Application started successfully") @@ -471,7 +486,8 @@ export const info = (...args: ReadonlyArray): Effect.Effect => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.log("Hello, world!") @@ -498,7 +514,8 @@ export const log = (...args: ReadonlyArray): Effect.Effect => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * const users = [ @@ -529,7 +546,8 @@ export const table = (tabularData: any, properties?: ReadonlyArray): Eff * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Effect.scoped( @@ -567,7 +585,8 @@ export const time = (label?: string | undefined): Effect.Effect): Effect.Eff * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.trace("Debug trace point") @@ -626,7 +646,8 @@ export const trace = (...args: ReadonlyArray): Effect.Effect => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.warn("This feature is deprecated") @@ -653,7 +674,8 @@ export const warn = (...args: ReadonlyArray): Effect.Effect => * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.withGroup( @@ -711,7 +733,8 @@ export const withGroup = dual< * * @example * ```ts - * import { Console, Effect } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function* () { * yield* Console.withTime( diff --git a/packages/effect/src/LogLevel.ts b/packages/effect/src/logging/LogLevel.ts similarity index 91% rename from packages/effect/src/LogLevel.ts rename to packages/effect/src/logging/LogLevel.ts index 10e0009832..1ad0d481d6 100644 --- a/packages/effect/src/LogLevel.ts +++ b/packages/effect/src/logging/LogLevel.ts @@ -21,7 +21,8 @@ * ## Basic Usage * * ```ts - * import { LogLevel, Effect } from "effect" + * import { Effect } from "effect" + * import { LogLevel } from "effect/logging" * * // Basic log level usage * const program = Effect.gen(function* () { @@ -37,7 +38,7 @@ * ## Level Comparison * * ```ts - * import { LogLevel } from "effect" + * import { LogLevel } from "effect/logging" * * // Check if one level is more severe than another * console.log(LogLevel.greaterThan("Error", "Info")) // true @@ -51,7 +52,9 @@ * ## Filtering by Level * * ```ts - * import { LogLevel, Effect, Logger } from "effect" + * import { Effect } from "effect" + * import { LogLevel } from "effect/logging" + * import { Logger } from "effect/logging" * * // Create a logger that only logs Error and above * const errorLogger = Logger.make((options) => { @@ -78,7 +81,10 @@ * ## Runtime Configuration * * ```ts - * import { LogLevel, Effect, Logger, Config } from "effect" + * import { Effect } from "effect" + * import { Config } from "effect/config" + * import { LogLevel } from "effect/logging" + * import { Logger } from "effect/logging" * * // Configure log level from environment * const logLevelConfig = Config.string("LOG_LEVEL").pipe( @@ -96,8 +102,8 @@ * }) * ``` */ -import * as effect from "./internal/effect.ts" -import * as Ord from "./Order.ts" +import * as Ord from "../data/Order.ts" +import * as effect from "../internal/effect.ts" /** * Represents the severity level of a log message. @@ -114,7 +120,8 @@ import * as Ord from "./Order.ts" * * @example * ```ts - * import { LogLevel, Effect } from "effect" + * import { Effect } from "effect" + * import { LogLevel } from "effect/logging" * * // Using log levels with Effect logging * const program = Effect.gen(function* () { @@ -150,7 +157,8 @@ export const values: ReadonlyArray = ["All", "Fatal", "Error", "Warn", * * @example * ```ts - * import { LogLevel, Array } from "effect" + * import { Array } from "effect/collections" + * import { LogLevel } from "effect/logging" * * // Compare log levels using Order * console.log(LogLevel.Order("Error", "Info")) // 1 (Error > Info) @@ -171,7 +179,7 @@ export const Order: Ord.Order = effect.LogLevelOrder * * @example * ```ts - * import { LogLevel } from "effect" + * import { LogLevel } from "effect/logging" * * // Check if Error is more severe than Info * console.log(LogLevel.greaterThan("Error", "Info")) // true @@ -207,7 +215,8 @@ export const greaterThan: { * * @example * ```ts - * import { LogLevel, Logger } from "effect" + * import { LogLevel } from "effect/logging" + * import { Logger } from "effect/logging" * * // Check if level meets minimum threshold * console.log(LogLevel.greaterThanOrEqualTo("Error", "Error")) // true @@ -249,7 +258,7 @@ export const greaterThanOrEqualTo: { * * @example * ```ts - * import { LogLevel } from "effect" + * import { LogLevel } from "effect/logging" * * // Check if Debug is less severe than Info * console.log(LogLevel.lessThan("Debug", "Info")) // true @@ -285,7 +294,8 @@ export const lessThan: { * * @example * ```ts - * import { LogLevel, Logger } from "effect" + * import { LogLevel } from "effect/logging" + * import { Logger } from "effect/logging" * * // Check if level is at or below threshold * console.log(LogLevel.lessThanOrEqualTo("Info", "Info")) // true diff --git a/packages/effect/src/Logger.ts b/packages/effect/src/logging/Logger.ts similarity index 90% rename from packages/effect/src/Logger.ts rename to packages/effect/src/logging/Logger.ts index d2f71d8453..51679bb61a 100644 --- a/packages/effect/src/Logger.ts +++ b/packages/effect/src/logging/Logger.ts @@ -17,7 +17,8 @@ * ## Basic Usage * * ```ts - * import { Effect, Logger } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Basic logging * const program = Effect.gen(function* () { @@ -37,7 +38,8 @@ * ## Custom Loggers * * ```ts - * import { Effect, Logger, LogLevel } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Create a custom logger * const customLogger = Logger.make((options) => { @@ -58,7 +60,9 @@ * ## Multiple Loggers * * ```ts - * import { Effect, Logger, Layer } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { Logger } from "effect/logging" * * // Combine multiple loggers * const CombinedLoggerLive = Logger.layer([ @@ -74,7 +78,9 @@ * ## Batched Logging * * ```ts - * import { Effect, Logger, Duration } from "effect" + * import { Logger } from "effect/logging" + * import { Effect } from "effect" + * import { Duration } from "effect/time" * * const batchedLogger = Logger.batched(Logger.formatJson, { * window: Duration.seconds(5), @@ -97,30 +103,30 @@ * }) * ``` */ -import * as Array from "./Array.ts" -import type * as Cause from "./Cause.ts" -import type * as Duration from "./Duration.ts" -import type * as Effect from "./Effect.ts" -import type * as Fiber from "./Fiber.ts" -import { dual } from "./Function.ts" -import * as Inspectable from "./Inspectable.ts" -import { isEffect, withFiber } from "./internal/core.ts" -import * as effect from "./internal/effect.ts" -import * as Layer from "./Layer.ts" -import type * as LogLevel from "./LogLevel.ts" -import type { Pipeable } from "./Pipeable.ts" -import * as FileSystem from "./platform/FileSystem.ts" -import type { PlatformError } from "./platform/PlatformError.ts" -import * as Predicate from "./Predicate.ts" -import { CurrentLogAnnotations, CurrentLogSpans } from "./References.ts" -import type * as Scope from "./Scope.ts" -import * as ServiceMap from "./ServiceMap.ts" -import type * as Types from "./Types.ts" +import type * as Cause from "../Cause.ts" +import * as Array from "../collections/Array.ts" +import * as Predicate from "../data/Predicate.ts" +import type * as Effect from "../Effect.ts" +import { dual } from "../Function.ts" +import * as Inspectable from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { isEffect, withFiber } from "../internal/core.ts" +import * as effect from "../internal/effect.ts" +import type * as LogLevel from "../logging/LogLevel.ts" +import * as FileSystem from "../platform/FileSystem.ts" +import type { PlatformError } from "../platform/PlatformError.ts" +import type * as Scope from "../resources/Scope.ts" +import type * as Fiber from "../runtime/Fiber.ts" +import * as Layer from "../services/Layer.ts" +import { CurrentLogAnnotations, CurrentLogSpans } from "../services/References.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import type * as Duration from "../time/Duration.ts" +import type * as Types from "../types/Types.ts" /** * @example * ```ts - * import { Logger } from "effect" + * import { Logger } from "effect/logging" * * console.log(Logger.TypeId) // "~effect/Logger" * ``` @@ -133,7 +139,7 @@ export const TypeId: TypeId = "~effect/Logger" /** * @example * ```ts - * import { Logger } from "effect" + * import { Logger } from "effect/logging" * * // TypeId is used for type checking and identification * const logger = Logger.make(() => {}) @@ -148,7 +154,8 @@ export type TypeId = "~effect/Logger" /** * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Create a custom logger that accepts unknown messages and returns void * const stringLogger = Logger.make((options) => { @@ -176,7 +183,8 @@ export interface Logger extends Logger.Variance { @@ -199,7 +207,7 @@ export declare namespace Logger { /** * @example * ```ts - * import { Logger } from "effect" + * import { Logger } from "effect/logging" * * // Variance interface defines contravariance for Message and covariance for Output * const customLogger = Logger.make((options) => { @@ -220,7 +228,7 @@ export declare namespace Logger { /** * @example * ```ts - * import { Logger } from "effect" + * import { Logger } from "effect/logging" * * // VarianceStruct defines the actual variance structure used internally * // This structure ensures proper typing and variance behavior @@ -243,7 +251,9 @@ export declare namespace Logger { /** * @example * ```ts - * import { Logger, Effect, LogLevel } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" + * import { LogLevel } from "effect/logging" * * // Options interface provides all logging context * const detailedLogger = Logger.make((options) => { @@ -279,7 +289,7 @@ export declare namespace Logger { * * @example * ```ts - * import { Logger } from "effect" + * import { Logger } from "effect/logging" * * const myLogger = Logger.make((options) => { * console.log(options.message) @@ -298,7 +308,8 @@ export const isLogger = (u: unknown): u is Logger => Predicate /** * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Access current loggers from fiber context * const program = Effect.gen(function* () { @@ -329,7 +340,7 @@ export const CurrentLoggers: ServiceMap.Reference ({ @@ -375,7 +386,8 @@ export const map = dual< * * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Create a custom formatter * const customFormatter = Logger.make((options) => @@ -409,7 +421,8 @@ export const withConsoleLog = ( * * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Create an error-specific formatter * const errorFormatter = Logger.make((options) => @@ -450,7 +463,8 @@ export const withConsoleError = ( * * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * const formatter = Logger.make((options) => * `[${options.logLevel}] ${options.message}` @@ -560,8 +574,9 @@ const format = ( * * @example * ```ts - * import { Logger, Effect } from "effect" - * import { CurrentLogAnnotations } from "effect/References" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" + * import { CurrentLogAnnotations } from "effect/services/References" * * // Simple text logger * const textLogger = Logger.make((options) => @@ -602,7 +617,8 @@ export const make: ( * * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Use the default logger (automatically used by Effect runtime) * const program = Effect.gen(function* () { @@ -637,7 +653,8 @@ export const defaultLogger: Logger = effect.defaultLogger * * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Use the simple format logger * const simpleLoggerProgram = Effect.log("Hello Simple Format").pipe( @@ -672,7 +689,8 @@ export const formatSimple = effect.loggerMake(format(escapeDoubleQuotes)) * * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Use the logfmt format logger * const logfmtLoggerProgram = Effect.log("Hello LogFmt Format").pipe( @@ -713,7 +731,8 @@ export const formatLogFmt = effect.loggerMake(format(JSON.stringify, 0)) * * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Use the structured format logger * const structuredLoggerProgram = Effect.log("Hello Structured Format").pipe( @@ -789,7 +808,8 @@ export const formatStructured: Logger = withConsoleLog(formatLogFmt) * * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Use the console structured logger * const structuredProgram = Effect.log("Hello Structured Console").pipe( @@ -1078,7 +1103,8 @@ export const consoleStructured: Logger = withConsoleLog(formatStr * * @example * ```ts - * import { Logger, Effect } from "effect" + * import { Effect } from "effect" + * import { Logger } from "effect/logging" * * // Use the console JSON logger * const jsonProgram = Effect.log("Hello JSON Console").pipe( @@ -1126,7 +1152,9 @@ export const consoleJson: Logger = withConsoleLog(formatJson) * * @example * ```ts - * import { Logger, Effect, Layer } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { Logger } from "effect/logging" * * // Single logger layer * const JsonLoggerLive = Logger.layer([Logger.consoleJson]) @@ -1188,7 +1216,9 @@ export const layer = < * * ```ts * import { NodeFileSystem, NodeRuntime } from "@effect/platform-node" - * import { Effect, Layer, Logger } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { Logger } from "effect/logging" * * const fileLogger = Logger.formatJson.pipe( * Logger.toFile("/tmp/log.txt") @@ -1207,7 +1237,9 @@ export const layer = < * * @example * ```ts - * import { Logger, Effect, Duration } from "effect" + * import { Logger } from "effect/logging" + * import { Effect } from "effect" + * import { Duration } from "effect/time" * import { NodeFileSystem } from "@effect/platform-node" * * // Basic file logging diff --git a/packages/effect/src/logging/index.ts b/packages/effect/src/logging/index.ts new file mode 100644 index 0000000000..9b6d9ddc70 --- /dev/null +++ b/packages/effect/src/logging/index.ts @@ -0,0 +1,293 @@ +/** + * @since 4.0.0 + */ + +/** + * The `Console` module provides a functional interface for console operations within + * the Effect ecosystem. It offers type-safe logging, debugging, and console manipulation + * capabilities with built-in support for testing and environment isolation. + * + * ## Key Features + * + * - **Type-safe logging**: All console operations return Effects for composability + * - **Testable**: Mock console output for testing scenarios + * - **Service-based**: Integrated with Effect's dependency injection system + * - **Environment isolation**: Different console implementations per environment + * - **Rich API**: Support for all standard console methods (log, error, debug, etc.) + * - **Performance tracking**: Built-in timing and profiling capabilities + * + * ## Core Operations + * + * - **Basic logging**: `log`, `error`, `warn`, `info`, `debug` + * - **Assertions**: `assert` for conditional logging + * - **Grouping**: `group`, `groupCollapsed`, `groupEnd` for organized output + * - **Timing**: `time`, `timeEnd`, `timeLog` for performance measurement + * - **Data display**: `table`, `dir`, `dirxml` for structured data visualization + * - **Utilities**: `clear`, `count`, `countReset`, `trace` + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * + * // Basic logging + * const program = Effect.gen(function* () { + * yield* Console.log("Hello, World!") + * yield* Console.error("Something went wrong") + * yield* Console.warn("This is a warning") + * yield* Console.info("Information message") + * }) + * ``` + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * + * // Grouped logging with timing + * const debugProgram = Console.withGroup( + * Effect.gen(function* () { + * yield* Console.log("Step 1: Loading...") + * yield* Effect.sleep("100 millis") + * + * yield* Console.log("Step 2: Processing...") + * yield* Effect.sleep("200 millis") + * }), + * { label: "Processing Data" } + * ) + * ``` + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * + * // Data visualization and debugging + * const dataProgram = Effect.gen(function* () { + * const users = [ + * { id: 1, name: "Alice", age: 30 }, + * { id: 2, name: "Bob", age: 25 } + * ] + * + * yield* Console.table(users) + * yield* Console.dir(users[0], { depth: 2 }) + * yield* Console.assert(users.length > 0, "Users array should not be empty") + * }) + * ``` + * + * @since 2.0.0 + */ +export * as Console from "./Console.ts" + +/** + * @since 2.0.0 + * + * The `Logger` module provides a robust and flexible logging system for Effect applications. + * It offers structured logging, multiple output formats, and seamless integration with the + * Effect runtime's tracing and context management. + * + * ## Key Features + * + * - **Structured Logging**: Built-in support for structured log messages with metadata + * - **Multiple Formats**: JSON, LogFmt, Pretty, and custom formatting options + * - **Context Integration**: Automatic capture of fiber context, spans, and annotations + * - **Batching**: Efficient log aggregation and batch processing + * - **File Output**: Direct file writing with configurable batch windows + * - **Composable**: Transform and compose loggers using functional patterns + * + * ## Basic Usage + * + * ```ts + * import { Effect } from "effect" + * import { Logger } from "effect/logging" + * + * // Basic logging + * const program = Effect.gen(function* () { + * yield* Effect.log("Application started") + * yield* Effect.logInfo("Processing user request") + * yield* Effect.logWarning("Resource limit approaching") + * yield* Effect.logError("Database connection failed") + * }) + * + * // With structured data + * const structuredLog = Effect.gen(function* () { + * yield* Effect.log("User action", { userId: 123, action: "login" }) + * yield* Effect.logInfo("Request processed", { duration: 150, statusCode: 200 }) + * }) + * ``` + * + * ## Custom Loggers + * + * ```ts + * import { Effect } from "effect" + * import { Logger } from "effect/logging" + * + * // Create a custom logger + * const customLogger = Logger.make((options) => { + * console.log(`[${options.logLevel}] ${options.message}`) + * }) + * + * // Use JSON format for production + * const jsonLogger = Logger.consoleJson + * + * // Pretty format for development + * const prettyLogger = Logger.consolePretty() + * + * const program = Effect.log("Hello World").pipe( + * Effect.provide(Logger.layer([jsonLogger])) + * ) + * ``` + * + * ## Multiple Loggers + * + * ```ts + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { Logger } from "effect/logging" + * + * // Combine multiple loggers + * const CombinedLoggerLive = Logger.layer([ + * Logger.consoleJson, + * Logger.consolePretty() + * ]) + * + * const program = Effect.log("Application event").pipe( + * Effect.provide(CombinedLoggerLive) + * ) + * ``` + * + * ## Batched Logging + * + * ```ts + * import { Logger } from "effect/logging" + * import { Effect } from "effect" + * import { Duration } from "effect/time" + * + * const batchedLogger = Logger.batched(Logger.formatJson, { + * window: Duration.seconds(5), + * flush: (messages) => Effect.sync(() => { + * // Process batch of log messages + * console.log("Flushing", messages.length, "log entries") + * }) + * }) + * + * const program = Effect.gen(function* () { + * const logger = yield* batchedLogger + * yield* Effect.provide( + * Effect.all([ + * Effect.log("Event 1"), + * Effect.log("Event 2"), + * Effect.log("Event 3") + * ]), + * Logger.layer([logger]) + * ) + * }) + * ``` + */ +export * as Logger from "./Logger.ts" + +/** + * @since 2.0.0 + * + * The `LogLevel` module provides utilities for managing log levels in Effect applications. + * It defines a hierarchy of log levels and provides functions for comparing and filtering logs + * based on their severity. + * + * ## Log Level Hierarchy + * + * The log levels are ordered from most severe to least severe: + * + * 1. **All** - Special level that allows all messages + * 2. **Fatal** - System is unusable, immediate attention required + * 3. **Error** - Error conditions that should be investigated + * 4. **Warn** - Warning conditions that may indicate problems + * 5. **Info** - Informational messages about normal operation + * 6. **Debug** - Debug information useful during development + * 7. **Trace** - Very detailed trace information + * 8. **None** - Special level that suppresses all messages + * + * ## Basic Usage + * + * ```ts + * import { Effect } from "effect" + * import { LogLevel } from "effect/logging" + * + * // Basic log level usage + * const program = Effect.gen(function* () { + * yield* Effect.logFatal("System is shutting down") + * yield* Effect.logError("Database connection failed") + * yield* Effect.logWarning("Memory usage is high") + * yield* Effect.logInfo("User logged in") + * yield* Effect.logDebug("Processing request") + * yield* Effect.logTrace("Variable value: xyz") + * }) + * ``` + * + * ## Level Comparison + * + * ```ts + * import { LogLevel } from "effect/logging" + * + * // Check if one level is more severe than another + * console.log(LogLevel.greaterThan("Error", "Info")) // true + * console.log(LogLevel.greaterThan("Debug", "Error")) // false + * + * // Check if level meets minimum threshold + * console.log(LogLevel.greaterThanOrEqualTo("Info", "Debug")) // true + * console.log(LogLevel.lessThan("Trace", "Info")) // true + * ``` + * + * ## Filtering by Level + * + * ```ts + * import { Effect } from "effect" + * import { LogLevel } from "effect/logging" + * import { Logger } from "effect/logging" + * + * // Create a logger that only logs Error and above + * const errorLogger = Logger.make((options) => { + * if (LogLevel.greaterThanOrEqualTo(options.logLevel, "Error")) { + * console.log(`[${options.logLevel}] ${options.message}`) + * } + * }) + * + * // Production logger - Info and above + * const productionLogger = Logger.make((options) => { + * if (LogLevel.greaterThanOrEqualTo(options.logLevel, "Info")) { + * console.log(`${options.date.toISOString()} [${options.logLevel}] ${options.message}`) + * } + * }) + * + * // Development logger - Debug and above + * const devLogger = Logger.make((options) => { + * if (LogLevel.greaterThanOrEqualTo(options.logLevel, "Debug")) { + * console.log(`[${options.logLevel}] ${options.message}`) + * } + * }) + * ``` + * + * ## Runtime Configuration + * + * ```ts + * import { Effect } from "effect" + * import { Config } from "effect/config" + * import { LogLevel } from "effect/logging" + * import { Logger } from "effect/logging" + * + * // Configure log level from environment + * const logLevelConfig = Config.string("LOG_LEVEL").pipe( + * Config.withDefault("Info") + * ) + * + * const configurableLogger = Effect.gen(function* () { + * const minLevel = yield* logLevelConfig + * + * return Logger.make((options) => { + * if (LogLevel.greaterThanOrEqualTo(options.logLevel, minLevel)) { + * console.log(`[${options.logLevel}] ${options.message}`) + * } + * }) + * }) + * ``` + */ +export * as LogLevel from "./LogLevel.ts" diff --git a/packages/effect/src/logging/index.ts.tpl b/packages/effect/src/logging/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/logging/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/Match.ts b/packages/effect/src/match/Match.ts similarity index 96% rename from packages/effect/src/Match.ts rename to packages/effect/src/match/Match.ts index 052c7a3b18..78a2c71f51 100644 --- a/packages/effect/src/Match.ts +++ b/packages/effect/src/match/Match.ts @@ -26,13 +26,13 @@ * * @since 4.0.0 */ -import * as internal from "./internal/matcher.ts" -import type * as Option from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import * as Predicate from "./Predicate.ts" -import type * as Result from "./Result.ts" -import type * as T from "./Types.ts" -import type { Unify } from "./Unify.ts" +import type * as Option from "../data/Option.ts" +import * as Predicate from "../data/Predicate.ts" +import type * as Result from "../data/Result.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import * as internal from "../internal/matcher.ts" +import type * as T from "../types/Types.ts" +import type { Unify } from "../types/Unify.ts" /** * Unique identifier for `Matcher` instances. @@ -42,7 +42,7 @@ import type { Unify } from "./Unify.ts" * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // The MatcherTypeId is used internally for type checking * const matcher = Match.type() @@ -64,7 +64,7 @@ export const MatcherTypeId: MatcherTypeId = internal.TypeId * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // MatcherTypeId is used in the internal type structure * type MyMatcher = { @@ -95,7 +95,7 @@ export type MatcherTypeId = "~effect/Match/Matcher" * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Simulated dynamic input that can be a string or a number * const input: string | number = "some input" @@ -132,7 +132,7 @@ export type Matcher().pipe( @@ -170,7 +170,7 @@ export interface TypeMatcher().pipe( @@ -269,7 +269,7 @@ export interface When { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Not creates cases that exclude specific patterns * const matcher = Match.type().pipe( @@ -304,7 +304,7 @@ export interface Not { * @example (Matching Numbers and Strings) * * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Create a matcher for values that are either strings or numbers * // @@ -349,7 +349,7 @@ export const type: () => Matcher, I, never, never> = * @example (Matching an Object by Property) * * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const input = { name: "John", age: 30 } * @@ -386,7 +386,7 @@ export const value: ( * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * type Status = { readonly _tag: "Success"; readonly data: string } * @@ -427,7 +427,7 @@ export const valueTags: { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * type Result = * | { readonly _tag: "Success"; readonly data: string } @@ -497,7 +497,7 @@ export const typeTags: { * @example (Validating Return Type Consistency) * * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const match = Match.type<{ a: number } | { b: string }>().pipe( * // Ensure all branches return a string @@ -536,7 +536,7 @@ export const withReturnType: () => ( * @example (Matching with Values and Predicates) * * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Create a matcher for objects with an "age" property * const match = Match.type<{ age: number }>().pipe( @@ -600,7 +600,7 @@ export const when: < * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * type ErrorType = * | { readonly _tag: "NetworkError"; readonly message: string } @@ -661,7 +661,7 @@ export const whenOr: < * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * type User = { readonly age: number; readonly role: "admin" | "user" } * @@ -714,7 +714,8 @@ export const whenAnd: < * * @example * ```ts - * import { Match, pipe } from "effect" + * import { pipe } from "effect" + * import { Match } from "effect/match" * * const match = pipe( * Match.type<{ type: "A"; a: string } | { type: "B"; b: number } | { type: "C"; c: boolean }>(), @@ -759,7 +760,8 @@ export const discriminator: ( * * @example * ```ts - * import { Match, pipe } from "effect" + * import { pipe } from "effect" + * import { Match } from "effect/match" * * const match = pipe( * Match.type<{ type: "A" } | { type: "B" } | { type: "A.A" } | {}>(), @@ -807,7 +809,8 @@ export const discriminatorStartsWith: ( * * @example * ```ts - * import { Match, pipe } from "effect" + * import { pipe } from "effect" + * import { Match } from "effect/match" * * const match = pipe( * Match.type<{ type: "A"; a: string } | { type: "B"; b: number } | { type: "C"; c: boolean }>(), @@ -861,7 +864,8 @@ export const discriminators: ( * * @example * ```ts - * import { Match, pipe } from "effect" + * import { pipe } from "effect" + * import { Match } from "effect/match" * * const match = pipe( * Match.type<{ type: "A"; a: string } | { type: "B"; b: number } | { type: "C"; c: boolean }>(), @@ -905,7 +909,7 @@ export const discriminatorsExhaustive: ( * @example (Matching a Discriminated Union by Tag) * * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * type Event = * | { readonly _tag: "fetch" } @@ -963,7 +967,8 @@ export const tag: < * * @example ```ts - * import { Match, pipe } from "effect" + * import { pipe } from "effect" + * import { Match } from "effect/match" * * const match = pipe( * Match.type<{ _tag: "A" } | { _tag: "B" } | { _tag: "A.A" } | {}>(), @@ -1012,7 +1017,8 @@ export const tagStartsWith: < * * @example * ```ts - * import { Match, pipe } from "effect" + * import { pipe } from "effect" + * import { Match } from "effect/match" * * const match = pipe( * Match.type<{ _tag: "A"; a: string } | { _tag: "B"; b: number } | { _tag: "C"; c: boolean }>(), @@ -1061,7 +1067,8 @@ export const tags: < * * @example * ```ts - * import { Match, pipe } from "effect" + * import { pipe } from "effect" + * import { Match } from "effect/match" * * const match = pipe( * Match.type<{ _tag: "A"; a: string } | { _tag: "B"; b: number } | { _tag: "C"; c: boolean }>(), @@ -1103,7 +1110,7 @@ export const tagsExhaustive: < * @example (Ignoring a Specific Value) * * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Create a matcher for string or number values * const match = Match.type().pipe( @@ -1150,7 +1157,7 @@ export const not: < * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const processInput = Match.type() * .pipe( @@ -1181,7 +1188,7 @@ export const nonEmptyString: SafeRefinement = internal.nonEmptySt * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const handleStatus = Match.type() * .pipe( @@ -1222,7 +1229,7 @@ export const is: < * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const processValue = Match.type().pipe( * Match.when(Match.string, (str) => `String: ${str.toUpperCase()}`), @@ -1250,7 +1257,7 @@ export const string: Predicate.Refinement = Predicate.isString * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const categorizeNumber = Match.type().pipe( * Match.when(Match.number, (num) => { @@ -1282,7 +1289,7 @@ export const number: Predicate.Refinement = Predicate.isNumber * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const describeValue = Match.type() * .pipe( @@ -1319,7 +1326,7 @@ export const any: SafeRefinement = internal.any * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const processValue = Match.type() * .pipe( @@ -1359,7 +1366,7 @@ export const defined: (u: A) => u is A & {} = internal.defined * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const describeTruthiness = Match.type().pipe( * Match.when(Match.boolean, (bool) => @@ -1412,7 +1419,7 @@ export { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const processLargeNumber = Match.type().pipe( * Match.when(Match.bigint, (big) => { @@ -1445,7 +1452,7 @@ export const bigint: Predicate.Refinement = Predicate.isBigInt * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const mySymbol = Symbol("my-symbol") * const globalSymbol = Symbol.for("global-symbol") @@ -1480,7 +1487,7 @@ export const symbol: Predicate.Refinement = Predicate.isSymbol * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const processDateValue = Match.type().pipe( * Match.when(Match.date, (date) => { @@ -1514,7 +1521,7 @@ export const date: Predicate.Refinement = Predicate.isDate * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const analyzeValue = Match.type().pipe( * Match.when(Match.record, (obj) => { @@ -1550,7 +1557,7 @@ export const record: Predicate.Refinement any>( * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * class CustomError extends Error { * constructor(message: string, public code: number) { @@ -1643,7 +1650,7 @@ export const instanceOfUnsafe: any>( * @example (Providing a Default Value When No Patterns Match) * * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Create a matcher for string or number values * const match = Match.type().pipe( @@ -1685,7 +1692,7 @@ export const orElse: Ret>( * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * const strictMatcher = Match.type<"a" | "b">().pipe( * Match.when("a", () => "Found A"), @@ -1726,7 +1733,7 @@ export const orElseAbsurd: ( * @example (Extracting a User Role with `Match.result`) * * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * type User = { readonly role: "admin" | "editor" | "viewer" } * @@ -1767,7 +1774,7 @@ export const result: ( * @example (Extracting a User Role with `Match.option`) * * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * type User = { readonly role: "admin" | "editor" | "viewer" } * @@ -1801,7 +1808,7 @@ export const option: ( * @example (Ensuring All Cases Are Covered) * * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Create a matcher for string or number values * const match = Match.type().pipe( @@ -1830,7 +1837,7 @@ export const exhaustive: ( * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // SafeRefinement predicates carry this identifier * const customPredicate = Match.string @@ -1854,7 +1861,7 @@ export const SafeRefinementId: SafeRefinementId = "~effect/SafeRefinement" * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // SafeRefinementId is used in the type structure * type MySafeRefinement = { @@ -1876,7 +1883,7 @@ export type SafeRefinementId = "~effect/SafeRefinement" * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Built-in safe refinements * const processValue = Match.type().pipe( @@ -1912,7 +1919,7 @@ type Fail = typeof Fail * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Most users won't need to use Types directly, but it powers the type system: * type MyPattern = Match.Types.PatternBase<{ name: string; age: number }> @@ -1939,7 +1946,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // WhenMatch computes the narrowed type after pattern matching * type StringMatch = Match.Types.WhenMatch @@ -1978,7 +1985,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // NotMatch computes what remains after exclusion * type NotString = Match.Types.NotMatch @@ -2005,7 +2012,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // PForMatch resolves patterns to their matched types * type StringPattern = Match.Types.PForMatch @@ -2030,7 +2037,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // PForExclude computes what to exclude from type operations * type ExcludeString = Match.Types.PForExclude @@ -2092,7 +2099,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // PatternBase enables complex object patterns * type UserPattern = Match.Types.PatternBase<{ @@ -2127,7 +2134,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // PatternPrimitive includes various pattern types: * @@ -2157,7 +2164,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Without is used internally when you write: * Match.type().pipe( @@ -2184,7 +2191,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // Only is used internally when you write: * Match.type().pipe( @@ -2211,7 +2218,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // AddWithout is used when combining multiple exclusions: * Match.type().pipe( @@ -2238,7 +2245,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // AddOnly is used when refining positive matches: * Match.type<{ type: "user" | "admin"; name: string }>().pipe( @@ -2266,7 +2273,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * // ApplyFilters computes the final narrowed type: * type Result = Match.Types.ApplyFilters< @@ -2298,7 +2305,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * type Events = * | { _tag: "click"; x: number; y: number } @@ -2329,7 +2336,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * type Combined = Match.Types.ArrayToIntersection<[ * { name: string }, @@ -2360,7 +2367,7 @@ export declare namespace Types { * * @example * ```ts - * import { Match } from "effect" + * import { Match } from "effect/match" * * type StringExtract = Match.Types.ExtractMatch< * string | number | boolean, diff --git a/packages/effect/src/match/index.ts b/packages/effect/src/match/index.ts new file mode 100644 index 0000000000..7b2fc45718 --- /dev/null +++ b/packages/effect/src/match/index.ts @@ -0,0 +1,33 @@ +/** + * @since 4.0.0 + */ + +/** + * The `effect/match` module provides a type-safe pattern matching system for + * TypeScript. Inspired by functional programming, it simplifies conditional + * logic by replacing verbose if/else or switch statements with a structured and + * expressive API. + * + * This module supports matching against types, values, and discriminated unions + * while enforcing exhaustiveness checking to ensure all cases are handled. + * + * Although pattern matching is not yet a native JavaScript feature, + * `effect/match` offers a reliable implementation that is available today. + * + * **How Pattern Matching Works** + * + * Pattern matching follows a structured process: + * + * - **Creating a matcher**: Define a `Matcher` that operates on either a + * specific `Match.type` or `Match.value`. + * + * - **Defining patterns**: Use combinators such as `Match.when`, `Match.not`, + * and `Match.tag` to specify matching conditions. + * + * - **Completing the match**: Apply a finalizer such as `Match.exhaustive`, + * `Match.orElse`, or `Match.option` to determine how unmatched cases should + * be handled. + * + * @since 4.0.0 + */ +export * as Match from "./Match.ts" diff --git a/packages/effect/src/match/index.ts.tpl b/packages/effect/src/match/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/match/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/Metric.ts b/packages/effect/src/observability/Metric.ts similarity index 94% rename from packages/effect/src/Metric.ts rename to packages/effect/src/observability/Metric.ts index 9d6df8b714..071942e96c 100644 --- a/packages/effect/src/Metric.ts +++ b/packages/effect/src/observability/Metric.ts @@ -39,7 +39,8 @@ * ## Basic Usage * * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * // Create metrics * const requestCount = Metric.counter("http_requests_total", { @@ -68,7 +69,8 @@ * ## Attributes and Tagging * * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * const requestCount = Metric.counter("requests", { * description: "Number of requests by endpoint and method" @@ -96,7 +98,9 @@ * ## Advanced Examples * * ```ts - * import { Effect, Metric, Schedule } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Schedule } from "effect/scheduling" * * // Business metrics * const userSignups = Metric.counter("user_signups_total") @@ -137,22 +141,22 @@ * ``` */ -import * as Arr from "./Array.ts" -import * as Duration from "./Duration.ts" -import type { Effect } from "./Effect.ts" -import type { Exit } from "./Exit.ts" -import { constUndefined, dual } from "./Function.ts" -import * as InternalEffect from "./internal/effect.ts" -import * as InternalMetric from "./internal/metric.ts" -import * as Layer from "./Layer.ts" -import * as Option from "./Option.ts" -import * as Order from "./Order.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" -import * as Predicate from "./Predicate.ts" -import * as ServiceMap from "./ServiceMap.ts" -import * as _String from "./String.ts" -import type { Contravariant, Covariant } from "./Types.ts" +import * as Arr from "../collections/Array.ts" +import * as Option from "../data/Option.ts" +import * as Order from "../data/Order.ts" +import * as Predicate from "../data/Predicate.ts" +import type { Effect } from "../Effect.ts" +import type { Exit } from "../Exit.ts" +import { constUndefined, dual } from "../Function.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import * as InternalEffect from "../internal/effect.ts" +import * as InternalMetric from "../internal/metric.ts" +import * as _String from "../primitives/String.ts" +import * as Layer from "../services/Layer.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import * as Duration from "../time/Duration.ts" +import type { Contravariant, Covariant } from "../types/Types.ts" /** * A `Metric` represents a concurrent metric which accepts update @@ -173,7 +177,9 @@ import type { Contravariant, Covariant } from "./Types.ts" * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class MetricExample extends Data.TaggedError("MetricExample")<{ * readonly operation: string @@ -241,7 +247,9 @@ export interface Metric extends Pipeable { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class CounterInterfaceError extends Data.TaggedError("CounterInterfaceError")<{ * readonly operation: string @@ -290,7 +298,9 @@ export interface Counter extends Metric { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class FrequencyInterfaceError extends Data.TaggedError("FrequencyInterfaceError")<{ * readonly operation: string @@ -428,7 +440,9 @@ export interface Frequency extends Metric {} * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class FrequencyStateError extends Data.TaggedError("FrequencyStateError")<{ * readonly operation: string @@ -511,7 +525,9 @@ export interface FrequencyState { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class GaugeInterfaceError extends Data.TaggedError("GaugeInterfaceError")<{ * readonly operation: string @@ -562,7 +578,9 @@ export interface Gauge extends Metric { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class HistogramInterfaceError extends Data.TaggedError("HistogramInterfaceError")<{ * readonly operation: string @@ -696,7 +716,9 @@ export interface Histogram extends Metric {} * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class HistogramStateError extends Data.TaggedError("HistogramStateError")<{ * readonly operation: string @@ -788,7 +810,9 @@ export interface HistogramState { * * @example * ```ts - * import { Metric, Effect, Data, Option } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data, Option } from "effect/data" * * class SummaryInterfaceError extends Data.TaggedError("SummaryInterfaceError")<{ * readonly operation: string @@ -869,7 +893,9 @@ export interface Summary extends Metric {} * * @example * ```ts - * import { Metric, Effect, Data, Option } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data, Option } from "effect/data" * * class SummaryStateError extends Data.TaggedError("SummaryStateError")<{ * readonly operation: string @@ -951,7 +977,9 @@ export interface SummaryState { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class MetricsError extends Data.TaggedError("MetricsError")<{ * readonly operation: string @@ -996,7 +1024,9 @@ export declare namespace Metric { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class MetricTypeError extends Data.TaggedError("MetricTypeError")<{ * readonly operation: string @@ -1064,7 +1094,9 @@ export declare namespace Metric { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class AttributesError extends Data.TaggedError("AttributesError")<{ * readonly operation: string @@ -1136,7 +1168,9 @@ export declare namespace Metric { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class AttributeSetError extends Data.TaggedError("AttributeSetError")<{ * readonly operation: string @@ -1213,7 +1247,7 @@ export declare namespace Metric { * * @example * ```ts - * import { Metric } from "effect" + * import { Metric } from "effect/observability" * * // Create various metric types * const numberCounter = Metric.counter("requests") @@ -1263,7 +1297,8 @@ export declare namespace Metric { * * @example * ```ts - * import { Metric, Effect } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * // Create various metric types * const requestCounter = Metric.counter("requests") @@ -1322,7 +1357,9 @@ export declare namespace Metric { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class HooksError extends Data.TaggedError("HooksError")<{ * readonly operation: string @@ -1370,7 +1407,9 @@ export declare namespace Metric { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class MetadataError extends Data.TaggedError("MetadataError")<{ * readonly operation: string @@ -1437,7 +1476,9 @@ export declare namespace Metric { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class SnapshotProtoError extends Data.TaggedError("SnapshotProtoError")<{ * readonly operation: string @@ -1505,7 +1546,9 @@ export declare namespace Metric { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class SnapshotError extends Data.TaggedError("SnapshotError")<{ * readonly operation: string @@ -1578,7 +1621,10 @@ export declare namespace Metric { * * @example * ```ts - * import { Metric, Effect, Layer, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Layer } from "effect/services" + * import { Data } from "effect/data" * * class AttributesKeyError extends Data.TaggedError("AttributesKeyError")<{ * readonly operation: string @@ -1628,7 +1674,10 @@ export const CurrentMetricAttributesKey = "effect/Metric/CurrentMetricAttributes * * @example * ```ts - * import { Metric, Effect, Layer, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Layer } from "effect/services" + * import { Data } from "effect/data" * * class AttributesError extends Data.TaggedError("AttributesError")<{ * readonly operation: string @@ -2052,7 +2101,7 @@ class MetricTransform extends Metric$ => * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class CounterError extends Data.TaggedError("CounterError")<{ * readonly operation: string @@ -2164,7 +2215,9 @@ export const counter: { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class GaugeError extends Data.TaggedError("GaugeError")<{ * readonly operation: string @@ -2241,7 +2294,9 @@ export const gauge: { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class FrequencyError extends Data.TaggedError("FrequencyError")<{ * readonly operation: string @@ -2320,7 +2375,9 @@ export const frequency = (name: string, options?: { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class HistogramError extends Data.TaggedError("HistogramError")<{ * readonly operation: string @@ -2399,7 +2456,10 @@ export const histogram = (name: string, options: { * * @example * ```ts - * import { Metric, Effect, Duration, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Duration } from "effect/time" + * import { Data } from "effect/data" * * class SummaryError extends Data.TaggedError("SummaryError")<{ * readonly operation: string @@ -2487,7 +2547,7 @@ export const summary = (name: string, options: { * * @example * ```ts - * import { Metric } from "effect" + * import { Metric } from "effect/observability" * * const responseTimesSummary = Metric.summaryWithTimestamp("response_times_summary", { * description: "Measures the distribution of response times", @@ -2520,7 +2580,10 @@ export const summaryWithTimestamp = (name: string, options: { * * @example * ```ts - * import { Metric, Effect, Duration, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Duration } from "effect/time" + * import { Data } from "effect/data" * * class TimerError extends Data.TaggedError("TimerError")<{ * readonly operation: string @@ -2572,7 +2635,8 @@ export const timer = (name: string, options?: { * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * const requestCounter = Metric.counter("requests") * const responseTime = Metric.histogram("response_time", { @@ -2621,7 +2685,8 @@ export const value = ( * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * const temperatureGauge = Metric.gauge("temperature") * const requestCounter = Metric.counter("requests") @@ -2673,7 +2738,8 @@ export const modify: { * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * const cpuUsage = Metric.gauge("cpu_usage_percent") * const httpStatus = Metric.frequency("http_status_codes") @@ -2729,7 +2795,9 @@ export const update: { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class MetricError extends Data.TaggedError("MetricError")<{ * readonly operation: string @@ -2794,7 +2862,9 @@ export const mapInput: { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class MetricError extends Data.TaggedError("MetricError")<{ * readonly operation: string @@ -2839,7 +2909,8 @@ export const withConstantInput: { * * @example * ```ts - * import { Effect, Metric } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" * * const requestCounter = Metric.counter("http_requests_total", { * description: "Total HTTP requests" @@ -2912,7 +2983,11 @@ export const withAttributes: { * * @example * ```ts - * import { Metric, Effect, Layer, Console, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Layer } from "effect/services" + * import { Console } from "effect/logging" + * import { Data } from "effect/data" * * class SnapshotError extends Data.TaggedError("SnapshotError")<{ * readonly operation: string @@ -2967,7 +3042,11 @@ export const snapshot: Effect> = InternalEffect.m * * @example * ```ts - * import { Metric, Effect, Layer, Console, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Layer } from "effect/services" + * import { Console } from "effect/logging" + * import { Data } from "effect/data" * * class DumpError extends Data.TaggedError("DumpError")<{ * readonly operation: string @@ -3056,7 +3135,9 @@ export const dump: Effect = InternalEffect.flatMap(InternalEffect.servic * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class UnsafeSnapshotError extends Data.TaggedError("UnsafeSnapshotError")<{ * readonly operation: string @@ -3187,7 +3268,9 @@ const attributesToString = (attributes: Metric.AttributeSet): string => { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class BoundaryError extends Data.TaggedError("BoundaryError")<{ * readonly operation: string @@ -3241,7 +3324,9 @@ export const boundariesFromIterable = (iterable: Iterable): ReadonlyArra * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class BoundaryError extends Data.TaggedError("BoundaryError")<{ * readonly operation: string @@ -3292,7 +3377,9 @@ export const linearBoundaries = (options: { * * @example * ```ts - * import { Metric, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" * * class BoundaryError extends Data.TaggedError("BoundaryError")<{ * readonly operation: string @@ -3364,7 +3451,10 @@ const fiberFailures = counter("child_fiber_failures", { * * @example * ```ts - * import { Metric, Effect, Layer, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Layer } from "effect/services" + * import { Data } from "effect/data" * * class MetricsError extends Data.TaggedError("MetricsError")<{ * readonly operation: string @@ -3401,7 +3491,11 @@ export const FiberRuntimeMetricsKey: typeof InternalMetric.FiberRuntimeMetricsKe * * @example * ```ts - * import { Metric, Effect, ServiceMap, Data, Layer } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Data } from "effect/data" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * import type { Exit } from "effect/Exit" * * class MetricsError extends Data.TaggedError("MetricsError")<{ @@ -3441,7 +3535,10 @@ export interface FiberRuntimeMetricsService { * * @example * ```ts - * import { Metric, Effect, Layer, Data } from "effect" + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Layer } from "effect/services" + * import { Data } from "effect/data" * * class MetricsError extends Data.TaggedError("MetricsError")<{ * readonly operation: string @@ -3491,7 +3588,10 @@ export const FiberRuntimeMetrics = ServiceMap.Reference(self: Effect) => Effect { @@ -103,7 +107,7 @@ export type AnySpan = Span | ExternalSpan * @category tags * @example * ```ts - * import { Tracer } from "effect" + * import { Tracer } from "effect/observability" * * // The key used to identify parent spans in the service map * console.log(Tracer.ParentSpanKey) // "effect/Tracer/ParentSpan" @@ -116,7 +120,8 @@ export const ParentSpanKey = "effect/Tracer/ParentSpan" * @category tags * @example * ```ts - * import { Tracer, Effect } from "effect" + * import { Effect } from "effect" + * import { Tracer } from "effect/observability" * * // Access the parent span from the context * const program = Effect.gen(function* () { @@ -132,7 +137,8 @@ export class ParentSpan extends ServiceMap.Key()(ParentSpan * @category models * @example * ```ts - * import { Tracer, ServiceMap } from "effect" + * import { Tracer } from "effect/observability" + * import { ServiceMap } from "effect/services" * * // Create an external span from another tracing system * const externalSpan: Tracer.ExternalSpan = { @@ -159,7 +165,8 @@ export interface ExternalSpan { * @category models * @example * ```ts - * import { Tracer, Effect } from "effect" + * import { Effect } from "effect" + * import { Tracer } from "effect/observability" * * // Create an effect with span options * const options: Tracer.SpanOptions = { @@ -189,7 +196,8 @@ export interface SpanOptions { * @category models * @example * ```ts - * import { Tracer, Effect } from "effect" + * import { Effect } from "effect" + * import { Tracer } from "effect/observability" * * // Different span kinds for different operations * const serverSpan = Effect.withSpan("handle-request", { @@ -245,7 +253,8 @@ export interface Span { * @category models * @example * ```ts - * import { Tracer, Effect } from "effect" + * import { Effect } from "effect" + * import { Tracer } from "effect/observability" * * // Create a span link to connect spans * const externalSpan = Tracer.externalSpan({ @@ -273,7 +282,9 @@ export interface SpanLink { * @category constructors * @example * ```ts - * import { Tracer, Option, ServiceMap } from "effect" + * import { Tracer } from "effect/observability" + * import { ServiceMap } from "effect/services" + * import { Option } from "effect/data" * * // Create a custom tracer with logging * const loggingTracer = Tracer.make({ @@ -295,7 +306,8 @@ export const make = (options: Tracer): Tracer => options * @category constructors * @example * ```ts - * import { Tracer, Effect } from "effect" + * import { Effect } from "effect" + * import { Tracer } from "effect/observability" * * // Create an external span from another tracing system * const span = Tracer.externalSpan({ @@ -330,7 +342,8 @@ export const externalSpan = ( * @category references * @example * ```ts - * import { Tracer, Effect } from "effect" + * import { Effect } from "effect" + * import { Tracer } from "effect/observability" * * // Disable span propagation for a specific effect * const program = Effect.gen(function* () { @@ -356,7 +369,8 @@ export const TracerKey = "effect/Tracer" * @category references * @example * ```ts - * import { Tracer, Effect } from "effect" + * import { Effect } from "effect" + * import { Tracer } from "effect/observability" * * // Access the current tracer from the context * const program = Effect.gen(function* () { @@ -391,7 +405,9 @@ export const Tracer: ServiceMap.Reference = ServiceMap.Reference * @category native tracer * @example * ```ts - * import { Tracer, Option, ServiceMap } from "effect" + * import { Tracer } from "effect/observability" + * import { ServiceMap } from "effect/services" + * import { Option } from "effect/data" * * // Create a native span directly * const span = new Tracer.NativeSpan( diff --git a/packages/effect/src/observability/index.ts b/packages/effect/src/observability/index.ts new file mode 100644 index 0000000000..7d18c2fe6c --- /dev/null +++ b/packages/effect/src/observability/index.ts @@ -0,0 +1,152 @@ +/** + * @since 4.0.0 + */ + +/** + * @since 2.0.0 + * + * The `Metric` module provides a comprehensive system for collecting, aggregating, and observing + * application metrics in Effect applications. It offers type-safe, concurrent metrics that can + * be used to monitor performance, track business metrics, and gain insights into application behavior. + * + * ## Key Features + * + * - **Five Metric Types**: Counters, Gauges, Frequencies, Histograms, and Summaries + * - **Type Safety**: Fully typed metrics with compile-time guarantees + * - **Concurrency Safe**: Thread-safe metrics that work with Effect's concurrency model + * - **Attributes**: Tag metrics with key-value attributes for filtering and grouping + * - **Snapshots**: Take point-in-time snapshots of all metrics for reporting + * - **Runtime Integration**: Automatic fiber runtime metrics collection + * + * ## Metric Types + * + * ### Counter + * Tracks cumulative values that only increase or can be reset to zero. + * Perfect for counting events, requests, errors, etc. + * + * ### Gauge + * Represents a single numerical value that can go up or down. + * Ideal for current resource usage, temperature, queue sizes, etc. + * + * ### Frequency + * Counts occurrences of discrete string values. + * Useful for tracking categorical data like HTTP status codes, user actions, etc. + * + * ### Histogram + * Records observations in configurable buckets to analyze distribution. + * Great for response times, request sizes, and other measured values. + * + * ### Summary + * Calculates quantiles over a sliding time window. + * Provides statistical insights into value distributions over time. + * + * ## Basic Usage + * + * ```ts + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * + * // Create metrics + * const requestCount = Metric.counter("http_requests_total", { + * description: "Total number of HTTP requests" + * }) + * + * const responseTime = Metric.histogram("http_response_time", { + * description: "HTTP response time in milliseconds", + * boundaries: Metric.linearBoundaries({ start: 0, width: 50, count: 20 }) + * }) + * + * // Use metrics in your application + * const handleRequest = Effect.gen(function* () { + * yield* Metric.update(requestCount, 1) + * + * const startTime = yield* Effect.clockWith(clock => clock.currentTimeMillis) + * + * // Process request... + * yield* Effect.sleep("100 millis") + * + * const endTime = yield* Effect.clockWith(clock => clock.currentTimeMillis) + * yield* Metric.update(responseTime, endTime - startTime) + * }) + * ``` + * + * ## Attributes and Tagging + * + * ```ts + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * + * const requestCount = Metric.counter("requests", { + * description: "Number of requests by endpoint and method" + * }) + * + * const program = Effect.gen(function* () { + * // Add attributes to metrics + * yield* Metric.update( + * Metric.withAttributes(requestCount, { + * endpoint: "/api/users", + * method: "GET" + * }), + * 1 + * ) + * + * // Or use withAttributes for compile-time attributes + * const taggedCounter = Metric.withAttributes(requestCount, { + * endpoint: "/api/posts", + * method: "POST" + * }) + * yield* Metric.update(taggedCounter, 1) + * }) + * ``` + * + * ## Advanced Examples + * + * ```ts + * import { Effect } from "effect" + * import { Metric } from "effect/observability" + * import { Schedule } from "effect/scheduling" + * + * // Business metrics + * const userSignups = Metric.counter("user_signups_total") + * const activeUsers = Metric.gauge("active_users_current") + * const featureUsage = Metric.frequency("feature_usage") + * + * // Performance metrics + * const dbQueryTime = Metric.summary("db_query_duration", { + * maxAge: "5 minutes", + * maxSize: 1000, + * quantiles: [0.5, 0.9, 0.95, 0.99] + * }) + * + * const program = Effect.gen(function* () { + * // Track user signup + * yield* Metric.update(userSignups, 1) + * + * // Update active user count + * yield* Metric.update(activeUsers, 1250) + * + * // Record feature usage + * yield* Metric.update(featureUsage, "dashboard_view") + * + * // Measure database query time + * yield* Effect.timed(performDatabaseQuery).pipe( + * Effect.tap(([duration]) => Metric.update(dbQueryTime, duration)) + * ) + * }) + * + * // Get metric snapshots + * const getMetrics = Effect.gen(function* () { + * const snapshots = yield* Metric.snapshot + * + * for (const metric of snapshots) { + * console.log(`${metric.id}: ${JSON.stringify(metric.state)}`) + * } + * }) + * ``` + */ +export * as Metric from "./Metric.ts" + +/** + * @since 2.0.0 + */ +export * as Tracer from "./Tracer.ts" diff --git a/packages/effect/src/observability/index.ts.tpl b/packages/effect/src/observability/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/observability/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/platform/FileSystem.ts b/packages/effect/src/platform/FileSystem.ts index 17b2770d13..6e9f1dadc7 100644 --- a/packages/effect/src/platform/FileSystem.ts +++ b/packages/effect/src/platform/FileSystem.ts @@ -9,7 +9,8 @@ * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * import { FileSystem } from "effect/platform" * * const program = Effect.gen(function* () { @@ -36,18 +37,18 @@ * * @since 4.0.0 */ -import * as Arr from "../Array.ts" -import * as Brand from "../Brand.ts" -import * as Data from "../Data.ts" +import * as Arr from "../collections/Array.ts" +import * as Brand from "../data/Brand.ts" +import * as Data from "../data/Data.ts" +import * as Option from "../data/Option.ts" import * as Effect from "../Effect.ts" import { pipe } from "../Function.ts" -import * as Layer from "../Layer.ts" -import * as Option from "../Option.ts" -import * as Pull from "../Pull.ts" -import type { Scope } from "../Scope.ts" -import * as ServiceMap from "../ServiceMap.ts" -import * as Sink from "../Sink.ts" -import * as Stream from "../Stream.ts" +import type { Scope } from "../resources/Scope.ts" +import * as Layer from "../services/Layer.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import * as Pull from "../stream/Pull.ts" +import * as Sink from "../stream/Sink.ts" +import * as Stream from "../stream/Stream.ts" import type { PlatformError } from "./PlatformError.ts" import { BadArgument, SystemError } from "./PlatformError.ts" @@ -82,7 +83,8 @@ export type TypeId = "~effect/platform/FileSystem" * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * import { FileSystem } from "effect/platform" * * const program = Effect.gen(function* () { @@ -513,7 +515,8 @@ export const MiB = (n: number): Size => Size(n * 1024 * 1024) * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * import { FileSystem } from "effect/platform" * * const program = Effect.gen(function* () { @@ -544,7 +547,8 @@ export const GiB = (n: number): Size => Size(n * 1024 * 1024 * 1024) * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * import { FileSystem } from "effect/platform" * * const program = Effect.gen(function* () { @@ -582,7 +586,8 @@ const bigintPiB = bigint1024 * bigint1024 * bigint1024 * bigint1024 * bigint1024 * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * import { FileSystem } from "effect/platform" * * const program = Effect.gen(function* () { @@ -1104,7 +1109,8 @@ export const makeNoop = (fileSystem: Partial): FileSystem => * * @example * ```ts - * import { Effect, Layer } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" * import { FileSystem } from "effect/platform" * * // Create a test layer with specific behaviors @@ -1171,7 +1177,8 @@ export const isFile = (u: unknown): u is File => typeof u === "object" && u !== * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * import { FileSystem } from "effect/platform" * * const program = Effect.gen(function* () { @@ -1261,7 +1268,9 @@ export declare namespace File { * * @example * ```ts - * import { Effect, Console, Option } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { Option } from "effect/data" * import { FileSystem } from "effect/platform" * * const program = Effect.gen(function* () { @@ -1422,7 +1431,9 @@ export const WatchEventRemove: Data.Case.Constructor * * @example * ```ts - * import { Effect, Option, Stream } from "effect" + * import { Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Option } from "effect/data" * import { FileSystem } from "effect/platform" * * // Custom watch backend implementation diff --git a/packages/effect/src/platform/Path.ts b/packages/effect/src/platform/Path.ts index 31829b2af0..1dc4a16427 100644 --- a/packages/effect/src/platform/Path.ts +++ b/packages/effect/src/platform/Path.ts @@ -3,8 +3,8 @@ */ import * as Effect from "../Effect.ts" import { identity } from "../Function.ts" -import * as Layer from "../Layer.ts" -import * as ServiceMap from "../ServiceMap.ts" +import * as Layer from "../services/Layer.ts" +import * as ServiceMap from "../services/ServiceMap.ts" import { BadArgument } from "./PlatformError.ts" /** @@ -156,7 +156,8 @@ export declare namespace Path { * @category tag * @example * ```ts - * import { Effect, Layer } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" * import { Path } from "effect/platform" * * // Create a custom path implementation diff --git a/packages/effect/src/platform/PlatformError.ts b/packages/effect/src/platform/PlatformError.ts index 2a03487c92..d6c63bf41d 100644 --- a/packages/effect/src/platform/PlatformError.ts +++ b/packages/effect/src/platform/PlatformError.ts @@ -1,7 +1,7 @@ /** * @since 4.0.0 */ -import * as Data from "../Data.ts" +import * as Data from "../data/Data.ts" /** * @since 1.0.0 diff --git a/packages/effect/src/platform/index.ts b/packages/effect/src/platform/index.ts index 0e2f951ad5..36e2453dd3 100644 --- a/packages/effect/src/platform/index.ts +++ b/packages/effect/src/platform/index.ts @@ -13,7 +13,8 @@ * * @example * ```ts - * import { Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * import { FileSystem } from "effect/platform" * * const program = Effect.gen(function* () { diff --git a/packages/effect/src/BigDecimal.ts b/packages/effect/src/primitives/BigDecimal.ts similarity index 91% rename from packages/effect/src/BigDecimal.ts rename to packages/effect/src/primitives/BigDecimal.ts index e9257b4c68..5404cf505b 100644 --- a/packages/effect/src/BigDecimal.ts +++ b/packages/effect/src/primitives/BigDecimal.ts @@ -14,16 +14,16 @@ * @since 2.0.0 */ -import * as Equal from "./Equal.ts" -import * as equivalence from "./Equivalence.ts" -import { dual, pipe } from "./Function.ts" -import * as Hash from "./Hash.ts" -import { type Inspectable, NodeInspectSymbol } from "./Inspectable.ts" -import * as Option from "./Option.ts" -import * as order from "./Order.ts" -import type { Ordering } from "./Ordering.ts" -import { type Pipeable, pipeArguments } from "./Pipeable.ts" -import { hasProperty } from "./Predicate.ts" +import * as equivalence from "../data/Equivalence.ts" +import * as Option from "../data/Option.ts" +import * as order from "../data/Order.ts" +import type { Ordering } from "../data/Ordering.ts" +import { hasProperty } from "../data/Predicate.ts" +import { dual, pipe } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import { type Inspectable, NodeInspectSymbol } from "../interfaces/Inspectable.ts" +import { type Pipeable, pipeArguments } from "../interfaces/Pipeable.ts" const DEFAULT_PRECISION = 100 const FINITE_INT_REGEX = /^[+-]?\d+$/ @@ -33,7 +33,7 @@ const FINITE_INT_REGEX = /^[+-]?\d+$/ * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const decimal = BigDecimal.fromNumber(123.45) * console.log(decimal[BigDecimal.TypeId]) // Symbol(effect/BigDecimal) @@ -49,7 +49,7 @@ export const TypeId: TypeId = "~effect/BigDecimal" * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * // TypeId is used for type-level operations * const hasTypeId: BigDecimal.TypeId = BigDecimal.TypeId @@ -65,7 +65,7 @@ export type TypeId = "~effect/BigDecimal" * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const decimal: BigDecimal.BigDecimal = BigDecimal.fromNumber(123.45) * console.log(decimal.value) // 12345n @@ -120,7 +120,7 @@ const BigDecimalProto: Omit = { * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const decimal = BigDecimal.fromNumber(123.45) * console.log(BigDecimal.isBigDecimal(decimal)) // true @@ -138,7 +138,7 @@ export const isBigDecimal = (u: unknown): u is BigDecimal => hasProperty(u, Type * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * // Create 123.45 (12345 with scale 2) * const decimal = BigDecimal.make(12345n, 2) @@ -185,7 +185,7 @@ const zero = unsafeMakeNormalized(bigint0, 0) * @example * ```ts * import * as assert from "node:assert" - * import { normalize, make, unsafeFromString } from "effect/BigDecimal" + * import { normalize, make, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(normalize(unsafeFromString("123.00000")), normalize(make(123n, 0))) * assert.deepStrictEqual(normalize(unsafeFromString("12300000")), normalize(make(123n, -5))) @@ -231,7 +231,7 @@ export const normalize = (self: BigDecimal): BigDecimal => { * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const decimal = BigDecimal.fromNumber(123.45) * @@ -268,7 +268,7 @@ export const scale: { * @example * ```ts * import * as assert from "node:assert" - * import { sum, unsafeFromString } from "effect/BigDecimal" + * import { sum, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(sum(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("5")) * ``` @@ -305,7 +305,7 @@ export const sum: { * @example * ```ts * import * as assert from "node:assert" - * import { multiply, unsafeFromString } from "effect/BigDecimal" + * import { multiply, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(multiply(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("6")) * ``` @@ -330,7 +330,7 @@ export const multiply: { * @example * ```ts * import * as assert from "node:assert" - * import { subtract, unsafeFromString } from "effect/BigDecimal" + * import { subtract, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(subtract(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("-1")) * ``` @@ -440,7 +440,8 @@ export const roundTerminal = (n: bigint): bigint => { * @example * ```ts * import * as assert from "node:assert" - * import { BigDecimal, Option } from "effect" + * import { Option } from "effect/data" + * import { BigDecimal } from "effect/primitives" * * assert.deepStrictEqual(BigDecimal.divide(BigDecimal.unsafeFromString("6"), BigDecimal.unsafeFromString("3")), Option.some(BigDecimal.unsafeFromString("2"))) * assert.deepStrictEqual(BigDecimal.divide(BigDecimal.unsafeFromString("6"), BigDecimal.unsafeFromString("4")), Option.some(BigDecimal.unsafeFromString("1.5"))) @@ -481,7 +482,7 @@ export const divide: { * @example * ```ts * import * as assert from "node:assert" - * import { unsafeDivide, unsafeFromString } from "effect/BigDecimal" + * import { unsafeDivide, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(unsafeDivide(unsafeFromString("6"), unsafeFromString("3")), unsafeFromString("2")) * assert.deepStrictEqual(unsafeDivide(unsafeFromString("6"), unsafeFromString("4")), unsafeFromString("1.5")) @@ -514,7 +515,7 @@ export const unsafeDivide: { * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const a = BigDecimal.fromNumber(1.5) * const b = BigDecimal.fromNumber(2.3) @@ -551,7 +552,7 @@ export const Order: order.Order = order.make((self, that) => { * @example * ```ts * import * as assert from "node:assert" - * import { lessThan, unsafeFromString } from "effect/BigDecimal" + * import { lessThan, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(lessThan(unsafeFromString("2"), unsafeFromString("3")), true) * assert.deepStrictEqual(lessThan(unsafeFromString("3"), unsafeFromString("3")), false) @@ -572,7 +573,7 @@ export const lessThan: { * @example * ```ts * import * as assert from "node:assert" - * import { lessThanOrEqualTo, unsafeFromString } from "effect/BigDecimal" + * import { lessThanOrEqualTo, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(lessThanOrEqualTo(unsafeFromString("2"), unsafeFromString("3")), true) * assert.deepStrictEqual(lessThanOrEqualTo(unsafeFromString("3"), unsafeFromString("3")), true) @@ -593,7 +594,7 @@ export const lessThanOrEqualTo: { * @example * ```ts * import * as assert from "node:assert" - * import { greaterThan, unsafeFromString } from "effect/BigDecimal" + * import { greaterThan, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(greaterThan(unsafeFromString("2"), unsafeFromString("3")), false) * assert.deepStrictEqual(greaterThan(unsafeFromString("3"), unsafeFromString("3")), false) @@ -614,7 +615,7 @@ export const greaterThan: { * @example * ```ts * import * as assert from "node:assert" - * import { greaterThanOrEqualTo, unsafeFromString } from "effect/BigDecimal" + * import { greaterThanOrEqualTo, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(greaterThanOrEqualTo(unsafeFromString("2"), unsafeFromString("3")), false) * assert.deepStrictEqual(greaterThanOrEqualTo(unsafeFromString("3"), unsafeFromString("3")), true) @@ -635,7 +636,7 @@ export const greaterThanOrEqualTo: { * @example * ```ts * import * as assert from "node:assert" - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const between = BigDecimal.between({ * minimum: BigDecimal.unsafeFromString("1"), @@ -671,7 +672,7 @@ export const between: { * @example * ```ts * import * as assert from "node:assert" - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const clamp = BigDecimal.clamp({ * minimum: BigDecimal.unsafeFromString("1"), @@ -703,7 +704,7 @@ export const clamp: { * @example * ```ts * import * as assert from "node:assert" - * import { min, unsafeFromString } from "effect/BigDecimal" + * import { min, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(min(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("2")) * ``` @@ -722,7 +723,7 @@ export const min: { * @example * ```ts * import * as assert from "node:assert" - * import { max, unsafeFromString } from "effect/BigDecimal" + * import { max, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(max(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("3")) * ``` @@ -741,7 +742,7 @@ export const max: { * @example * ```ts * import * as assert from "node:assert" - * import { sign, unsafeFromString } from "effect/BigDecimal" + * import { sign, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(sign(unsafeFromString("-5")), -1) * assert.deepStrictEqual(sign(unsafeFromString("0")), 0) @@ -759,7 +760,7 @@ export const sign = (n: BigDecimal): Ordering => n.value === bigint0 ? 0 : n.val * @example * ```ts * import * as assert from "node:assert" - * import { abs, unsafeFromString } from "effect/BigDecimal" + * import { abs, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(abs(unsafeFromString("-5")), unsafeFromString("5")) * assert.deepStrictEqual(abs(unsafeFromString("0")), unsafeFromString("0")) @@ -777,7 +778,7 @@ export const abs = (n: BigDecimal): BigDecimal => n.value < bigint0 ? make(-n.va * @example * ```ts * import * as assert from "node:assert" - * import { negate, unsafeFromString } from "effect/BigDecimal" + * import { negate, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(negate(unsafeFromString("3")), unsafeFromString("-3")) * assert.deepStrictEqual(negate(unsafeFromString("-6")), unsafeFromString("6")) @@ -796,7 +797,8 @@ export const negate = (n: BigDecimal): BigDecimal => make(-n.value, n.scale) * @example * ```ts * import * as assert from "node:assert" - * import { BigDecimal, Option } from "effect" + * import { Option } from "effect/data" + * import { BigDecimal } from "effect/primitives" * * assert.deepStrictEqual(BigDecimal.remainder(BigDecimal.unsafeFromString("2"), BigDecimal.unsafeFromString("2")), Option.some(BigDecimal.unsafeFromString("0"))) * assert.deepStrictEqual(BigDecimal.remainder(BigDecimal.unsafeFromString("3"), BigDecimal.unsafeFromString("2")), Option.some(BigDecimal.unsafeFromString("1"))) @@ -826,7 +828,7 @@ export const remainder: { * @example * ```ts * import * as assert from "node:assert" - * import { unsafeRemainder, unsafeFromString } from "effect/BigDecimal" + * import { unsafeRemainder, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(unsafeRemainder(unsafeFromString("2"), unsafeFromString("2")), unsafeFromString("0")) * assert.deepStrictEqual(unsafeRemainder(unsafeFromString("3"), unsafeFromString("2")), unsafeFromString("1")) @@ -853,7 +855,7 @@ export const unsafeRemainder: { * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const a = BigDecimal.fromNumber(1.50) * const b = BigDecimal.fromNumber(1.5) @@ -883,7 +885,7 @@ export const Equivalence: equivalence.Equivalence = equivalence.make * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const a = BigDecimal.fromNumber(1.5) * const b = BigDecimal.fromNumber(1.50) @@ -906,7 +908,7 @@ export const equals: { * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const decimal = BigDecimal.fromBigInt(123n) * console.log(BigDecimal.format(decimal)) // "123" @@ -931,7 +933,7 @@ export const fromBigInt = (n: bigint): BigDecimal => make(n, 0) * @example * ```ts * import * as assert from "node:assert" - * import { unsafeFromNumber, make } from "effect/BigDecimal" + * import { unsafeFromNumber, make } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(unsafeFromNumber(123), make(123n, 0)) * assert.deepStrictEqual(unsafeFromNumber(123.456), make(123456n, 3)) @@ -953,7 +955,7 @@ export const unsafeFromNumber = (n: number): BigDecimal => * * @example * ```ts - * import { BigDecimal } from "effect" + * import { BigDecimal } from "effect/primitives" * * const decimal = BigDecimal.fromNumber(123.45) * console.log(BigDecimal.format(decimal)) // "123.45" @@ -979,7 +981,8 @@ export const fromNumber: (n: number) => BigDecimal = unsafeFromNumber * @example * ```ts * import * as assert from "node:assert" - * import { BigDecimal, Option } from "effect" + * import { Option } from "effect/data" + * import { BigDecimal } from "effect/primitives" * * assert.deepStrictEqual(BigDecimal.safeFromNumber(123), Option.some(BigDecimal.make(123n, 0))) * assert.deepStrictEqual(BigDecimal.safeFromNumber(123.456), Option.some(BigDecimal.make(123456n, 3))) @@ -1009,7 +1012,8 @@ export const safeFromNumber = (n: number): Option.Option => { * @example * ```ts * import * as assert from "node:assert" - * import { BigDecimal, Option } from "effect" + * import { Option } from "effect/data" + * import { BigDecimal } from "effect/primitives" * * assert.deepStrictEqual(BigDecimal.fromString("123"), Option.some(BigDecimal.make(123n, 0))) * assert.deepStrictEqual(BigDecimal.fromString("123.456"), Option.some(BigDecimal.make(123456n, 3))) @@ -1070,7 +1074,7 @@ export const fromString = (s: string): Option.Option => { * @example * ```ts * import * as assert from "node:assert" - * import { unsafeFromString, make } from "effect/BigDecimal" + * import { unsafeFromString, make } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(unsafeFromString("123"), make(123n, 0)) * assert.deepStrictEqual(unsafeFromString("123.456"), make(123456n, 3)) @@ -1092,7 +1096,7 @@ export const unsafeFromString = (s: string): BigDecimal => * @example * ```ts * import * as assert from "node:assert" - * import { format, unsafeFromString } from "effect/BigDecimal" + * import { format, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(format(unsafeFromString("-5")), "-5") * assert.deepStrictEqual(format(unsafeFromString("123.456")), "123.456") @@ -1139,7 +1143,7 @@ export const format = (n: BigDecimal): string => { * @example * ```ts * import * as assert from "node:assert" - * import { toExponential, make } from "effect/BigDecimal" + * import { toExponential, make } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(toExponential(make(123456n, -5)), "1.23456e+10") * ``` @@ -1174,7 +1178,7 @@ export const toExponential = (n: BigDecimal): string => { * @example * ```ts * import * as assert from "node:assert" - * import { unsafeToNumber, unsafeFromString } from "effect/BigDecimal" + * import { unsafeToNumber, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(unsafeToNumber(unsafeFromString("123.456")), 123.456) * ``` @@ -1190,7 +1194,7 @@ export const unsafeToNumber = (n: BigDecimal): number => Number(format(n)) * @example * ```ts * import * as assert from "node:assert" - * import { isInteger, unsafeFromString } from "effect/BigDecimal" + * import { isInteger, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(isInteger(unsafeFromString("0")), true) * assert.deepStrictEqual(isInteger(unsafeFromString("1")), true) @@ -1208,7 +1212,7 @@ export const isInteger = (n: BigDecimal): boolean => normalize(n).scale <= 0 * @example * ```ts * import * as assert from "node:assert" - * import { isZero, unsafeFromString } from "effect/BigDecimal" + * import { isZero, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(isZero(unsafeFromString("0")), true) * assert.deepStrictEqual(isZero(unsafeFromString("1")), false) @@ -1225,7 +1229,7 @@ export const isZero = (n: BigDecimal): boolean => n.value === bigint0 * @example * ```ts * import * as assert from "node:assert" - * import { isNegative, unsafeFromString } from "effect/BigDecimal" + * import { isNegative, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(isNegative(unsafeFromString("-1")), true) * assert.deepStrictEqual(isNegative(unsafeFromString("0")), false) @@ -1243,7 +1247,7 @@ export const isNegative = (n: BigDecimal): boolean => n.value < bigint0 * @example * ```ts * import * as assert from "node:assert" - * import { isPositive, unsafeFromString } from "effect/BigDecimal" + * import { isPositive, unsafeFromString } from "effect/primitives/BigDecimal" * * assert.deepStrictEqual(isPositive(unsafeFromString("-1")), false) * assert.deepStrictEqual(isPositive(unsafeFromString("0")), false) diff --git a/packages/effect/src/BigInt.ts b/packages/effect/src/primitives/BigInt.ts similarity index 87% rename from packages/effect/src/BigInt.ts rename to packages/effect/src/primitives/BigInt.ts index 1e67d02310..35a9d0b0f5 100644 --- a/packages/effect/src/BigInt.ts +++ b/packages/effect/src/primitives/BigInt.ts @@ -6,19 +6,19 @@ * @since 2.0.0 */ -import * as equivalence from "./Equivalence.ts" -import { dual } from "./Function.ts" -import * as Option from "./Option.ts" -import * as order from "./Order.ts" -import type { Ordering } from "./Ordering.ts" -import * as predicate from "./Predicate.ts" +import * as equivalence from "../data/Equivalence.ts" +import * as Option from "../data/Option.ts" +import * as order from "../data/Order.ts" +import type { Ordering } from "../data/Ordering.ts" +import * as predicate from "../data/Predicate.ts" +import { dual } from "../Function.ts" /** * Reference to the global BigInt constructor. * * @example * ```ts - * import { BigInt } from "effect" + * import * as BigInt from "effect/primitives/BigInt" * * const bigInt = BigInt.BigInt(123) * console.log(bigInt) // 123n @@ -42,7 +42,7 @@ const bigint2 = BigInt(2) * @example * ```ts * import * as assert from "node:assert" - * import { isBigInt } from "effect/BigInt" + * import { isBigInt } from "effect/primitives/BigInt" * * assert.deepStrictEqual(isBigInt(1n), true) * assert.deepStrictEqual(isBigInt(1), false) @@ -59,7 +59,7 @@ export const isBigInt: (u: unknown) => u is bigint = predicate.isBigInt * @example * ```ts * import * as assert from "node:assert" - * import { sum } from "effect/BigInt" + * import { sum } from "effect/primitives/BigInt" * * assert.deepStrictEqual(sum(2n, 3n), 5n) * ``` @@ -78,7 +78,7 @@ export const sum: { * @example * ```ts * import * as assert from "node:assert" - * import { multiply } from "effect/BigInt" + * import { multiply } from "effect/primitives/BigInt" * * assert.deepStrictEqual(multiply(2n, 3n), 6n) * ``` @@ -97,7 +97,7 @@ export const multiply: { * @example * ```ts * import * as assert from "node:assert" - * import { subtract } from "effect/BigInt" + * import { subtract } from "effect/primitives/BigInt" * * assert.deepStrictEqual(subtract(2n, 3n), -1n) * ``` @@ -121,10 +121,11 @@ export const subtract: { * @example * ```ts * import * as assert from "node:assert" - * import { BigInt, Option } from "effect" + * import { Option } from "effect/data" + * import { divide } from "effect/primitives/BigInt" * - * assert.deepStrictEqual(BigInt.divide(6n, 3n), Option.some(2n)) - * assert.deepStrictEqual(BigInt.divide(6n, 0n), Option.none()) + * assert.deepStrictEqual(divide(6n, 3n), Option.some(2n)) + * assert.deepStrictEqual(divide(6n, 0n), Option.none()) * ``` * * @category math @@ -149,7 +150,7 @@ export const divide: { * @example * ```ts * import * as assert from "node:assert" - * import { unsafeDivide } from "effect/BigInt" + * import { unsafeDivide } from "effect/primitives/BigInt" * * assert.deepStrictEqual(unsafeDivide(6n, 3n), 2n) * assert.deepStrictEqual(unsafeDivide(6n, 4n), 1n) @@ -169,7 +170,7 @@ export const unsafeDivide: { * @example * ```ts * import * as assert from "node:assert" - * import { increment } from "effect/BigInt" + * import { increment } from "effect/primitives/BigInt" * * assert.deepStrictEqual(increment(2n), 3n) * ``` @@ -185,7 +186,7 @@ export const increment = (n: bigint): bigint => n + bigint1 * @example * ```ts * import * as assert from "node:assert" - * import { decrement } from "effect/BigInt" + * import { decrement } from "effect/primitives/BigInt" * * assert.deepStrictEqual(decrement(3n), 2n) * ``` @@ -200,7 +201,7 @@ export const decrement = (n: bigint): bigint => n - bigint1 * * @example * ```ts - * import { BigInt } from "effect" + * import * as BigInt from "effect/primitives/BigInt" * * const a = 123n * const b = 123n @@ -220,7 +221,7 @@ export const Equivalence: equivalence.Equivalence = equivalence.bigint * * @example * ```ts - * import { BigInt } from "effect" + * import * as BigInt from "effect/primitives/BigInt" * * const a = 123n * const b = 456n @@ -242,7 +243,7 @@ export const Order: order.Order = order.bigint * @example * ```ts * import * as assert from "node:assert" - * import { lessThan } from "effect/BigInt" + * import { lessThan } from "effect/primitives/BigInt" * * assert.deepStrictEqual(lessThan(2n, 3n), true) * assert.deepStrictEqual(lessThan(3n, 3n), false) @@ -263,7 +264,7 @@ export const lessThan: { * @example * ```ts * import * as assert from "node:assert" - * import { lessThanOrEqualTo } from "effect/BigInt" + * import { lessThanOrEqualTo } from "effect/primitives/BigInt" * * assert.deepStrictEqual(lessThanOrEqualTo(2n, 3n), true) * assert.deepStrictEqual(lessThanOrEqualTo(3n, 3n), true) @@ -284,7 +285,7 @@ export const lessThanOrEqualTo: { * @example * ```ts * import * as assert from "node:assert" - * import { greaterThan } from "effect/BigInt" + * import { greaterThan } from "effect/primitives/BigInt" * * assert.deepStrictEqual(greaterThan(2n, 3n), false) * assert.deepStrictEqual(greaterThan(3n, 3n), false) @@ -305,7 +306,7 @@ export const greaterThan: { * @example * ```ts * import * as assert from "node:assert" - * import { greaterThanOrEqualTo } from "effect/BigInt" + * import { greaterThanOrEqualTo } from "effect/primitives/BigInt" * * assert.deepStrictEqual(greaterThanOrEqualTo(2n, 3n), false) * assert.deepStrictEqual(greaterThanOrEqualTo(3n, 3n), true) @@ -326,7 +327,7 @@ export const greaterThanOrEqualTo: { * @example * ```ts * import * as assert from "node:assert" - * import { BigInt } from "effect" + * import * as BigInt from "effect/primitives/BigInt" * * const between = BigInt.between({ minimum: 0n, maximum: 5n }) * @@ -359,7 +360,7 @@ export const between: { * @example * ```ts * import * as assert from "node:assert" - * import { BigInt } from "effect" + * import * as BigInt from "effect/primitives/BigInt" * * const clamp = BigInt.clamp({ minimum: 1n, maximum: 5n }) * @@ -388,7 +389,7 @@ export const clamp: { * @example * ```ts * import * as assert from "node:assert" - * import { min } from "effect/BigInt" + * import { min } from "effect/primitives/BigInt" * * assert.deepStrictEqual(min(2n, 3n), 2n) * ``` @@ -407,7 +408,7 @@ export const min: { * @example * ```ts * import * as assert from "node:assert" - * import { max } from "effect/BigInt" + * import { max } from "effect/primitives/BigInt" * * assert.deepStrictEqual(max(2n, 3n), 3n) * ``` @@ -426,7 +427,7 @@ export const max: { * @example * ```ts * import * as assert from "node:assert" - * import { sign } from "effect/BigInt" + * import { sign } from "effect/primitives/BigInt" * * assert.deepStrictEqual(sign(-5n), -1) * assert.deepStrictEqual(sign(0n), 0) @@ -444,7 +445,7 @@ export const sign = (n: bigint): Ordering => Order(n, bigint0) * @example * ```ts * import * as assert from "node:assert" - * import { abs } from "effect/BigInt" + * import { abs } from "effect/primitives/BigInt" * * assert.deepStrictEqual(abs(-5n), 5n) * assert.deepStrictEqual(abs(0n), 0n) @@ -462,7 +463,7 @@ export const abs = (n: bigint): bigint => (n < bigint0 ? -n : n) * @example * ```ts * import * as assert from "node:assert" - * import { gcd } from "effect/BigInt" + * import { gcd } from "effect/primitives/BigInt" * * assert.deepStrictEqual(gcd(2n, 3n), 1n) * assert.deepStrictEqual(gcd(2n, 4n), 2n) @@ -490,7 +491,7 @@ export const gcd: { * @example * ```ts * import * as assert from "node:assert" - * import { lcm } from "effect/BigInt" + * import { lcm } from "effect/primitives/BigInt" * * assert.deepStrictEqual(lcm(2n, 3n), 6n) * assert.deepStrictEqual(lcm(2n, 4n), 4n) @@ -511,7 +512,7 @@ export const lcm: { * @example * ```ts * import * as assert from "node:assert" - * import { unsafeSqrt } from "effect/BigInt" + * import { unsafeSqrt } from "effect/primitives/BigInt" * * assert.deepStrictEqual(unsafeSqrt(4n), 2n) * assert.deepStrictEqual(unsafeSqrt(9n), 3n) @@ -541,7 +542,8 @@ export const unsafeSqrt = (n: bigint): bigint => { * @example * ```ts * import * as assert from "node:assert" - * import { BigInt, Option } from "effect" + * import { Option } from "effect/data" + * import * as BigInt from "effect/primitives/BigInt" * * assert.deepStrictEqual(BigInt.sqrt(4n), Option.some(2n)) * assert.deepStrictEqual(BigInt.sqrt(9n), Option.some(3n)) @@ -561,7 +563,7 @@ export const sqrt = (n: bigint): Option.Option => * @example * ```ts * import * as assert from "node:assert" - * import { sumAll } from "effect/BigInt" + * import { sumAll } from "effect/primitives/BigInt" * * assert.deepStrictEqual(sumAll([2n, 3n, 4n]), 9n) * ``` @@ -583,7 +585,7 @@ export const sumAll = (collection: Iterable): bigint => { * @example * ```ts * import * as assert from "node:assert" - * import { multiplyAll } from "effect/BigInt" + * import { multiplyAll } from "effect/primitives/BigInt" * * assert.deepStrictEqual(multiplyAll([2n, 3n, 4n]), 24n) * ``` @@ -612,7 +614,8 @@ export const multiplyAll = (collection: Iterable): bigint => { * @example * ```ts * import * as assert from "node:assert" - * import { BigInt as BI, Option } from "effect" + * import { Option } from "effect/data" + * import * as BI from "effect/primitives/BigInt" * * assert.deepStrictEqual(BI.toNumber(BigInt(42)), Option.some(42)) * assert.deepStrictEqual(BI.toNumber(BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1)), Option.none()) @@ -638,7 +641,8 @@ export const toNumber = (b: bigint): Option.Option => { * @example * ```ts * import * as assert from "node:assert" - * import { BigInt as BI, Option } from "effect" + * import { Option } from "effect/data" + * import * as BI from "effect/primitives/BigInt" * * assert.deepStrictEqual(BI.fromString("42"), Option.some(BigInt(42))) * assert.deepStrictEqual(BI.fromString(" "), Option.none()) @@ -668,7 +672,8 @@ export const fromString = (s: string): Option.Option => { * @example * ```ts * import * as assert from "node:assert" - * import { BigInt as BI, Option } from "effect" + * import { Option } from "effect/data" + * import * as BI from "effect/primitives/BigInt" * * assert.deepStrictEqual(BI.fromNumber(42), Option.some(BigInt(42))) * assert.deepStrictEqual(BI.fromNumber(Number.MAX_SAFE_INTEGER + 1), Option.none()) @@ -695,7 +700,7 @@ export const fromNumber = (n: number): Option.Option => { * * @example * ```ts - * import { BigInt } from "effect" + * import * as BigInt from "effect/primitives/BigInt" * * const result = BigInt.remainder(10n, 3n) * console.log(result) // 1n diff --git a/packages/effect/src/Boolean.ts b/packages/effect/src/primitives/Boolean.ts similarity index 88% rename from packages/effect/src/Boolean.ts rename to packages/effect/src/primitives/Boolean.ts index 013aff79b3..c25ab7edeb 100644 --- a/packages/effect/src/Boolean.ts +++ b/packages/effect/src/primitives/Boolean.ts @@ -5,18 +5,18 @@ * * @since 2.0.0 */ -import * as equivalence from "./Equivalence.ts" -import type { LazyArg } from "./Function.ts" -import { dual } from "./Function.ts" -import * as order from "./Order.ts" -import * as predicate from "./Predicate.ts" +import * as equivalence from "../data/Equivalence.ts" +import * as order from "../data/Order.ts" +import * as predicate from "../data/Predicate.ts" +import type { LazyArg } from "../Function.ts" +import { dual } from "../Function.ts" /** * Reference to the global Boolean constructor. * * @example * ```ts - * import { Boolean } from "effect" + * import * as Boolean from "effect/primitives/Boolean" * * const bool = Boolean.Boolean(1) * console.log(bool) // true @@ -39,7 +39,7 @@ export const Boolean = globalThis.Boolean * @example * ```ts * import * as assert from "node:assert" - * import { isBoolean } from "effect/Boolean" + * import { isBoolean } from "effect/primitives/Boolean" * * assert.deepStrictEqual(isBoolean(true), true) * assert.deepStrictEqual(isBoolean("true"), false) @@ -57,7 +57,7 @@ export const isBoolean: (input: unknown) => input is boolean = predicate.isBoole * @example * ```ts * import * as assert from "node:assert" - * import { Boolean } from "effect" + * import * as Boolean from "effect/primitives/Boolean" * * assert.deepStrictEqual(Boolean.match(true, { onFalse: () => "It's false!", onTrue: () => "It's true!" }), "It's true!") * ``` @@ -84,7 +84,7 @@ export const match: { * * @example * ```ts - * import { Boolean } from "effect" + * import * as Boolean from "effect/primitives/Boolean" * * console.log(Boolean.Equivalence(true, true)) // true * console.log(Boolean.Equivalence(false, false)) // true @@ -102,7 +102,7 @@ export const Equivalence: equivalence.Equivalence = equivalence.boolean * * @example * ```ts - * import { Boolean } from "effect" + * import * as Boolean from "effect/primitives/Boolean" * * console.log(Boolean.Order(false, true)) // -1 (false < true) * console.log(Boolean.Order(true, false)) // 1 (true > false) @@ -120,7 +120,7 @@ export const Order: order.Order = order.boolean * @example * ```ts * import * as assert from "node:assert" - * import { not } from "effect/Boolean" + * import { not } from "effect/primitives/Boolean" * * assert.deepStrictEqual(not(true), false) * assert.deepStrictEqual(not(false), true) @@ -137,7 +137,7 @@ export const not = (self: boolean): boolean => !self * @example * ```ts * import * as assert from "node:assert" - * import { and } from "effect/Boolean" + * import { and } from "effect/primitives/Boolean" * * assert.deepStrictEqual(and(true, true), true) * assert.deepStrictEqual(and(true, false), false) @@ -159,7 +159,7 @@ export const and: { * @example * ```ts * import * as assert from "node:assert" - * import { nand } from "effect/Boolean" + * import { nand } from "effect/primitives/Boolean" * * assert.deepStrictEqual(nand(true, true), false) * assert.deepStrictEqual(nand(true, false), true) @@ -181,7 +181,7 @@ export const nand: { * @example * ```ts * import * as assert from "node:assert" - * import { or } from "effect/Boolean" + * import { or } from "effect/primitives/Boolean" * * assert.deepStrictEqual(or(true, true), true) * assert.deepStrictEqual(or(true, false), true) @@ -203,7 +203,7 @@ export const or: { * @example * ```ts * import * as assert from "node:assert" - * import { nor } from "effect/Boolean" + * import { nor } from "effect/primitives/Boolean" * * assert.deepStrictEqual(nor(true, true), false) * assert.deepStrictEqual(nor(true, false), false) @@ -225,7 +225,7 @@ export const nor: { * @example * ```ts * import * as assert from "node:assert" - * import { xor } from "effect/Boolean" + * import { xor } from "effect/primitives/Boolean" * * assert.deepStrictEqual(xor(true, true), false) * assert.deepStrictEqual(xor(true, false), true) @@ -247,7 +247,7 @@ export const xor: { * @example * ```ts * import * as assert from "node:assert" - * import { eqv } from "effect/Boolean" + * import { eqv } from "effect/primitives/Boolean" * * assert.deepStrictEqual(eqv(true, true), true) * assert.deepStrictEqual(eqv(true, false), false) @@ -269,7 +269,7 @@ export const eqv: { * @example * ```ts * import * as assert from "node:assert" - * import { implies } from "effect/Boolean" + * import { implies } from "effect/primitives/Boolean" * * assert.deepStrictEqual(implies(true, true), true) * assert.deepStrictEqual(implies(true, false), false) @@ -291,7 +291,7 @@ export const implies: { * @example * ```ts * import * as assert from "node:assert" - * import { every } from "effect/Boolean" + * import { every } from "effect/primitives/Boolean" * * assert.deepStrictEqual(every([true, true, true]), true) * assert.deepStrictEqual(every([true, false, true]), false) @@ -315,7 +315,7 @@ export const every = (collection: Iterable): boolean => { * @example * ```ts * import * as assert from "node:assert" - * import { some } from "effect/Boolean" + * import { some } from "effect/primitives/Boolean" * * assert.deepStrictEqual(some([true, false, true]), true) * assert.deepStrictEqual(some([false, false, false]), false) diff --git a/packages/effect/src/Number.ts b/packages/effect/src/primitives/Number.ts similarity index 86% rename from packages/effect/src/Number.ts rename to packages/effect/src/primitives/Number.ts index 25aa982d33..c1dca459ba 100644 --- a/packages/effect/src/Number.ts +++ b/packages/effect/src/primitives/Number.ts @@ -5,20 +5,20 @@ * * @since 2.0.0 */ -import * as equivalence from "./Equivalence.ts" -import { dual } from "./Function.ts" -import * as option from "./internal/option.ts" -import type { Option } from "./Option.ts" -import * as order from "./Order.ts" -import type { Ordering } from "./Ordering.ts" -import * as predicate from "./Predicate.ts" +import * as equivalence from "../data/Equivalence.ts" +import type { Option } from "../data/Option.ts" +import * as order from "../data/Order.ts" +import type { Ordering } from "../data/Ordering.ts" +import * as predicate from "../data/Predicate.ts" +import { dual } from "../Function.ts" +import * as option from "../internal/option.ts" /** * The global `Number` constructor. * * @example * ```ts - * import * as N from "effect/Number" + * import * as N from "effect/primitives/Number" * * const num = N.Number("42") * console.log(num) // 42 @@ -38,7 +38,7 @@ export const Number = globalThis.Number * @example * ```ts * import * as assert from "node:assert" - * import { isNumber } from "effect/Number" + * import { isNumber } from "effect/primitives/Number" * * assert.deepStrictEqual(isNumber(2), true) * assert.deepStrictEqual(isNumber("2"), false) @@ -55,7 +55,7 @@ export const isNumber: (input: unknown) => input is number = predicate.isNumber * @example * ```ts * import * as assert from "node:assert" - * import { sum } from "effect/Number" + * import { sum } from "effect/primitives/Number" * * assert.deepStrictEqual(sum(2, 3), 5) * ``` @@ -74,7 +74,7 @@ export const sum: { * @example * ```ts * import * as assert from "node:assert" - * import { multiply } from "effect/Number" + * import { multiply } from "effect/primitives/Number" * * assert.deepStrictEqual(multiply(2, 3), 6) * ``` @@ -93,7 +93,7 @@ export const multiply: { * @example * ```ts * import * as assert from "node:assert" - * import { subtract } from "effect/Number" + * import { subtract } from "effect/primitives/Number" * * assert.deepStrictEqual(subtract(2, 3), -1) * ``` @@ -112,10 +112,11 @@ export const subtract: { * @example * ```ts * import * as assert from "node:assert" - * import { Number, Option } from "effect" + * import { Option } from "effect/data" + * import { divide } from "effect/primitives/Number" * - * assert.deepStrictEqual(Number.divide(6, 3), Option.some(2)) - * assert.deepStrictEqual(Number.divide(6, 0), Option.none()) + * assert.deepStrictEqual(divide(6, 3), Option.some(2)) + * assert.deepStrictEqual(divide(6, 0), Option.none()) * ``` * * @category math @@ -137,7 +138,7 @@ export const divide: { * @example * ```ts * import * as assert from "node:assert" - * import { unsafeDivide } from "effect/Number" + * import { unsafeDivide } from "effect/primitives/Number" * * assert.deepStrictEqual(unsafeDivide(6, 3), 2) * ``` @@ -156,7 +157,7 @@ export const unsafeDivide: { * @example * ```ts * import * as assert from "node:assert" - * import { increment } from "effect/Number" + * import { increment } from "effect/primitives/Number" * * assert.deepStrictEqual(increment(2), 3) * ``` @@ -172,7 +173,7 @@ export const increment = (n: number): number => n + 1 * @example * ```ts * import * as assert from "node:assert" - * import { decrement } from "effect/Number" + * import { decrement } from "effect/primitives/Number" * * assert.deepStrictEqual(decrement(3), 2) * ``` @@ -187,7 +188,7 @@ export const decrement = (n: number): number => n - 1 * * @example * ```ts - * import { Number } from "effect" + * import * as Number from "effect/primitives/Number" * * console.log(Number.Equivalence(1, 1)) // true * console.log(Number.Equivalence(1, 2)) // false @@ -203,7 +204,7 @@ export const Equivalence: equivalence.Equivalence = equivalence.number * * @example * ```ts - * import { Number } from "effect" + * import * as Number from "effect/primitives/Number" * * console.log(Number.Order(1, 2)) // -1 * console.log(Number.Order(2, 1)) // 1 @@ -221,7 +222,7 @@ export const Order: order.Order = order.number * @example * ```ts * import * as assert from "node:assert" - * import { lessThan } from "effect/Number" + * import { lessThan } from "effect/primitives/Number" * * assert.deepStrictEqual(lessThan(2, 3), true) * assert.deepStrictEqual(lessThan(3, 3), false) @@ -242,7 +243,7 @@ export const lessThan: { * @example * ```ts * import * as assert from "node:assert" - * import { lessThanOrEqualTo } from "effect/Number" + * import { lessThanOrEqualTo } from "effect/primitives/Number" * * assert.deepStrictEqual(lessThanOrEqualTo(2, 3), true) * assert.deepStrictEqual(lessThanOrEqualTo(3, 3), true) @@ -263,7 +264,7 @@ export const lessThanOrEqualTo: { * @example * ```ts * import * as assert from "node:assert" - * import { greaterThan } from "effect/Number" + * import { greaterThan } from "effect/primitives/Number" * * assert.deepStrictEqual(greaterThan(2, 3), false) * assert.deepStrictEqual(greaterThan(3, 3), false) @@ -284,7 +285,7 @@ export const greaterThan: { * @example * ```ts * import * as assert from "node:assert" - * import { greaterThanOrEqualTo } from "effect/Number" + * import { greaterThanOrEqualTo } from "effect/primitives/Number" * * assert.deepStrictEqual(greaterThanOrEqualTo(2, 3), false) * assert.deepStrictEqual(greaterThanOrEqualTo(3, 3), true) @@ -305,7 +306,7 @@ export const greaterThanOrEqualTo: { * @example * ```ts * import * as assert from "node:assert" - * import { Number } from "effect" + * import * as Number from "effect/primitives/Number" * * const between = Number.between({ minimum: 0, maximum: 5 }) * @@ -338,7 +339,7 @@ export const between: { * @example * ```ts * import * as assert from "node:assert" - * import { Number } from "effect" + * import * as Number from "effect/primitives/Number" * * const clamp = Number.clamp({ minimum: 1, maximum: 5 }) * @@ -367,7 +368,7 @@ export const clamp: { * @example * ```ts * import * as assert from "node:assert" - * import { min } from "effect/Number" + * import { min } from "effect/primitives/Number" * * assert.deepStrictEqual(min(2, 3), 2) * ``` @@ -386,7 +387,7 @@ export const min: { * @example * ```ts * import * as assert from "node:assert" - * import { max } from "effect/Number" + * import { max } from "effect/primitives/Number" * * assert.deepStrictEqual(max(2, 3), 3) * ``` @@ -405,7 +406,7 @@ export const max: { * @example * ```ts * import * as assert from "node:assert" - * import { sign } from "effect/Number" + * import { sign } from "effect/primitives/Number" * * assert.deepStrictEqual(sign(-5), -1) * assert.deepStrictEqual(sign(0), 0) @@ -423,7 +424,7 @@ export const sign = (n: number): Ordering => Order(n, 0) * @example * ```ts * import * as assert from "node:assert" - * import { sumAll } from "effect/Number" + * import { sumAll } from "effect/primitives/Number" * * assert.deepStrictEqual(sumAll([2, 3, 4]), 9) * ``` @@ -445,7 +446,7 @@ export const sumAll = (collection: Iterable): number => { * @example * ```ts * import * as assert from "node:assert" - * import { multiplyAll } from "effect/Number" + * import { multiplyAll } from "effect/primitives/Number" * * assert.deepStrictEqual(multiplyAll([2, 3, 4]), 24) * ``` @@ -472,7 +473,7 @@ export const multiplyAll = (collection: Iterable): number => { * @example * ```ts * import * as assert from "node:assert" - * import { remainder } from "effect/Number" + * import { remainder } from "effect/primitives/Number" * * assert.deepStrictEqual(remainder(2, 2), 0) * assert.deepStrictEqual(remainder(3, 2), 1) @@ -501,7 +502,7 @@ export const remainder: { * @example * ```ts * import * as assert from "node:assert" - * import { nextPow2 } from "effect/Number" + * import { nextPow2 } from "effect/primitives/Number" * * assert.deepStrictEqual(nextPow2(5), 8) * assert.deepStrictEqual(nextPow2(17), 32) @@ -522,7 +523,8 @@ export const nextPow2 = (n: number): number => { * @example * ```ts * import * as assert from "node:assert" - * import { Number, Option } from "effect" + * import { Option } from "effect/data" + * import * as Number from "effect/primitives/Number" * * assert.deepStrictEqual(Number.parse("42"), Option.some(42)) * assert.deepStrictEqual(Number.parse("3.14"), Option.some(3.14)) @@ -560,7 +562,7 @@ export const parse = (s: string): Option => { * @example * ```ts * import * as assert from "node:assert" - * import { round } from "effect/Number" + * import { round } from "effect/primitives/Number" * * assert.deepStrictEqual(round(1.1234, 2), 1.12) * assert.deepStrictEqual(round(1.567, 2), 1.57) diff --git a/packages/effect/src/RegExp.ts b/packages/effect/src/primitives/RegExp.ts similarity index 86% rename from packages/effect/src/RegExp.ts rename to packages/effect/src/primitives/RegExp.ts index acad9293ca..c96e2619d9 100644 --- a/packages/effect/src/RegExp.ts +++ b/packages/effect/src/primitives/RegExp.ts @@ -3,14 +3,14 @@ * * @since 2.0.0 */ -import * as predicate from "./Predicate.ts" +import * as predicate from "../data/Predicate.ts" /** * @since 4.0.0 * @category constructors * @example * ```ts - * import { RegExp } from "effect" + * import { RegExp } from "effect/primitives" * * // Create a regular expression using Effect's RegExp constructor * const pattern = new RegExp.RegExp("hello", "i") @@ -28,7 +28,7 @@ export const RegExp = globalThis.RegExp * @example * ```ts * import * as assert from "node:assert" - * import { RegExp } from "effect" + * import { RegExp } from "effect/primitives" * * assert.deepStrictEqual(RegExp.isRegExp(/a/), true) * assert.deepStrictEqual(RegExp.isRegExp("a"), false) @@ -45,7 +45,7 @@ export const isRegExp: (input: unknown) => input is RegExp = predicate.isRegExp * @example * ```ts * import * as assert from "node:assert" - * import { RegExp } from "effect" + * import { RegExp } from "effect/primitives" * * assert.deepStrictEqual(RegExp.escape("a*b"), "a\\*b") * ``` diff --git a/packages/effect/src/String.ts b/packages/effect/src/primitives/String.ts similarity index 87% rename from packages/effect/src/String.ts rename to packages/effect/src/primitives/String.ts index 9b270b793b..946cb9d072 100644 --- a/packages/effect/src/String.ts +++ b/packages/effect/src/primitives/String.ts @@ -6,23 +6,23 @@ * @since 2.0.0 */ -import type { NonEmptyArray } from "./Array.ts" -import * as equivalence from "./Equivalence.ts" -import { dual } from "./Function.ts" -import * as readonlyArray from "./internal/array.ts" -import * as number from "./Number.ts" -import * as Option from "./Option.ts" -import * as order from "./Order.ts" -import type * as Ordering from "./Ordering.ts" -import type { Refinement } from "./Predicate.ts" -import * as predicate from "./Predicate.ts" +import type { NonEmptyArray } from "../collections/Array.ts" +import * as equivalence from "../data/Equivalence.ts" +import * as Option from "../data/Option.ts" +import * as order from "../data/Order.ts" +import type * as Ordering from "../data/Ordering.ts" +import type { Refinement } from "../data/Predicate.ts" +import * as predicate from "../data/Predicate.ts" +import { dual } from "../Function.ts" +import * as readonlyArray from "../internal/array.ts" +import * as number from "../primitives/Number.ts" /** * Reference to the global `String` constructor. * * @example * ```ts - * import { String as EffectString } from "effect" + * import { String as EffectString } from "effect/primitives" * * // EffectString refers to the global String constructor * const str = "hello" @@ -40,7 +40,7 @@ export const String = globalThis.String * @example * ```ts * import * as assert from "node:assert" - * import { String } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(String.isString("a"), true) * assert.deepStrictEqual(String.isString(1), false) @@ -56,7 +56,7 @@ export const isString: Refinement = predicate.isString * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * console.log(String.Equivalence("hello", "hello")) // true * console.log(String.Equivalence("hello", "world")) // false @@ -72,7 +72,7 @@ export const Equivalence: equivalence.Equivalence = equivalence.string * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * console.log(String.Order("apple", "banana")) // -1 * console.log(String.Order("banana", "apple")) // 1 @@ -89,7 +89,7 @@ export const Order: order.Order = order.string * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * console.log(String.empty) // "" * console.log(String.isEmpty(String.empty)) // true @@ -105,7 +105,7 @@ export const empty: "" = "" as const * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * // Type-level concatenation * type Result = String.Concat<"hello", "world"> // "helloworld" @@ -121,7 +121,8 @@ export type Concat = `${A}${B}` * * @example * ```ts - * import { String, pipe } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * const result1 = String.concat("hello", "world") * console.log(result1) // "helloworld" @@ -144,7 +145,8 @@ export const concat: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe('a', String.toUpperCase), 'A') * assert.deepStrictEqual(String.toUpperCase('hello'), 'HELLO') @@ -161,7 +163,8 @@ export const toUpperCase = (self: S): Uppercase => self.toU * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe('A', String.toLowerCase), 'a') * assert.deepStrictEqual(String.toLowerCase('HELLO'), 'hello') @@ -178,7 +181,8 @@ export const toLowerCase = (self: T): Lowercase => self.toL * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe('abc', String.capitalize), 'Abc') * assert.deepStrictEqual(String.capitalize('hello'), 'Hello') @@ -199,7 +203,8 @@ export const capitalize = (self: T): Capitalize => { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe('ABC', String.uncapitalize), 'aBC') * assert.deepStrictEqual(String.uncapitalize('Hello'), 'hello') @@ -220,7 +225,8 @@ export const uncapitalize = (self: T): Uncapitalize => { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe('abc', String.replace('b', 'd')), 'adc') * assert.deepStrictEqual(pipe('hello world', String.replace('world', 'Effect')), 'hello Effect') @@ -237,7 +243,7 @@ export const replace = (searchValue: string | RegExp, replaceValue: string) => ( * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * type Result = String.Trim<" hello "> // "hello" * ``` @@ -253,7 +259,7 @@ export type Trim = TrimEnd> * @example * ```ts * import * as assert from "node:assert" - * import { String } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(String.trim(' a '), 'a') * assert.deepStrictEqual(String.trim(' hello world '), 'hello world') @@ -269,7 +275,7 @@ export const trim = (self: A): Trim => self.trim() as Trim< * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * type Result = String.TrimStart<" hello"> // "hello" * ``` @@ -285,7 +291,7 @@ export type TrimStart = A extends `${" " | "\n" | "\t" | "\r"} * @example * ```ts * import * as assert from "node:assert" - * import { String } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(String.trimStart(' a '), 'a ') * assert.deepStrictEqual(String.trimStart(' hello world'), 'hello world') @@ -301,7 +307,7 @@ export const trimStart = (self: A): TrimStart => self.trimS * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * type Result = String.TrimEnd<"hello "> // "hello" * ``` @@ -317,7 +323,7 @@ export type TrimEnd = A extends `${infer B}${" " | "\n" | "\t" * @example * ```ts * import * as assert from "node:assert" - * import { String } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(String.trimEnd(' a '), ' a') * assert.deepStrictEqual(String.trimEnd('hello world '), 'hello world') @@ -334,7 +340,8 @@ export const trimEnd = (self: A): TrimEnd => self.trimEnd() * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe('abcd', String.slice(1, 3)), 'bc') * assert.deepStrictEqual(pipe('hello world', String.slice(0, 5)), 'hello') @@ -351,7 +358,7 @@ export const slice = (start?: number, end?: number) => (self: string): string => * @example * ```ts * import * as assert from "node:assert" - * import { String } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(String.isEmpty(''), true) * assert.deepStrictEqual(String.isEmpty('a'), false) @@ -368,7 +375,7 @@ export const isEmpty = (self: string): self is "" => self.length === 0 * @example * ```ts * import * as assert from "node:assert" - * import { String } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(String.isNonEmpty(''), false) * assert.deepStrictEqual(String.isNonEmpty('a'), true) @@ -385,7 +392,7 @@ export const isNonEmpty = (self: string): boolean => self.length > 0 * @example * ```ts * import * as assert from "node:assert" - * import { String } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(String.length('abc'), 3) * ``` @@ -401,7 +408,8 @@ export const length = (self: string): number => self.length * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe('abc', String.split('')), ['a', 'b', 'c']) * assert.deepStrictEqual(pipe('', String.split('')), ['']) @@ -426,7 +434,8 @@ export const split: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe('hello world', String.includes('world')), true) * assert.deepStrictEqual(pipe('hello world', String.includes('foo')), false) @@ -444,7 +453,8 @@ export const includes = (searchString: string, position?: number) => (self: stri * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe('hello world', String.startsWith('hello')), true) * assert.deepStrictEqual(pipe('hello world', String.startsWith('world')), false) @@ -462,7 +472,8 @@ export const startsWith = (searchString: string, position?: number) => (self: st * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe('hello world', String.endsWith('world')), true) * assert.deepStrictEqual(pipe('hello world', String.endsWith('hello')), false) @@ -480,7 +491,9 @@ export const endsWith = (searchString: string, position?: number) => (self: stri * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String, Option } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("abc", String.charCodeAt(1)), Option.some(98)) * assert.deepStrictEqual(pipe("abc", String.charCodeAt(4)), Option.none()) @@ -504,7 +517,9 @@ export const charCodeAt: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String, Option } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("abcd", String.substring(1)), "bcd") * assert.deepStrictEqual(pipe("abcd", String.substring(1, 3)), "bc") @@ -521,7 +536,9 @@ export const substring = (start: number, end?: number) => (self: string): string * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String, Option } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("abc", String.at(1)), Option.some("b")) * assert.deepStrictEqual(pipe("abc", String.at(4)), Option.none()) @@ -541,7 +558,9 @@ export const at: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String, Option } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("abc", String.charAt(1)), Option.some("b")) * assert.deepStrictEqual(pipe("abc", String.charAt(4)), Option.none()) @@ -564,7 +583,9 @@ export const charAt: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String, Option } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("abc", String.codePointAt(1)), Option.some(98)) * assert.deepStrictEqual(pipe("abc", String.codePointAt(10)), Option.none()) @@ -584,7 +605,9 @@ export const codePointAt: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String, Option } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("abbbc", String.indexOf("b")), Option.some(1)) * assert.deepStrictEqual(pipe("abbbc", String.indexOf("z")), Option.none()) @@ -602,7 +625,9 @@ export const indexOf = (searchString: string) => (self: string): Option.Option (self: string): Option.Opti * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("a", String.localeCompare("b")), -1) * assert.deepStrictEqual(pipe("b", String.localeCompare("a")), 1) @@ -640,7 +666,9 @@ export const localeCompare = * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String, Option } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("hello", String.match(/l+/)), Option.some(["ll"])) * assert.deepStrictEqual(pipe("hello", String.match(/x/)), Option.none()) @@ -657,7 +685,8 @@ export const match = (regexp: RegExp | string) => (self: string): Option.Option< * * @example * ```ts - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * const matches = pipe("hello world", String.matchAll(/l/g)) * console.log(Array.from(matches)) // [["l"], ["l"], ["l"]] @@ -674,7 +703,8 @@ export const matchAll = (regexp: RegExp) => (self: string): IterableIterator (self: stri * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("a", String.padEnd(5)), "a ") * assert.deepStrictEqual(pipe("a", String.padEnd(5, "_")), "a____") @@ -713,7 +744,8 @@ export const padEnd = (maxLength: number, fillString?: string) => (self: string) * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("a", String.padStart(5)), " a") * assert.deepStrictEqual(pipe("a", String.padStart(5, "_")), "____a") @@ -731,7 +763,8 @@ export const padStart = (maxLength: number, fillString?: string) => (self: strin * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("a", String.repeat(5)), "aaaaa") * assert.deepStrictEqual(pipe("hello", String.repeat(3)), "hellohellohello") @@ -748,7 +781,8 @@ export const repeat = (count: number) => (self: string): string => self.repeat(c * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("ababb", String.replaceAll("b", "c")), "acacc") * assert.deepStrictEqual(pipe("ababb", String.replaceAll(/ba/g, "cc")), "accbb") @@ -766,7 +800,9 @@ export const replaceAll = (searchValue: string | RegExp, replaceValue: string) = * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String, Option } from "effect" + * import { pipe } from "effect" + * import { Option } from "effect/data" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(pipe("ababb", String.search("b")), Option.some(1)) * assert.deepStrictEqual(pipe("ababb", String.search(/abb/)), Option.some(2)) @@ -791,7 +827,8 @@ export const search: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * const str = "\u0130" * assert.deepStrictEqual(pipe(str, String.toLocaleLowerCase("tr")), "i") @@ -809,7 +846,8 @@ export const toLocaleLowerCase = (locale?: string | Array) => (self: str * @example * ```ts * import * as assert from "node:assert" - * import { pipe, String } from "effect" + * import { pipe } from "effect" + * import { String } from "effect/primitives" * * const str = "i\u0307" * assert.deepStrictEqual(pipe(str, String.toLocaleUpperCase("lt-LT")), "I") @@ -834,7 +872,7 @@ export const toLocaleUpperCase = (locale?: string | Array) => (self: str * @example * ```ts * import * as assert from "node:assert" - * import { String } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(String.takeLeft("Hello World", 5), "Hello") * ``` @@ -860,7 +898,7 @@ export const takeLeft: { * @example * ```ts * import * as assert from "node:assert" - * import { String } from "effect" + * import { String } from "effect/primitives" * * assert.deepStrictEqual(String.takeRight("Hello World", 5), "World") * ``` @@ -885,7 +923,7 @@ const LF = 0x0a * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * const lines = String.linesIterator("hello\nworld\n") * console.log(Array.from(lines)) // ["hello", "world"] @@ -902,7 +940,7 @@ export const linesIterator = (self: string): LinesIterator => linesSeparated(sel * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * const lines = String.linesWithSeparators("hello\nworld\n") * console.log(Array.from(lines)) // ["hello\n", "world\n"] @@ -920,7 +958,7 @@ export const linesWithSeparators = (s: string): LinesIterator => linesSeparated( * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * const text = " |hello\n |world" * const result = String.stripMarginWith(text, "|") @@ -959,7 +997,7 @@ export const stripMarginWith: { * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * const text = " |hello\n |world" * const result = String.stripMargin(text) @@ -976,7 +1014,7 @@ export const stripMargin = (self: string): string => stripMarginWith(self, "|") * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * console.log(String.snakeToCamel("hello_world")) // "helloWorld" * console.log(String.snakeToCamel("foo_bar_baz")) // "fooBarBaz" @@ -998,7 +1036,7 @@ export const snakeToCamel = (self: string): string => { * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * console.log(String.snakeToPascal("hello_world")) // "HelloWorld" * console.log(String.snakeToPascal("foo_bar_baz")) // "FooBarBaz" @@ -1020,7 +1058,7 @@ export const snakeToPascal = (self: string): string => { * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * console.log(String.snakeToKebab("hello_world")) // "hello-world" * console.log(String.snakeToKebab("foo_bar_baz")) // "foo-bar-baz" @@ -1036,7 +1074,7 @@ export const snakeToKebab = (self: string): string => self.replace(/_/g, "-") * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * console.log(String.camelToSnake("helloWorld")) // "hello_world" * console.log(String.camelToSnake("fooBarBaz")) // "foo_bar_baz" @@ -1052,7 +1090,7 @@ export const camelToSnake = (self: string): string => self.replace(/([A-Z])/g, " * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * console.log(String.pascalToSnake("HelloWorld")) // "hello_world" * console.log(String.pascalToSnake("FooBarBaz")) // "foo_bar_baz" @@ -1069,7 +1107,7 @@ export const pascalToSnake = (self: string): string => * * @example * ```ts - * import { String } from "effect" + * import { String } from "effect/primitives" * * console.log(String.kebabToSnake("hello-world")) // "hello_world" * console.log(String.kebabToSnake("foo-bar-baz")) // "foo_bar_baz" diff --git a/packages/effect/src/primitives/index.ts b/packages/effect/src/primitives/index.ts new file mode 100644 index 0000000000..7dc7ca15ad --- /dev/null +++ b/packages/effect/src/primitives/index.ts @@ -0,0 +1,63 @@ +/** + * @since 4.0.0 + */ + +/** + * This module provides utility functions and type class instances for working with the `BigDecimal` type in TypeScript. + * It includes functions for basic arithmetic operations, as well as type class instances for `Equivalence` and `Order`. + * + * A `BigDecimal` allows storing any real number to arbitrary precision; which avoids common floating point errors + * (such as 0.1 + 0.2 ≠ 0.3) at the cost of complexity. + * + * Internally, `BigDecimal` uses a `BigInt` object, paired with a 64-bit integer which determines the position of the + * decimal point. Therefore, the precision *is not* actually arbitrary, but limited to 263 decimal places. + * + * It is not recommended to convert a floating point number to a decimal directly, as the floating point representation + * may be unexpected. + * + * @since 2.0.0 + */ +export * as BigDecimal from "./BigDecimal.ts" + +/** + * This module provides utility functions and type class instances for working with the `bigint` type in TypeScript. + * It includes functions for basic arithmetic operations, as well as type class instances for + * `Equivalence` and `Order`. + * + * @since 2.0.0 + */ +export * as BigInt from "./BigInt.ts" + +/** + * This module provides utility functions and type class instances for working with the `boolean` type in TypeScript. + * It includes functions for basic boolean operations, as well as type class instances for + * `Equivalence` and `Order`. + * + * @since 2.0.0 + */ +export * as Boolean from "./Boolean.ts" + +/** + * This module provides utility functions and type class instances for working with the `number` type in TypeScript. + * It includes functions for basic arithmetic operations, as well as type class instances for + * `Equivalence` and `Order`. + * + * @since 2.0.0 + */ +export * as Number from "./Number.ts" + +/** + * This module provides utility functions for working with RegExp in TypeScript. + * + * @since 2.0.0 + */ +export * as RegExp from "./RegExp.ts" + +/** + * This module provides utility functions and type class instances for working with the `string` type in TypeScript. + * It includes functions for basic string manipulation, as well as type class instances for + * `Equivalence` and `Order`. + * + * @since 2.0.0 + */ +export * as String from "./String.ts" diff --git a/packages/effect/src/primitives/index.ts.tpl b/packages/effect/src/primitives/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/primitives/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/LayerMap.ts b/packages/effect/src/resources/LayerMap.ts similarity index 88% rename from packages/effect/src/LayerMap.ts rename to packages/effect/src/resources/LayerMap.ts index ff8544362f..c866cd7413 100644 --- a/packages/effect/src/LayerMap.ts +++ b/packages/effect/src/resources/LayerMap.ts @@ -2,21 +2,21 @@ * @since 3.14.0 * @experimental */ -import type * as Duration from "./Duration.ts" -import * as Effect from "./Effect.ts" -import { identity } from "./Function.ts" -import * as Layer from "./Layer.ts" -import * as RcMap from "./RcMap.ts" -import * as Scope from "./Scope.ts" -import * as ServiceMap from "./ServiceMap.ts" -import type { Mutable } from "./Types.ts" +import * as Effect from "../Effect.ts" +import { identity } from "../Function.ts" +import * as RcMap from "../resources/RcMap.ts" +import * as Scope from "../resources/Scope.ts" +import * as Layer from "../services/Layer.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import type * as Duration from "../time/Duration.ts" +import type { Mutable } from "../types/Types.ts" /** * @since 3.14.0 * @category Symbols * @example * ```ts - * import { LayerMap } from "effect" + * import { LayerMap } from "effect/resources" * * console.log(LayerMap.TypeId) * // Output: "~effect/LayerMap" @@ -29,7 +29,7 @@ export const TypeId: TypeId = "~effect/LayerMap" * @category Symbols * @example * ```ts - * import { LayerMap } from "effect" + * import { LayerMap } from "effect/resources" * * // Use the TypeId type for type checking * function isLayerMapTypeId(id: unknown): id is LayerMap.TypeId { @@ -45,7 +45,10 @@ export type TypeId = "~effect/LayerMap" * @experimental * @example * ```ts - * import { LayerMap, Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { LayerMap } from "effect/resources" * * // Define a service key * const DatabaseService = ServiceMap.Key<{ @@ -108,7 +111,9 @@ export interface LayerMap { * * @example * ```ts - * import { LayerMap, Layer, ServiceMap, Effect, Scope } from "effect" + * import { Effect } from "effect" + * import { Layer, ServiceMap } from "effect/services" + * import { LayerMap, Scope } from "effect/resources" * * // Define a service key * const DatabaseService = ServiceMap.Key<{ @@ -188,7 +193,9 @@ export const make: < * @experimental * @example * ```ts - * import { LayerMap, Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { LayerMap } from "effect/resources" + * import { Layer, ServiceMap } from "effect/services" * * // Define service keys * const DevDatabase = ServiceMap.Key<{ @@ -245,7 +252,10 @@ export const fromRecord = < * @category Service * @example * ```ts - * import { LayerMap, Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { LayerMap } from "effect/resources" * * // Define a service interface * interface DatabaseConfig { @@ -334,7 +344,11 @@ export interface TagClass< * * @example * ```ts - * import { LayerMap, Layer, ServiceMap, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { Console } from "effect/logging" + * import { LayerMap } from "effect/resources" * * // Define a service key * const Greeter = ServiceMap.Key<{ @@ -432,7 +446,9 @@ export const Service = () => * @experimental * @example * ```ts - * import { LayerMap, Layer, ServiceMap } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { LayerMap } from "effect/resources" * * // Define options for a database service * const databaseOptions = { @@ -460,7 +476,9 @@ export declare namespace Service { * @experimental * @example * ```ts - * import { LayerMap, Layer, ServiceMap } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { LayerMap } from "effect/resources" * * // Options with lookup function * const lookupOptions = { @@ -490,7 +508,9 @@ export declare namespace Service { * @experimental * @example * ```ts - * import { LayerMap, Layer, ServiceMap } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { LayerMap } from "effect/resources" * * // Options with lookup function * const lookupOptions = { @@ -520,7 +540,9 @@ export declare namespace Service { * @experimental * @example * ```ts - * import { LayerMap, Layer, ServiceMap } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { LayerMap } from "effect/resources" * * // Service interface * interface DatabaseService { @@ -550,7 +572,11 @@ export declare namespace Service { * @experimental * @example * ```ts - * import { LayerMap, Layer, ServiceMap, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { Data } from "effect/data" + * import { LayerMap } from "effect/resources" * * // Define a custom error type * class DatabaseConnectionError extends Data.TaggedError("DatabaseConnectionError")<{ @@ -579,7 +605,10 @@ export declare namespace Service { * @experimental * @example * ```ts - * import { LayerMap, Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { LayerMap } from "effect/resources" * * // Service that provides configuration * const ConfigService = ServiceMap.Key<{ diff --git a/packages/effect/src/RcMap.ts b/packages/effect/src/resources/RcMap.ts similarity index 91% rename from packages/effect/src/RcMap.ts rename to packages/effect/src/resources/RcMap.ts index f73167c98e..a4a2b2e015 100644 --- a/packages/effect/src/RcMap.ts +++ b/packages/effect/src/resources/RcMap.ts @@ -1,18 +1,18 @@ /** * @since 3.5.0 */ -import * as Cause from "./Cause.ts" -import * as Deferred from "./Deferred.ts" -import * as Duration from "./Duration.ts" -import * as Effect from "./Effect.ts" -import * as Exit from "./Exit.ts" -import * as Fiber from "./Fiber.ts" -import { dual } from "./Function.ts" -import * as MutableHashMap from "./MutableHashMap.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" -import * as Scope from "./Scope.ts" -import * as ServiceMap from "./ServiceMap.ts" +import * as Cause from "../Cause.ts" +import * as MutableHashMap from "../collections/MutableHashMap.ts" +import * as Deferred from "../concurrency/Deferred.ts" +import * as Effect from "../Effect.ts" +import * as Exit from "../Exit.ts" +import { dual } from "../Function.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import * as Scope from "../resources/Scope.ts" +import * as Fiber from "../runtime/Fiber.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import * as Duration from "../time/Duration.ts" /** * The unique identifier for the RcMap type. @@ -21,7 +21,7 @@ import * as ServiceMap from "./ServiceMap.ts" * @category type ids * @example * ```ts - * import { RcMap } from "effect" + * import { RcMap } from "effect/resources" * * // TypeId is used internally for type identification * console.log(RcMap.TypeId) // "~effect/RcMap" @@ -42,7 +42,7 @@ export const TypeId: TypeId = "~effect/RcMap" * @category type ids * @example * ```ts - * import { RcMap } from "effect" + * import { RcMap } from "effect/resources" * * // TypeId type represents the literal string identifier * type Id = RcMap.TypeId // "~effect/RcMap" @@ -65,7 +65,8 @@ export type TypeId = "~effect/RcMap" * @category models * @example * ```ts - * import { Effect, RcMap } from "effect" + * import { Effect } from "effect" + * import { RcMap } from "effect/resources" * * Effect.gen(function*() { * // Create an RcMap that manages database connections @@ -109,7 +110,7 @@ export interface RcMap extends Pipeable { * @category Models * @example * ```ts - * import { RcMap } from "effect" + * import { RcMap } from "effect/resources" * * // State is a union type that can be either: * declare const openState: RcMap.State.Open @@ -135,7 +136,7 @@ export type State = State.Open | State.Closed * @category Models * @example * ```ts - * import { RcMap } from "effect" + * import { RcMap } from "effect/resources" * * // The State namespace contains types for RcMap internal state: * // - Open: Contains the active resource map @@ -156,7 +157,8 @@ export declare namespace State { * @category Models * @example * ```ts - * import { MutableHashMap, RcMap } from "effect" + * import * as MutableHashMap from "effect/collections/MutableHashMap" + * import { RcMap } from "effect/resources" * * // State.Open contains the active resource map * declare const openState: RcMap.State.Open @@ -182,7 +184,7 @@ export declare namespace State { * @category Models * @example * ```ts - * import { RcMap } from "effect" + * import { RcMap } from "effect/resources" * * // State.Closed indicates the RcMap is shut down * declare const closedState: RcMap.State.Closed @@ -206,7 +208,11 @@ export declare namespace State { * @category Models * @example * ```ts - * import { Deferred, Effect, Fiber, RcMap, Scope } from "effect" + * import { Effect } from "effect" + * import { Deferred } from "effect/concurrency" + * import { Fiber } from "effect/runtime" + * import { RcMap } from "effect/resources" + * import { Scope } from "effect/resources" * * // Entry contains all metadata for a resource in the map * declare const entry: RcMap.State.Entry @@ -272,7 +278,8 @@ const unsafeMake = (options: { * @category models * @example * ```ts - * import { Effect, RcMap } from "effect" + * import { Effect } from "effect" + * import { RcMap } from "effect/resources" * * Effect.gen(function*() { * const map = yield* RcMap.make({ @@ -348,7 +355,8 @@ export const make: { * @category combinators * @example * ```ts - * import { Effect, RcMap } from "effect" + * import { Effect } from "effect" + * import { RcMap } from "effect/resources" * * Effect.gen(function*() { * const map = yield* RcMap.make({ @@ -479,7 +487,8 @@ const release = (self: RcMap, key: K, entry: State.Entry * @category combinators * @example * ```ts - * import { Effect, RcMap } from "effect" + * import { Effect } from "effect" + * import { RcMap } from "effect/resources" * * Effect.gen(function*() { * const map = yield* RcMap.make({ @@ -511,7 +520,8 @@ export const keys = (self: RcMap): Effect.Effect> => * @category combinators * @example * ```ts - * import { Effect, RcMap } from "effect" + * import { Effect } from "effect" + * import { RcMap } from "effect/resources" * * Effect.gen(function*() { * const map = yield* RcMap.make({ @@ -560,7 +570,8 @@ export const invalidate: { * @category combinators * @example * ```ts - * import { Effect, RcMap } from "effect" + * import { Effect } from "effect" + * import { RcMap } from "effect/resources" * * Effect.gen(function*() { * const map = yield* RcMap.make({ diff --git a/packages/effect/src/RcRef.ts b/packages/effect/src/resources/RcRef.ts similarity index 86% rename from packages/effect/src/RcRef.ts rename to packages/effect/src/resources/RcRef.ts index 4ad5cfbe66..dfe8937388 100644 --- a/packages/effect/src/RcRef.ts +++ b/packages/effect/src/resources/RcRef.ts @@ -1,18 +1,18 @@ /** * @since 3.5.0 */ -import type * as Duration from "./Duration.ts" -import type * as Effect from "./Effect.ts" -import * as internal from "./internal/rcRef.ts" -import type { Scope } from "./Scope.ts" -import type * as Types from "./Types.ts" +import type * as Effect from "../Effect.ts" +import * as internal from "../internal/rcRef.ts" +import type { Scope } from "../resources/Scope.ts" +import type * as Duration from "../time/Duration.ts" +import type * as Types from "../types/Types.ts" /** * @since 3.5.0 * @category type ids * @example * ```ts - * import { RcRef } from "effect" + * import { RcRef } from "effect/resources" * * // Check if a value has the RcRef type ID * const hasRcRefTypeId = (value: unknown): value is RcRef.RcRef => @@ -26,7 +26,7 @@ export const TypeId: TypeId = "~effect/RcRef" * @category type ids * @example * ```ts - * import type { RcRef } from "effect" + * import type { RcRef } from "effect/resources" * * // Use TypeId in type constraints * type HasRcRefTypeId = T extends { readonly [RcRef.TypeId]: any } ? T : never @@ -45,7 +45,8 @@ export type TypeId = "~effect/RcRef" * @category models * @example * ```ts - * import { Effect, RcRef } from "effect" + * import { Effect } from "effect" + * import { RcRef } from "effect/resources" * * // Create an RcRef for a database connection * const createConnectionRef = (connectionString: string) => @@ -77,7 +78,7 @@ export interface RcRef { * @category models * @example * ```ts - * import type { RcRef } from "effect" + * import type { RcRef } from "effect/resources" * * // Use RcRef namespace types * type MyRcRef = RcRef.RcRef @@ -90,7 +91,7 @@ export declare namespace RcRef { * @category models * @example * ```ts - * import type { RcRef } from "effect" + * import type { RcRef } from "effect/resources" * * // Variance interface defines covariance for type parameters * type StringRcRefVariance = RcRef.RcRef.Variance @@ -118,7 +119,8 @@ export declare namespace RcRef { * @category constructors * @example * ```ts - * import { Effect, RcRef } from "effect" + * import { Effect } from "effect" + * import { RcRef } from "effect/resources" * * Effect.gen(function*() { * const ref = yield* RcRef.make({ @@ -159,7 +161,8 @@ export const make: ( * @category combinators * @example * ```ts - * import { Effect, RcRef } from "effect" + * import { Effect } from "effect" + * import { RcRef } from "effect/resources" * * const program = Effect.gen(function* () { * // Create an RcRef with a resource diff --git a/packages/effect/src/Scope.ts b/packages/effect/src/resources/Scope.ts similarity index 86% rename from packages/effect/src/Scope.ts rename to packages/effect/src/resources/Scope.ts index 7a13955ad6..740480c62d 100644 --- a/packages/effect/src/Scope.ts +++ b/packages/effect/src/resources/Scope.ts @@ -14,17 +14,17 @@ * @since 2.0.0 */ -import type { Effect } from "./Effect.ts" -import type { Exit } from "./Exit.ts" -import * as effect from "./internal/effect.ts" -import type * as ServiceMap from "./ServiceMap.ts" +import type { Effect } from "../Effect.ts" +import type { Exit } from "../Exit.ts" +import * as effect from "../internal/effect.ts" +import type * as ServiceMap from "../services/ServiceMap.ts" /** * The unique identifier for the `Scope` type. * * @example * ```ts - * import { Scope } from "effect" + * import { Scope } from "effect/resources" * * const scope = Scope.unsafeMake() * console.log(scope[Scope.TypeId] === Scope.TypeId) @@ -41,7 +41,7 @@ export const TypeId: TypeId = effect.ScopeTypeId * * @example * ```ts - * import { Scope } from "effect" + * import { Scope } from "effect/resources" * * // The TypeId is used internally for type checking * type ScopeTypeId = Scope.TypeId @@ -59,7 +59,9 @@ export type TypeId = "~effect/Scope" * * @example * ```ts - * import { Scope, Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" + * import { Scope } from "effect/resources" * * const program = Effect.gen(function* () { * const scope = yield* Scope.make("sequential") @@ -88,7 +90,8 @@ export interface Scope { * * @example * ```ts - * import { Scope, Effect, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Scope } from "effect/resources" * * const program = Effect.gen(function* () { * const scope = yield* Scope.make() @@ -117,7 +120,8 @@ export declare namespace Scope { * * @example * ```ts - * import { Scope, Effect, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Scope } from "effect/resources" * * // Example of checking scope states * const program = Effect.gen(function* () { @@ -147,7 +151,8 @@ export declare namespace Scope { * * @example * ```ts - * import { Scope, Effect, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Scope } from "effect/resources" * * const scope = Scope.unsafeMake() * @@ -170,7 +175,8 @@ export declare namespace Scope { * * @example * ```ts - * import { Scope, Effect, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Scope } from "effect/resources" * * const scope = Scope.unsafeMake() * @@ -194,7 +200,8 @@ export declare namespace Scope { * * @example * ```ts - * import { Scope, Effect, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Scope } from "effect/resources" * * const program = Effect.gen(function* () { * const scope = yield* Scope.make() @@ -224,7 +231,9 @@ export declare namespace Scope { * * @example * ```ts - * import { Scope, Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" + * import { Scope } from "effect/resources" * * const program = Effect.gen(function* () { * const scope = yield* Scope.make() @@ -252,7 +261,8 @@ export declare namespace Scope { * * @example * ```ts - * import { Scope, Effect } from "effect" + * import { Effect } from "effect" + * import { Scope } from "effect/resources" * * const program = Effect.gen(function* () { * // Access the scope from the context @@ -276,7 +286,9 @@ export const Scope: ServiceMap.Key = effect.scopeTag * * @example * ```ts - * import { Scope, Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" + * import { Scope } from "effect/resources" * * const program = Effect.gen(function* () { * // Create a scope with sequential cleanup @@ -304,7 +316,9 @@ export const make: (finalizerStrategy?: "sequential" | "parallel") => Effect Scop * * @example * ```ts - * import { Scope, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { Scope } from "effect/resources" * * // An effect that requires a Scope * const program = Effect.gen(function* () { @@ -357,7 +373,9 @@ export const provide: { * * @example * ```ts - * import { Scope, Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" + * import { Scope } from "effect/resources" * * const withResource = Effect.gen(function* () { * const scope = yield* Scope.make() @@ -388,7 +406,9 @@ export const addFinalizerExit: (scope: Scope, finalizer: (exit: Exit) * * @example * ```ts - * import { Scope, Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" + * import { Scope } from "effect/resources" * * const program = Effect.gen(function* () { * const scope = yield* Scope.make() @@ -417,7 +437,9 @@ export const addFinalizer: (scope: Scope, finalizer: Effect) => Effect< * * @example * ```ts - * import { Scope, Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" + * import { Scope } from "effect/resources" * * const nestedScopes = Effect.gen(function* () { * const parentScope = yield* Scope.make("sequential") @@ -451,7 +473,9 @@ export const fork: ( * * @example * ```ts - * import { Scope, Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" + * import { Scope } from "effect/resources" * * const program = Effect.gen(function* () { * const parentScope = Scope.unsafeMake("sequential") @@ -479,7 +503,9 @@ export const unsafeFork: (scope: Scope, finalizerStrategy?: "sequential" | "para * * @example * ```ts - * import { Scope, Effect, Console, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Console } from "effect/logging" + * import { Scope } from "effect/resources" * * const resourceManagement = Effect.gen(function* () { * const scope = yield* Scope.make("sequential") diff --git a/packages/effect/src/resources/index.ts b/packages/effect/src/resources/index.ts new file mode 100644 index 0000000000..d1afa48922 --- /dev/null +++ b/packages/effect/src/resources/index.ts @@ -0,0 +1,36 @@ +/** + * @since 4.0.0 + */ + +/** + * @since 3.14.0 + * @experimental + */ +export * as LayerMap from "./LayerMap.ts" + +/** + * @since 3.5.0 + */ +export * as RcMap from "./RcMap.ts" + +/** + * @since 3.5.0 + */ +export * as RcRef from "./RcRef.ts" + +/** + * The `Scope` module provides functionality for managing resource lifecycles + * and cleanup operations in a functional and composable manner. + * + * A `Scope` represents a context where resources can be acquired and automatically + * cleaned up when the scope is closed. This is essential for managing resources + * like file handles, database connections, or any other resources that need + * proper cleanup. + * + * Scopes support both sequential and parallel finalization strategies: + * - Sequential: Finalizers run one after another in reverse order of registration + * - Parallel: Finalizers run concurrently for better performance + * + * @since 2.0.0 + */ +export * as Scope from "./Scope.ts" diff --git a/packages/effect/src/resources/index.ts.tpl b/packages/effect/src/resources/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/resources/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/Fiber.ts b/packages/effect/src/runtime/Fiber.ts similarity index 87% rename from packages/effect/src/Fiber.ts rename to packages/effect/src/runtime/Fiber.ts index f6c941d8b6..de08d65650 100644 --- a/packages/effect/src/Fiber.ts +++ b/packages/effect/src/runtime/Fiber.ts @@ -18,7 +18,9 @@ * * @example * ```ts - * import { Effect, Fiber, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { Fiber } from "effect/runtime" * * // Basic fiber operations * const basicExample = Effect.gen(function* () { @@ -72,24 +74,25 @@ * * @since 2.0.0 */ -import type { Effect } from "./Effect.ts" -import type { Exit } from "./Exit.ts" -import * as effect from "./internal/effect.ts" -import { version } from "./internal/version.ts" -import type { Pipeable } from "./Pipeable.ts" -import { hasProperty } from "./Predicate.ts" -import type { Scheduler } from "./Scheduler.ts" -import type { Scope } from "./Scope.ts" -import type * as ServiceMap from "./ServiceMap.ts" -import type { AnySpan, Span } from "./Tracer.ts" -import type { Covariant } from "./Types.ts" +import { hasProperty } from "../data/Predicate.ts" +import type { Effect } from "../Effect.ts" +import type { Exit } from "../Exit.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import * as effect from "../internal/effect.ts" +import { version } from "../internal/version.ts" +import type { AnySpan, Span } from "../observability/Tracer.ts" +import type { Scope } from "../resources/Scope.ts" +import type { Scheduler } from "../runtime/Scheduler.ts" +import type * as ServiceMap from "../services/ServiceMap.ts" +import type { Covariant } from "../types/Types.ts" /** * A unique identifier used to brand Fiber types. * * @example * ```ts - * import { Fiber, Effect } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * // TypeId is used internally for type branding * const fiber = Effect.runFork(Effect.succeed(42)) @@ -106,7 +109,7 @@ export const TypeId: TypeId = `~effect/Fiber/${version}` * * @example * ```ts - * import { Fiber } from "effect" + * import { Fiber } from "effect/runtime" * * type FiberTypeId = Fiber.TypeId * ``` @@ -124,7 +127,8 @@ export type TypeId = `~effect/Fiber/${version}` * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * // Fork an effect to run in a new fiber @@ -163,7 +167,8 @@ export interface Fiber extends Pipeable { * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * // Create a fiber @@ -191,7 +196,7 @@ export declare namespace Fiber { * * @example * ```ts - * import { Fiber } from "effect" + * import { Fiber } from "effect/runtime" * * // Variance allows safe subtyping * declare const fiber: Fiber.Fiber @@ -214,7 +219,8 @@ export { * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const fiber = yield* Effect.fork(Effect.succeed(42)) @@ -234,7 +240,8 @@ export { * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const fiber1 = yield* Effect.fork(Effect.succeed(1)) @@ -264,7 +271,8 @@ export const awaitAll: >( * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const fiber = yield* Effect.fork(Effect.succeed(42)) @@ -284,7 +292,8 @@ export const join: (self: Fiber) => Effect = effect.fiberJoin * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const fiber = yield* Effect.fork(Effect.delay("1 second")(Effect.succeed(42))) @@ -303,7 +312,8 @@ export const interrupt: (self: Fiber) => Effect = effect.fiber * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const fiber1 = yield* Effect.fork(Effect.delay("1 second")(Effect.succeed(1))) @@ -327,7 +337,9 @@ export const interruptAs: { * * @example * ```ts - * import { Effect, Fiber, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * // Create multiple long-running fibers @@ -377,7 +389,9 @@ export const interruptAll: >>( * * @example * ```ts - * import { Effect, Fiber, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * // Create a controlling fiber @@ -422,7 +436,8 @@ export const interruptAllAs: { * * @example * ```ts - * import { Effect, Fiber } from "effect" + * import { Effect } from "effect" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * // Create a fiber @@ -456,7 +471,9 @@ export const isFiber = ( * * @example * ```ts - * import { Effect, Fiber, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { Fiber } from "effect/runtime" * * const program = Effect.gen(function* () { * const current = Fiber.getCurrent() diff --git a/packages/effect/src/ManagedRuntime.ts b/packages/effect/src/runtime/ManagedRuntime.ts similarity index 92% rename from packages/effect/src/ManagedRuntime.ts rename to packages/effect/src/runtime/ManagedRuntime.ts index 7f1fe0a043..6e593daa7c 100644 --- a/packages/effect/src/ManagedRuntime.ts +++ b/packages/effect/src/runtime/ManagedRuntime.ts @@ -1,14 +1,14 @@ /** * @since 2.0.0 */ -import * as Effect from "./Effect.ts" -import * as Exit from "./Exit.ts" -import * as Fiber from "./Fiber.ts" -import * as Layer from "./Layer.ts" -import { hasProperty } from "./Predicate.ts" -import * as Scope from "./Scope.ts" -import type * as ServiceMap from "./ServiceMap.ts" -import type { Mutable } from "./Types.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Effect from "../Effect.ts" +import * as Exit from "../Exit.ts" +import * as Scope from "../resources/Scope.ts" +import * as Fiber from "../runtime/Fiber.ts" +import * as Layer from "../services/Layer.ts" +import type * as ServiceMap from "../services/ServiceMap.ts" +import type { Mutable } from "../types/Types.ts" /** * @since 3.9.0 @@ -141,7 +141,11 @@ export interface ManagedRuntime { * @category runtime class * @example * ```ts - * import { Console, Effect, Layer, ManagedRuntime, ServiceMap } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { Console } from "effect/logging" + * import { ServiceMap } from "effect/services" + * import { ManagedRuntime } from "effect/runtime" * * class Notifications extends ServiceMap.Key< * Notifications, diff --git a/packages/effect/src/Runtime.ts b/packages/effect/src/runtime/Runtime.ts similarity index 93% rename from packages/effect/src/Runtime.ts rename to packages/effect/src/runtime/Runtime.ts index 043642ecfe..de826bb753 100644 --- a/packages/effect/src/Runtime.ts +++ b/packages/effect/src/runtime/Runtime.ts @@ -7,7 +7,9 @@ * * @example * ```ts - * import { Effect, Runtime, Fiber } from "effect" + * import { Effect } from "effect" + * import { Runtime } from "effect/runtime" + * import { Fiber } from "effect/runtime" * * // Create a main runner for Node.js * const runMain = Runtime.makeRunMain((options) => { @@ -29,8 +31,8 @@ import * as Cause from "effect/Cause" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import type * as Fiber from "effect/Fiber" import { dual } from "effect/Function" +import type * as Fiber from "../runtime/Fiber.ts" /** * Represents a teardown function that handles program completion and determines the exit code. @@ -43,7 +45,8 @@ import { dual } from "effect/Function" * * @example * ```ts - * import { Effect, Exit, Runtime } from "effect" + * import { Effect, Exit } from "effect" + * import { Runtime } from "effect/runtime" * * // Custom teardown that logs completion status * const customTeardown: Runtime.Teardown = (exit, onExit) => { @@ -86,7 +89,8 @@ export interface Teardown { * * @example * ```ts - * import { Effect, Exit, Runtime, Cause } from "effect" + * import { Effect, Exit, Cause } from "effect" + * import { Runtime } from "effect/runtime" * * // The default teardown behavior * const program1 = Effect.succeed(42) @@ -131,7 +135,9 @@ export const defaultTeardown: Teardown = ( * * @example * ```ts - * import { Effect, Runtime, Fiber } from "effect" + * import { Effect } from "effect" + * import { Runtime } from "effect/runtime" + * import { Fiber } from "effect/runtime" * * // Create a simple runner for a hypothetical platform * const runMain = Runtime.makeRunMain(({ fiber, teardown }) => { diff --git a/packages/effect/src/Scheduler.ts b/packages/effect/src/runtime/Scheduler.ts similarity index 95% rename from packages/effect/src/Scheduler.ts rename to packages/effect/src/runtime/Scheduler.ts index 4706c38aaa..3e4dad6ea4 100644 --- a/packages/effect/src/Scheduler.ts +++ b/packages/effect/src/runtime/Scheduler.ts @@ -1,8 +1,8 @@ /** * @since 2.0.0 */ -import type * as Fiber from "./Fiber.ts" -import * as ServiceMap from "./ServiceMap.ts" +import type * as Fiber from "../runtime/Fiber.ts" +import * as ServiceMap from "../services/ServiceMap.ts" /** * A scheduler manages the execution of Effects by controlling when and how tasks @@ -16,8 +16,9 @@ import * as ServiceMap from "./ServiceMap.ts" * * @example * ```ts - * import { Effect, type Fiber } from "effect" - * import type { Scheduler } from "effect/Scheduler" + * import { Effect } from "effect" + * import type { Fiber } from "effect/runtime" + * import type { Scheduler } from "effect/runtime/Scheduler" * * // Create a custom scheduler implementation * class CustomScheduler implements Scheduler { @@ -100,7 +101,7 @@ const setImmediate = "setImmediate" in globalThis * * @example * ```ts - * import { MixedScheduler } from "effect/Scheduler" + * import { MixedScheduler } from "effect/runtime/Scheduler" * * // Create a mixed scheduler with async execution (default) * const asyncScheduler = new MixedScheduler("async") @@ -201,7 +202,7 @@ export class MixedScheduler implements Scheduler { * @example * ```ts * import { Effect } from "effect" - * import { MaxOpsBeforeYield } from "effect/Scheduler" + * import { MaxOpsBeforeYield } from "effect/runtime/Scheduler" * * // Configure a fiber to yield more frequently * const program = Effect.gen(function* () { diff --git a/packages/effect/src/runtime/index.ts b/packages/effect/src/runtime/index.ts new file mode 100644 index 0000000000..60bfc4e6b7 --- /dev/null +++ b/packages/effect/src/runtime/index.ts @@ -0,0 +1,123 @@ +/** + * @since 4.0.0 + */ + +/** + * This module provides utilities for working with `Fiber`, the fundamental unit of + * concurrency in Effect. Fibers are lightweight, user-space threads that allow + * multiple Effects to run concurrently with structured concurrency guarantees. + * + * Key characteristics of Fibers: + * - **Lightweight**: Much lighter than OS threads, you can create millions + * - **Structured concurrency**: Parent fibers manage child fiber lifecycles + * - **Cancellation safety**: Proper resource cleanup when interrupted + * - **Cooperative**: Fibers yield control at effect boundaries + * - **Traceable**: Each fiber has an ID for debugging and monitoring + * + * Common patterns: + * - **Fork and join**: Start concurrent work and wait for results + * - **Race conditions**: Run multiple effects, take the first to complete + * - **Supervision**: Monitor and restart failed fibers + * - **Resource management**: Ensure proper cleanup on interruption + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { Fiber } from "effect/runtime" + * + * // Basic fiber operations + * const basicExample = Effect.gen(function* () { + * // Fork an effect to run concurrently + * const fiber = yield* Effect.fork( + * Effect.gen(function* () { + * yield* Effect.sleep("2 seconds") + * yield* Console.log("Background task completed") + * return "background result" + * }) + * ) + * + * // Do other work while the fiber runs + * yield* Console.log("Doing other work...") + * yield* Effect.sleep("1 second") + * + * // Wait for the fiber to complete + * const result = yield* Fiber.join(fiber) + * yield* Console.log(`Fiber result: ${result}`) + * }) + * + * // Joining multiple fibers + * const joinExample = Effect.gen(function* () { + * const task1 = Effect.delay(Effect.succeed("task1"), "1 second") + * const task2 = Effect.delay(Effect.succeed("task2"), "2 seconds") + * + * // Start both effects as fibers + * const fiber1 = yield* Effect.fork(task1) + * const fiber2 = yield* Effect.fork(task2) + * + * // Wait for both to complete + * const result1 = yield* Fiber.join(fiber1) + * const result2 = yield* Fiber.join(fiber2) + * return [result1, result2] // ["task1", "task2"] + * }) + * + * // Parallel execution with structured concurrency + * const parallelExample = Effect.gen(function* () { + * const tasks = [1, 2, 3, 4, 5].map(n => + * Effect.gen(function* () { + * yield* Effect.sleep(`${n * 100} millis`) + * return n * n + * }) + * ) + * + * // Run all tasks in parallel, wait for all to complete + * const results = yield* Effect.all(tasks, { concurrency: "unbounded" }) + * return results // [1, 4, 9, 16, 25] + * }) + * ``` + * + * @since 2.0.0 + */ +export * as Fiber from "./Fiber.ts" + +/** + * @since 2.0.0 + */ +export * as ManagedRuntime from "./ManagedRuntime.ts" + +/** + * This module provides utilities for running Effect programs and managing their execution lifecycle. + * + * The Runtime module contains functions for creating main program runners that handle process + * teardown, error reporting, and exit code management. These utilities are particularly useful + * for creating CLI applications and server processes that need to manage their lifecycle properly. + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Runtime } from "effect/runtime" + * import { Fiber } from "effect/runtime" + * + * // Create a main runner for Node.js + * const runMain = Runtime.makeRunMain((options) => { + * process.on('SIGINT', () => Effect.runFork(Fiber.interrupt(options.fiber))) + * process.on('SIGTERM', () => Effect.runFork(Fiber.interrupt(options.fiber))) + * + * options.fiber.addObserver((exit) => { + * options.teardown(exit, (code) => process.exit(code)) + * }) + * }) + * + * // Use the runner + * const program = Effect.log("Hello, World!") + * runMain(program) + * ``` + * + * @since 4.0.0 + */ +export * as Runtime from "./Runtime.ts" + +/** + * @since 2.0.0 + */ +export * as Scheduler from "./Scheduler.ts" diff --git a/packages/effect/src/runtime/index.ts.tpl b/packages/effect/src/runtime/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/runtime/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/Schedule.ts b/packages/effect/src/scheduling/Schedule.ts similarity index 93% rename from packages/effect/src/Schedule.ts rename to packages/effect/src/scheduling/Schedule.ts index 696a8b146d..48e8669dd4 100644 --- a/packages/effect/src/Schedule.ts +++ b/packages/effect/src/scheduling/Schedule.ts @@ -8,7 +8,9 @@ * * @example * ```ts - * import { Effect, Schedule, Duration } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Duration } from "effect/time" * * // Retry with exponential backoff * const retryPolicy = Schedule.exponential("100 millis", 2.0) @@ -29,26 +31,26 @@ * * @since 2.0.0 */ -import * as Cron from "./Cron.ts" -import type * as DateTime from "./DateTime.ts" -import * as Duration from "./Duration.ts" -import type { Effect } from "./Effect.ts" -import type { LazyArg } from "./Function.ts" -import { constant, constTrue, dual, identity } from "./Function.ts" -import { isEffect } from "./internal/core.ts" -import * as effect from "./internal/effect.ts" -import { type Pipeable, pipeArguments } from "./Pipeable.ts" -import { hasProperty } from "./Predicate.ts" -import * as Pull from "./Pull.ts" -import * as Result from "./Result.ts" -import type { Contravariant, Covariant } from "./Types.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Result from "../data/Result.ts" +import type { Effect } from "../Effect.ts" +import type { LazyArg } from "../Function.ts" +import { constant, constTrue, dual, identity } from "../Function.ts" +import { type Pipeable, pipeArguments } from "../interfaces/Pipeable.ts" +import { isEffect } from "../internal/core.ts" +import * as effect from "../internal/effect.ts" +import * as Pull from "../stream/Pull.ts" +import * as Cron from "../time/Cron.ts" +import type * as DateTime from "../time/DateTime.ts" +import * as Duration from "../time/Duration.ts" +import type { Contravariant, Covariant } from "../types/Types.ts" /** * Unique identifier for Schedule types, used for type branding and runtime identification. * * @example * ```ts - * import { Schedule } from "effect" + * import { Schedule } from "effect/scheduling" * * console.log(Schedule.TypeId) // "~effect/Schedule" * @@ -67,7 +69,7 @@ export const TypeId: TypeId = "~effect/Schedule" * * @example * ```ts - * import { Schedule } from "effect" + * import { Schedule } from "effect/scheduling" * * // Type-level usage * type MyTypeId = Schedule.TypeId // "~effect/Schedule" @@ -88,7 +90,9 @@ export type TypeId = "~effect/Schedule" * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Basic retry schedule - retry up to 3 times with exponential backoff * const retrySchedule = Schedule.exponential("100 millis").pipe( @@ -128,7 +132,9 @@ export interface Schedule n + 1).pipe( @@ -320,7 +334,7 @@ const ScheduleProto = { * * @example * ```ts - * import { Schedule } from "effect" + * import { Schedule } from "effect/scheduling" * * const schedule = Schedule.exponential("100 millis") * const notSchedule = { foo: "bar" } @@ -341,7 +355,8 @@ export const isSchedule = (u: unknown): u is Schedule => has * * @example * ```ts - * import { Schedule, Effect } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" * * // fromStep is an advanced function for creating custom schedules * // It requires a step function that returns a Pull value @@ -390,7 +405,8 @@ const metadataFn = () => { * * @example * ```ts - * import { Schedule, Effect } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" * * // fromStepWithMetadata is an advanced function for creating schedules * // that need access to execution metadata like timing and recurrence count @@ -426,7 +442,8 @@ export const fromStepWithMetadata = ( * * @example * ```ts - * import { Schedule, Effect } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" * * // Extract step function from an existing schedule * const schedule = Schedule.exponential("100 millis").pipe(Schedule.take(3)) @@ -462,7 +479,8 @@ export const toStep = ( * * @example * ```ts - * import { Schedule, Effect } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" * * // Convert schedule to step function with automatic sleeping * const schedule = Schedule.spaced("1 second").pipe(Schedule.take(3)) @@ -511,7 +529,9 @@ export const toStepWithSleep = ( * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Add random jitter to schedule delays * const jitteredSchedule = Schedule.addDelay( @@ -661,7 +681,9 @@ export const addDelay: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // First retry 3 times quickly, then switch to slower retries * const quickRetries = Schedule.exponential("100 millis").pipe( @@ -719,7 +741,10 @@ export const andThen: { * * @example * ```ts - * import { Effect, Schedule, Console, Result } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Result } from "effect/data" + * import { Console } from "effect/logging" * * // Track which phase of the schedule we're in * const phaseTracker = Schedule.andThenResult( @@ -799,7 +824,9 @@ export const andThenResult: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Both schedules must want to continue for the combined schedule to continue * const timeLimit = Schedule.spaced("1 second").pipe(Schedule.take(5)) // max 5 times @@ -882,7 +909,9 @@ export const both: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Combine two schedules, keeping left output * const leftSchedule = Schedule.exponential("100 millis").pipe( @@ -928,7 +957,9 @@ export const bothLeft: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Combine two schedules, keeping right output * const leftSchedule = Schedule.exponential("100 millis").pipe( @@ -977,7 +1008,9 @@ export const bothRight: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Combine two schedules with custom output combination * const leftSchedule = Schedule.exponential("100 millis").pipe( @@ -1054,7 +1087,9 @@ export const bothWith: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Compose a quick retry phase followed by slower retry phase * const fastRetries = Schedule.exponential("100 millis").pipe( @@ -1130,7 +1165,9 @@ export const compose: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Collect all inputs passed to the schedule * const inputCollector = Schedule.collectInputs( @@ -1163,7 +1200,9 @@ export const collectInputs = ( * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Collect all outputs from the schedule * const outputCollector = Schedule.collectOutputs( @@ -1194,7 +1233,9 @@ export const collectOutputs = ( * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Collect outputs while under time limit * const collectForTime = Schedule.collectWhile( @@ -1321,7 +1362,9 @@ export const collectWhile: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Run every minute * const everyMinute = Schedule.cron("* * * * *") @@ -1454,7 +1497,9 @@ export const cron: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Extract delays from an exponential backoff schedule * const exponentialDelays = Schedule.delays( @@ -1554,7 +1599,9 @@ export const delays = (self: Schedule): Schedule = fromStepWithMetadata( * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Basic exponential backoff with default factor of 2 * const basicExponential = Schedule.exponential("100 millis") @@ -2003,7 +2063,9 @@ export const exponential = ( * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Basic fibonacci schedule starting with 100ms * const fibSchedule = Schedule.fibonacci("100 millis") @@ -2091,7 +2153,9 @@ export const fibonacci = (one: Duration.DurationInput): Schedule => { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Transform schedule output from number to string * const countSchedule = Schedule.recurs(5).pipe( @@ -2247,7 +2313,10 @@ export const map: { * * @example * ```ts - * import { Effect, Schedule, Duration, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Duration } from "effect/time" + * import { Console } from "effect/logging" * * // Modify delays based on output - increase delay on high iteration counts * const adaptiveDelay = Schedule.recurs(10).pipe( @@ -2312,7 +2381,9 @@ export const modifyDelay: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Create a schedule that outputs the inputs instead of original outputs * const inputSchedule = Schedule.passthrough( @@ -2351,7 +2422,9 @@ export const passthrough = ( * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Basic recurs - retry at most 3 times * const maxThreeAttempts = Schedule.recurs(3) @@ -2408,7 +2481,9 @@ export const recurs = (times: number): Schedule => while_(forever, ({ re * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Sum up execution counts from a counter schedule * const sumSchedule = Schedule.reduce( @@ -2556,7 +2631,9 @@ export const reduce: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Basic spaced schedule - runs every 2 seconds * const everyTwoSeconds = Schedule.spaced("2 seconds") @@ -2611,7 +2688,9 @@ export const spaced = (duration: Duration.DurationInput): Schedule => { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Log retry errors for debugging * const errorLoggingSchedule = Schedule.exponential("100 millis").pipe( @@ -2746,7 +2825,9 @@ export const tapInput: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Log schedule outputs for debugging/monitoring * const monitoredSchedule = Schedule.exponential("100 millis").pipe( @@ -2850,7 +2931,9 @@ export const tapOutput: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Limit an infinite schedule to run only 5 times * const limitedHeartbeat = Schedule.spaced("1 second").pipe( @@ -2938,7 +3021,9 @@ export const take: { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Counter schedule that increments by 1 each time * const counterSchedule = Schedule.unfold(0, (n) => n + 1) @@ -3096,7 +3181,9 @@ export { * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // Execute tasks at regular intervals aligned to window boundaries * const windowSchedule = Schedule.windowed("5 seconds") @@ -3134,7 +3221,9 @@ export const windowed = (interval: Duration.DurationInput): Schedule => * * @example * ```ts - * import { Effect, Schedule, Console } from "effect" + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Console } from "effect/logging" * * // A schedule that runs forever with no delay * const infiniteSchedule = Schedule.forever @@ -3160,7 +3249,7 @@ export const forever: Schedule = spaced(Duration.zero) * * @example * ```ts - * import { Schedule } from "effect" + * import { Schedule } from "effect/scheduling" * * // Ensure schedule accepts string inputs * const stringSchedule = Schedule.exponential("100 millis").pipe( @@ -3190,7 +3279,8 @@ export const ensureInput = () => * * @example * ```ts - * import { Schedule, Duration } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Duration } from "effect/time" * * // ensureOutput is a type-level function for compile-time constraints * // It ensures that a schedule's output type matches the specified type @@ -3215,7 +3305,8 @@ export const ensureOutput = () => * * @example * ```ts - * import { Schedule, Data } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Data } from "effect/data" * * // Create a custom error using Data.TaggedError * class CustomError extends Data.TaggedError("CustomError")<{ @@ -3246,7 +3337,7 @@ export const ensureError = () => * * @example * ```ts - * import { Schedule } from "effect" + * import { Schedule } from "effect/scheduling" * * // Define service interfaces (type-level only) * interface Logger { diff --git a/packages/effect/src/scheduling/index.ts b/packages/effect/src/scheduling/index.ts new file mode 100644 index 0000000000..287f3ed506 --- /dev/null +++ b/packages/effect/src/scheduling/index.ts @@ -0,0 +1,38 @@ +/** + * @since 4.0.0 + */ + +/** + * This module provides utilities for creating and composing schedules for retrying operations, + * repeating effects, and implementing various timing strategies. + * + * A Schedule is a function that takes an input and returns a decision whether to continue or halt, + * along with a delay duration. Schedules can be combined, transformed, and used to implement + * sophisticated retry and repetition logic. + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Schedule } from "effect/scheduling" + * import { Duration } from "effect/time" + * + * // Retry with exponential backoff + * const retryPolicy = Schedule.exponential("100 millis", 2.0) + * .pipe(Schedule.compose(Schedule.recurs(3))) + * + * const program = Effect.gen(function*() { + * // This will retry up to 3 times with exponential backoff + * const result = yield* Effect.retry( + * Effect.fail("Network error"), + * retryPolicy + * ) + * }) + * + * // Repeat on a fixed schedule + * const heartbeat = Effect.log("heartbeat") + * .pipe(Effect.repeat(Schedule.spaced("30 seconds"))) + * ``` + * + * @since 2.0.0 + */ +export * as Schedule from "./Schedule.ts" diff --git a/packages/effect/src/scheduling/index.ts.tpl b/packages/effect/src/scheduling/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/scheduling/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/schema/AST.ts b/packages/effect/src/schema/AST.ts index 4eebe518c8..4b6b69223c 100644 --- a/packages/effect/src/schema/AST.ts +++ b/packages/effect/src/schema/AST.ts @@ -2,14 +2,14 @@ * @since 4.0.0 */ -import * as Arr from "../Array.ts" +import * as Arr from "../collections/Array.ts" +import * as Option from "../data/Option.ts" +import * as Predicate from "../data/Predicate.ts" +import * as Result from "../data/Result.ts" import * as Effect from "../Effect.ts" import * as internalRecord from "../internal/record.ts" import { formatPropertyKey, memoizeThunk, ownKeys } from "../internal/schema/util.ts" -import * as Option from "../Option.ts" -import * as Predicate from "../Predicate.ts" -import * as RegEx from "../RegExp.ts" -import * as Result from "../Result.ts" +import * as RegEx from "../primitives/RegExp.ts" import type { Annotated } from "./Annotations.ts" import type * as Annotations from "./Annotations.ts" import type * as Check from "./Check.ts" diff --git a/packages/effect/src/schema/Annotations.ts b/packages/effect/src/schema/Annotations.ts index cda000a03c..e0cdd11b6e 100644 --- a/packages/effect/src/schema/Annotations.ts +++ b/packages/effect/src/schema/Annotations.ts @@ -52,7 +52,7 @@ export interface Key extends Documentation { * @since 4.0.0 */ export interface JsonSchema extends Documentation { - readonly id?: string | undefined + readonly identifier?: string | undefined readonly default?: T | undefined readonly examples?: ReadonlyArray | undefined /** diff --git a/packages/effect/src/schema/Check.ts b/packages/effect/src/schema/Check.ts index 6f027e05df..d0cf4e91b0 100644 --- a/packages/effect/src/schema/Check.ts +++ b/packages/effect/src/schema/Check.ts @@ -2,14 +2,14 @@ * @since 4.0.0 */ -import * as Arr from "../Array.ts" -import type { Brand } from "../Brand.ts" -import type * as Equivalence from "../Equivalence.ts" +import * as Arr from "../collections/Array.ts" +import type { Brand } from "../data/Brand.ts" +import type * as Equivalence from "../data/Equivalence.ts" +import * as Option from "../data/Option.ts" +import * as Order from "../data/Order.ts" +import * as Predicate from "../data/Predicate.ts" import { formatUnknown, PipeableClass } from "../internal/schema/util.ts" -import * as Num from "../Number.ts" -import * as Option from "../Option.ts" -import * as Order from "../Order.ts" -import * as Predicate from "../Predicate.ts" +import * as Num from "../primitives/Number.ts" import type * as Annotations from "./Annotations.ts" import type * as AST from "./AST.ts" import * as Issue from "./Issue.ts" diff --git a/packages/effect/src/schema/Formatter.ts b/packages/effect/src/schema/Formatter.ts index 6fb27c5290..84bf3b0aeb 100644 --- a/packages/effect/src/schema/Formatter.ts +++ b/packages/effect/src/schema/Formatter.ts @@ -3,10 +3,10 @@ */ import type { StandardSchemaV1 } from "@standard-schema/spec" import * as Cause from "../Cause.ts" +import * as Option from "../data/Option.ts" +import * as Predicate from "../data/Predicate.ts" import * as Effect from "../Effect.ts" import { formatPath, formatUnknown } from "../internal/schema/util.ts" -import * as Option from "../Option.ts" -import * as Predicate from "../Predicate.ts" import type * as Annotations from "./Annotations.ts" import * as AST from "./AST.ts" import * as Check from "./Check.ts" @@ -182,15 +182,15 @@ export function formatAST( } } let checks: string = "" - const id = ast.annotations?.id - if (Predicate.isString(id)) { - out = id + const identifier = ast.annotations?.identifier + if (Predicate.isString(identifier)) { + out = identifier } if (ast.checks) { for (const check of ast.checks) { - const id = check.annotations?.id - if (Predicate.isString(id)) { - out = id + const identifier = check.annotations?.identifier + if (Predicate.isString(identifier)) { + out = identifier checks = "" } else { checks += ` & ${formatCheck(check)}` diff --git a/packages/effect/src/schema/Getter.ts b/packages/effect/src/schema/Getter.ts index e84fc6cbf2..01174d4897 100644 --- a/packages/effect/src/schema/Getter.ts +++ b/packages/effect/src/schema/Getter.ts @@ -1,11 +1,11 @@ /** * @since 4.0.0 */ +import * as Option from "../data/Option.ts" +import * as Predicate from "../data/Predicate.ts" import * as Effect from "../Effect.ts" import { PipeableClass } from "../internal/schema/util.ts" -import * as Option from "../Option.ts" -import * as Predicate from "../Predicate.ts" -import * as Str from "../String.ts" +import * as Str from "../primitives/String.ts" import type * as Annotations from "./Annotations.ts" import type * as AST from "./AST.ts" import * as Check from "./Check.ts" diff --git a/packages/effect/src/schema/Issue.ts b/packages/effect/src/schema/Issue.ts index b67537ba4e..05264877ed 100644 --- a/packages/effect/src/schema/Issue.ts +++ b/packages/effect/src/schema/Issue.ts @@ -1,8 +1,8 @@ /** * @since 4.0.0 */ -import * as Option from "../Option.ts" -import { hasProperty } from "../Predicate.ts" +import * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" import type * as Annotations from "./Annotations.ts" import type * as AST from "./AST.ts" import type * as Check from "./Check.ts" diff --git a/packages/effect/src/schema/MetaAST.ts b/packages/effect/src/schema/MetaAST.ts index 71a5e8c02e..7960e13837 100644 --- a/packages/effect/src/schema/MetaAST.ts +++ b/packages/effect/src/schema/MetaAST.ts @@ -14,7 +14,7 @@ import * as Transformation from "./Transformation.ts" export const Declaration = Schema.instanceOf({ constructor: ast.Declaration, annotations: { - id: "Declaration", + identifier: "Declaration", "~sentinels": [{ key: "_tag", literal: "Declaration" }] } }) @@ -25,7 +25,7 @@ export const Declaration = Schema.instanceOf({ export const NullKeyword = Schema.instanceOf({ constructor: ast.NullKeyword, annotations: { - id: "NullKeyword", + identifier: "NullKeyword", "~sentinels": [{ key: "_tag", literal: "NullKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -46,7 +46,7 @@ export const NullKeyword = Schema.instanceOf({ export const UndefinedKeyword = Schema.instanceOf({ constructor: ast.UndefinedKeyword, annotations: { - id: "UndefinedKeyword", + identifier: "UndefinedKeyword", "~sentinels": [{ key: "_tag", literal: "UndefinedKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -67,7 +67,7 @@ export const UndefinedKeyword = Schema.instanceOf({ export const VoidKeyword = Schema.instanceOf({ constructor: ast.VoidKeyword, annotations: { - id: "VoidKeyword", + identifier: "VoidKeyword", "~sentinels": [{ key: "_tag", literal: "VoidKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -88,7 +88,7 @@ export const VoidKeyword = Schema.instanceOf({ export const NeverKeyword = Schema.instanceOf({ constructor: ast.NeverKeyword, annotations: { - id: "NeverKeyword", + identifier: "NeverKeyword", "~sentinels": [{ key: "_tag", literal: "NeverKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -109,7 +109,7 @@ export const NeverKeyword = Schema.instanceOf({ export const UnknownKeyword = Schema.instanceOf({ constructor: ast.UnknownKeyword, annotations: { - id: "UnknownKeyword", + identifier: "UnknownKeyword", "~sentinels": [{ key: "_tag", literal: "UnknownKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -130,7 +130,7 @@ export const UnknownKeyword = Schema.instanceOf({ export const AnyKeyword = Schema.instanceOf({ constructor: ast.AnyKeyword, annotations: { - id: "AnyKeyword", + identifier: "AnyKeyword", "~sentinels": [{ key: "_tag", literal: "AnyKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -151,7 +151,7 @@ export const AnyKeyword = Schema.instanceOf({ export const StringKeyword = Schema.instanceOf({ constructor: ast.StringKeyword, annotations: { - id: "StringKeyword", + identifier: "StringKeyword", "~sentinels": [{ key: "_tag", literal: "StringKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -172,7 +172,7 @@ export const StringKeyword = Schema.instanceOf({ export const NumberKeyword = Schema.instanceOf({ constructor: ast.NumberKeyword, annotations: { - id: "NumberKeyword", + identifier: "NumberKeyword", "~sentinels": [{ key: "_tag", literal: "NumberKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -193,7 +193,7 @@ export const NumberKeyword = Schema.instanceOf({ export const BooleanKeyword = Schema.instanceOf({ constructor: ast.BooleanKeyword, annotations: { - id: "BooleanKeyword", + identifier: "BooleanKeyword", "~sentinels": [{ key: "_tag", literal: "BooleanKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -214,7 +214,7 @@ export const BooleanKeyword = Schema.instanceOf({ export const BigIntKeyword = Schema.instanceOf({ constructor: ast.BigIntKeyword, annotations: { - id: "BigIntKeyword", + identifier: "BigIntKeyword", "~sentinels": [{ key: "_tag", literal: "BigIntKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -235,7 +235,7 @@ export const BigIntKeyword = Schema.instanceOf({ export const SymbolKeyword = Schema.instanceOf({ constructor: ast.SymbolKeyword, annotations: { - id: "SymbolKeyword", + identifier: "SymbolKeyword", "~sentinels": [{ key: "_tag", literal: "SymbolKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -256,7 +256,7 @@ export const SymbolKeyword = Schema.instanceOf({ export const LiteralType = Schema.instanceOf({ constructor: ast.LiteralType, annotations: { - id: "LiteralType", + identifier: "LiteralType", "~sentinels": [{ key: "_tag", literal: "LiteralType" }], defaultJsonSerializer: () => Schema.link()( @@ -278,7 +278,7 @@ export const LiteralType = Schema.instanceOf({ export const UniqueSymbol = Schema.instanceOf({ constructor: ast.UniqueSymbol, annotations: { - id: "UniqueSymbol", + identifier: "UniqueSymbol", "~sentinels": [{ key: "_tag", literal: "UniqueSymbol" }], defaultJsonSerializer: () => Schema.link()( @@ -300,7 +300,7 @@ export const UniqueSymbol = Schema.instanceOf({ export const ObjectKeyword = Schema.instanceOf({ constructor: ast.ObjectKeyword, annotations: { - id: "ObjectKeyword", + identifier: "ObjectKeyword", "~sentinels": [{ key: "_tag", literal: "ObjectKeyword" }], defaultJsonSerializer: () => Schema.link()( @@ -321,7 +321,7 @@ export const ObjectKeyword = Schema.instanceOf({ export const Enums = Schema.instanceOf({ constructor: ast.Enums, annotations: { - id: "Enums", + identifier: "Enums", "~sentinels": [{ key: "_tag", literal: "Enums" }], defaultJsonSerializer: () => Schema.link()( @@ -345,7 +345,7 @@ const SuspendedAST: Schema.Codec = Schema.suspend(() => AST) export const TemplateLiteral = Schema.instanceOf({ constructor: ast.TemplateLiteral, annotations: { - id: "TemplateLiteral", + identifier: "TemplateLiteral", "~sentinels": [{ key: "_tag", literal: "TemplateLiteral" }], defaultJsonSerializer: () => Schema.link()( @@ -369,7 +369,7 @@ export const TemplateLiteral = Schema.instanceOf({ export const TupleType = Schema.instanceOf({ constructor: ast.TupleType, annotations: { - id: "TupleType", + identifier: "TupleType", "~sentinels": [{ key: "_tag", literal: "TupleType" }], defaultJsonSerializer: () => Schema.link()( @@ -398,7 +398,7 @@ const PropertySignature = Schema.Struct({ export const TypeLiteral = Schema.instanceOf({ constructor: ast.TypeLiteral, annotations: { - id: "TypeLiteral", + identifier: "TypeLiteral", "~sentinels": [{ key: "_tag", literal: "TypeLiteral" }], defaultJsonSerializer: () => Schema.link()( @@ -424,7 +424,7 @@ export const TypeLiteral = Schema.instanceOf({ export const UnionType = Schema.instanceOf({ constructor: ast.UnionType, annotations: { - id: "UnionType", + identifier: "UnionType", "~sentinels": [{ key: "_tag", literal: "UnionType" }], defaultJsonSerializer: () => Schema.link()( @@ -447,7 +447,7 @@ export const UnionType = Schema.instanceOf({ export const Suspend = Schema.instanceOf({ constructor: ast.Suspend, annotations: { - id: "Suspend", + identifier: "Suspend", "~sentinels": [{ key: "_tag", literal: "Suspend" }] } }) @@ -477,7 +477,7 @@ export const AST = Schema.Union([ TypeLiteral, UnionType, Suspend -]).annotate({ id: "AST" }) +]).annotate({ identifier: "AST" }) /** * @since 4.0.0 diff --git a/packages/effect/src/schema/Schema.ts b/packages/effect/src/schema/Schema.ts index 40acef8e1a..abc33e85f5 100644 --- a/packages/effect/src/schema/Schema.ts +++ b/packages/effect/src/schema/Schema.ts @@ -3,25 +3,25 @@ */ import type { StandardSchemaV1 } from "@standard-schema/spec" -import * as Arr from "../Array.ts" import * as Request from "../batching/Request.ts" -import type { Brand } from "../Brand.ts" import * as Cause from "../Cause.ts" -import * as Data from "../Data.ts" +import * as Arr from "../collections/Array.ts" +import type { Brand } from "../data/Brand.ts" +import * as Data from "../data/Data.ts" +import * as Equivalence from "../data/Equivalence.ts" +import * as O from "../data/Option.ts" +import * as Predicate from "../data/Predicate.ts" +import * as R from "../data/Record.ts" +import * as Result from "../data/Result.ts" +import type { Lambda, Merge, Mutable, Simplify } from "../data/Struct.ts" +import { lambda, renameKeys } from "../data/Struct.ts" import * as Effect from "../Effect.ts" -import * as Equivalence from "../Equivalence.ts" import * as Exit from "../Exit.ts" import { identity } from "../Function.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" import * as core from "../internal/core.ts" -import * as O from "../Option.ts" -import type { Pipeable } from "../Pipeable.ts" -import { pipeArguments } from "../Pipeable.ts" -import * as Predicate from "../Predicate.ts" -import * as R from "../Record.ts" -import * as Result from "../Result.ts" -import * as Scheduler from "../Scheduler.ts" -import type { Lambda, Merge, Mutable, Simplify } from "../Struct.ts" -import { lambda, renameKeys } from "../Struct.ts" +import * as Scheduler from "../runtime/Scheduler.ts" import type * as Annotations from "./Annotations.ts" import * as AST from "./AST.ts" import * as Check from "./Check.ts" @@ -3577,7 +3577,7 @@ export interface Class { new(props: S["~type.make.in"], options?: MakeOptions): S["Type"] & Inherited - readonly id: string + readonly identifier: string readonly fields: S["fields"] } @@ -3591,7 +3591,7 @@ export interface ExtendableClass extend( - id: string + identifier: string ): ( fields: NewFields, annotations?: Annotations.Declaration>>]> @@ -3609,11 +3609,11 @@ function makeClass< Inherited extends new(...args: ReadonlyArray) => any >( Inherited: Inherited, - id: string, + identifier: string, schema: S, annotations?: Annotations.Declaration ): any { - const computeAST = getComputeAST(schema.ast, { id, ...annotations }) + const computeAST = getComputeAST(schema.ast, { identifier, ...annotations }) return class extends Inherited { constructor(...[input, options]: ReadonlyArray) { @@ -3645,7 +3645,7 @@ function makeClass< declare static readonly "~encoded.mutability": S["~encoded.mutability"] declare static readonly "~encoded.optionality": S["~encoded.optionality"] - static readonly id = id + static readonly identifier = identifier static readonly fields = schema.fields static get ast(): AST.Declaration { @@ -3677,7 +3677,7 @@ function makeClass< return this.rebuild(AST.appendChecks(this.ast, checks)) } static extend( - id: string + identifier: string ): ( fields: NewFields, annotations?: Annotations.Declaration>>]> @@ -3687,7 +3687,7 @@ function makeClass< const struct: any = new Struct$(AST.struct(fields, schema.ast.checks), fields) return makeClass( this, - id, + identifier, struct, annotations ) @@ -3737,7 +3737,7 @@ function getComputeAST( }, pretty: { _tag: "declaration", - declaration: ([from]) => (t) => `${self.id}(${from(t)})` + declaration: ([from]) => (t) => `${self.identifier}(${from(t)})` }, ...annotations } as Annotations.Declaration, @@ -3763,7 +3763,7 @@ function getComputeAST( * @since 4.0.0 */ export const Class: { - (id: string): { + (identifier: string): { ( fields: Fields, annotations?: Annotations.Declaration]> @@ -3773,7 +3773,7 @@ export const Class: { annotations?: Annotations.Declaration ): ExtendableClass } -} = (id: string) => +} = (identifier: string) => ( schema: Struct.Fields | Struct, annotations?: Annotations.Declaration]> @@ -3782,7 +3782,7 @@ export const Class: { return makeClass( Data.Class, - id, + identifier, struct, annotations ) @@ -3802,7 +3802,7 @@ export interface ErrorClass(id: string): { + (identifier: string): { ( fields: Fields, annotations?: Annotations.Declaration]> @@ -3812,7 +3812,7 @@ export const ErrorClass: { annotations?: Annotations.Declaration ): ErrorClass } -} = (id: string) => +} = (identifier: string) => ( schema: Struct.Fields | Struct, annotations?: Annotations.Declaration]> @@ -3821,7 +3821,7 @@ export const ErrorClass: { return makeClass( core.Error, - id, + identifier, struct, annotations ) @@ -3848,7 +3848,7 @@ export interface RequestClass< * @since 4.0.0 */ export const RequestClass = - (id: string) => + (identifier: string) => , Success extends Top, Error extends Top>( options: { readonly payload: Payload @@ -3869,7 +3869,7 @@ export const RequestClass = > => { return class RequestClass extends makeClass( Request.Class, - id, + identifier, options.payload, options.annotations ) { diff --git a/packages/effect/src/schema/Serializer.ts b/packages/effect/src/schema/Serializer.ts index 712d1f7ef3..0a818973f7 100644 --- a/packages/effect/src/schema/Serializer.ts +++ b/packages/effect/src/schema/Serializer.ts @@ -2,10 +2,10 @@ * @since 4.0.0 */ -import * as Arr from "../Array.ts" +import * as Arr from "../collections/Array.ts" +import * as Option from "../data/Option.ts" +import * as Predicate from "../data/Predicate.ts" import * as Effect from "../Effect.ts" -import * as Option from "../Option.ts" -import * as Predicate from "../Predicate.ts" import * as AST from "./AST.ts" import * as Getter from "./Getter.ts" import * as Issue from "./Issue.ts" diff --git a/packages/effect/src/schema/ToArbitrary.ts b/packages/effect/src/schema/ToArbitrary.ts index 905f3f27d1..04424b311c 100644 --- a/packages/effect/src/schema/ToArbitrary.ts +++ b/packages/effect/src/schema/ToArbitrary.ts @@ -1,11 +1,11 @@ /** * @since 4.0.0 */ -import * as Array from "../Array.ts" -import * as FastCheck from "../FastCheck.ts" +import * as Array from "../collections/Array.ts" +import * as Option from "../data/Option.ts" +import * as Predicate from "../data/Predicate.ts" import { defaultParseOptions, memoizeThunk } from "../internal/schema/util.ts" -import * as Option from "../Option.ts" -import * as Predicate from "../Predicate.ts" +import * as FastCheck from "../testing/FastCheck.ts" import * as AST from "./AST.ts" import type * as Check from "./Check.ts" import type * as Schema from "./Schema.ts" diff --git a/packages/effect/src/schema/ToEquivalence.ts b/packages/effect/src/schema/ToEquivalence.ts index d91c2812e3..264d991bc2 100644 --- a/packages/effect/src/schema/ToEquivalence.ts +++ b/packages/effect/src/schema/ToEquivalence.ts @@ -1,10 +1,10 @@ /** * @since 4.0.0 */ -import * as Equal from "../Equal.ts" -import * as Equivalence from "../Equivalence.ts" +import * as Equivalence from "../data/Equivalence.ts" +import * as Predicate from "../data/Predicate.ts" +import * as Equal from "../interfaces/Equal.ts" import { memoizeThunk } from "../internal/schema/util.ts" -import * as Predicate from "../Predicate.ts" import * as AST from "./AST.ts" import type * as Schema from "./Schema.ts" import * as ToParser from "./ToParser.ts" diff --git a/packages/effect/src/schema/ToJsonSchema.ts b/packages/effect/src/schema/ToJsonSchema.ts index 6062a12443..a407679a5b 100644 --- a/packages/effect/src/schema/ToJsonSchema.ts +++ b/packages/effect/src/schema/ToJsonSchema.ts @@ -1,9 +1,9 @@ /** * @since 4.0.0 */ +import * as Predicate from "../data/Predicate.ts" +import type * as Record from "../data/Record.ts" import { formatPath, hasOwn } from "../internal/schema/util.ts" -import * as Predicate from "../Predicate.ts" -import type * as Record from "../Record.ts" import type * as Annotations from "./Annotations.ts" import * as AST from "./AST.ts" import type * as Check from "./Check.ts" @@ -250,7 +250,7 @@ export function make(schema: S, options?: Options): JsonSc const target = options?.target ?? "draft-07" const additionalPropertiesStrategy = options?.additionalPropertiesStrategy ?? "strict" const topLevelReferenceStrategy = options?.topLevelReferenceStrategy ?? "keep" - const skipId = topLevelReferenceStrategy === "skip" + const skipIdentifier = topLevelReferenceStrategy === "skip" const out: JsonSchema.Root = { $schema: getTarget(target), ...go(AST.encodedAST(schema.ast), [], { @@ -258,7 +258,7 @@ export function make(schema: S, options?: Options): JsonSc getRef, target, additionalPropertiesStrategy - }, skipId) + }, skipIdentifier) } if (Object.keys($defs).length > 0) { out.$defs = $defs @@ -379,20 +379,20 @@ type GoOptions = { readonly additionalPropertiesStrategy: AdditionalPropertiesStrategy } -function getId(ast: AST.AST): string | undefined { +function getIdentifier(ast: AST.AST): string | undefined { if (ast.checks) { const last = ast.checks[ast.checks.length - 1] - const id = last.annotations?.id - if (Predicate.isString(id)) { - return id + const identifier = last.annotations?.identifier + if (Predicate.isString(identifier)) { + return identifier } } else { - const id = ast.annotations?.id - if (Predicate.isString(id)) { - return id + const identifier = ast.annotations?.identifier + if (Predicate.isString(identifier)) { + return identifier } if (AST.isSuspend(ast)) { - return getId(ast.thunk()) + return getIdentifier(ast.thunk()) } } } @@ -401,19 +401,19 @@ function go( ast: AST.AST, path: ReadonlyArray, options: GoOptions, - ignoreId: boolean = false, + ignoreIdentifier: boolean = false, ignoreJsonSchemaAnnotation: boolean = false ): JsonSchema.JsonSchema { - if (!ignoreId) { - const id = getId(ast) - if (id !== undefined) { - if (Object.hasOwn(options.$defs, id)) { - return options.$defs[id] + if (!ignoreIdentifier) { + const identifier = getIdentifier(ast) + if (identifier !== undefined) { + if (Object.hasOwn(options.$defs, identifier)) { + return options.$defs[identifier] } else { - const escapedId = id.replace(/~/ig, "~0").replace(/\//ig, "~1") + const escapedId = identifier.replace(/~/ig, "~0").replace(/\//ig, "~1") const out = { $ref: options.getRef(escapedId) } - options.$defs[id] = out - options.$defs[id] = go(ast, path, options, true) + options.$defs[identifier] = out + options.$defs[identifier] = go(ast, path, options, true) return out } } @@ -421,7 +421,7 @@ function go( if (!ignoreJsonSchemaAnnotation) { const annotation = getAnnotation(ast.annotations) if (annotation && annotation._tag === "override") { - return annotation.override(go(ast, path, options, ignoreId, true)) + return annotation.override(go(ast, path, options, ignoreIdentifier, true)) } } switch (ast._tag) { @@ -587,12 +587,14 @@ function go( } } case "Suspend": { - const id = getId(ast) - if (id !== undefined) { + const identifier = getIdentifier(ast) + if (identifier !== undefined) { return go(ast.thunk(), path, options, true) } throw new Error( - `cannot generate JSON Schema for ${ast._tag} at ${formatPath(path) || "root"}, required \`id\` annotation` + `cannot generate JSON Schema for ${ast._tag} at ${ + formatPath(path) || "root" + }, required \`identifier\` annotation` ) } } diff --git a/packages/effect/src/schema/ToParser.ts b/packages/effect/src/schema/ToParser.ts index e2aa80816c..a00b71e60d 100644 --- a/packages/effect/src/schema/ToParser.ts +++ b/packages/effect/src/schema/ToParser.ts @@ -2,11 +2,11 @@ * @since 4.0.0 */ -import * as Arr from "../Array.ts" +import * as Arr from "../collections/Array.ts" +import * as Option from "../data/Option.ts" +import * as Result from "../data/Result.ts" import * as Effect from "../Effect.ts" import { defaultParseOptions } from "../internal/schema/util.ts" -import * as Option from "../Option.ts" -import * as Result from "../Result.ts" import * as AST from "./AST.ts" import type * as Check from "./Check.ts" import * as Issue from "./Issue.ts" diff --git a/packages/effect/src/schema/ToPretty.ts b/packages/effect/src/schema/ToPretty.ts index 3de6540c35..c99dffccca 100644 --- a/packages/effect/src/schema/ToPretty.ts +++ b/packages/effect/src/schema/ToPretty.ts @@ -1,8 +1,8 @@ /** * @since 4.0.0 */ +import * as Option from "../data/Option.ts" import { formatPropertyKey, formatUnknown, memoizeThunk } from "../internal/schema/util.ts" -import * as Option from "../Option.ts" import * as AST from "./AST.ts" import type * as Schema from "./Schema.ts" import * as ToParser from "./ToParser.ts" diff --git a/packages/effect/src/schema/Transformation.ts b/packages/effect/src/schema/Transformation.ts index 2695145d3f..73372822e4 100644 --- a/packages/effect/src/schema/Transformation.ts +++ b/packages/effect/src/schema/Transformation.ts @@ -2,8 +2,8 @@ * @since 4.0.0 */ +import type * as Option from "../data/Option.ts" import type * as Effect from "../Effect.ts" -import type * as Option from "../Option.ts" import type * as AST from "./AST.ts" import * as Getter from "./Getter.ts" import type * as Issue from "./Issue.ts" diff --git a/packages/effect/src/schema/index.ts b/packages/effect/src/schema/index.ts index 98d9d40fa2..79d6174f05 100644 --- a/packages/effect/src/schema/index.ts +++ b/packages/effect/src/schema/index.ts @@ -1,5 +1,5 @@ /** - * @since 2.0.0 + * @since 4.0.0 */ /** diff --git a/packages/effect/src/schema/index.ts.tpl b/packages/effect/src/schema/index.ts.tpl index f84b39f7c3..c2aac82f76 100644 --- a/packages/effect/src/schema/index.ts.tpl +++ b/packages/effect/src/schema/index.ts.tpl @@ -1,3 +1,3 @@ /** - * @since 2.0.0 + * @since 4.0.0 */ diff --git a/packages/effect/src/Layer.ts b/packages/effect/src/services/Layer.ts similarity index 91% rename from packages/effect/src/Layer.ts rename to packages/effect/src/services/Layer.ts index fd2bbb273f..ff3e8a813a 100644 --- a/packages/effect/src/Layer.ts +++ b/packages/effect/src/services/Layer.ts @@ -17,20 +17,20 @@ * * @since 2.0.0 */ -import type { NonEmptyArray } from "./Array.ts" -import type * as Cause from "./Cause.ts" -import * as Deferred from "./Deferred.ts" -import type { Effect } from "./Effect.ts" -import type * as Exit from "./Exit.ts" -import type { LazyArg } from "./Function.ts" -import { constant, constTrue, dual, identity } from "./Function.ts" -import * as internalEffect from "./internal/effect.ts" -import type { ErrorWithStackTraceLimit } from "./internal/tracer.ts" -import { type Pipeable, pipeArguments } from "./Pipeable.ts" -import { hasProperty } from "./Predicate.ts" -import * as Scope from "./Scope.ts" -import * as ServiceMap from "./ServiceMap.ts" -import type * as Types from "./Types.ts" +import type * as Cause from "../Cause.ts" +import type { NonEmptyArray } from "../collections/Array.ts" +import * as Deferred from "../concurrency/Deferred.ts" +import { hasProperty } from "../data/Predicate.ts" +import type { Effect } from "../Effect.ts" +import type * as Exit from "../Exit.ts" +import type { LazyArg } from "../Function.ts" +import { constant, constTrue, dual, identity } from "../Function.ts" +import { type Pipeable, pipeArguments } from "../interfaces/Pipeable.ts" +import * as internalEffect from "../internal/effect.ts" +import type { ErrorWithStackTraceLimit } from "../internal/tracer.ts" +import * as Scope from "../resources/Scope.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import type * as Types from "../types/Types.ts" /** * The unique type identifier for Layer. @@ -141,7 +141,9 @@ export type MemoMapTypeId = "~effect/Layer/MemoMap" * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -174,7 +176,9 @@ export interface MemoMap { * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -220,7 +224,9 @@ const fromBuildUnsafe = ( * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -255,7 +261,9 @@ export const fromBuild = ( * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -332,7 +340,9 @@ class MemoMapImpl implements MemoMap { * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -358,7 +368,9 @@ export const unsafeMakeMemoMap = (): MemoMap => new MemoMapImpl() * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -387,7 +399,9 @@ export const makeMemoMap: Effect = internalEffect.sync(unsafeMakeMemoMa * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * const getMemoMap = ServiceMap.get(Layer.CurrentMemoMap) * ``` @@ -405,7 +419,9 @@ export const CurrentMemoMap = ServiceMap.Reference("effect/Layer/Curren * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -460,7 +476,9 @@ export const buildWithMemoMap: { * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -495,7 +513,10 @@ export const build = ( * * @example * ```ts - * import { Layer, ServiceMap, Effect, Scope } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { Scope } from "effect/resources" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -534,7 +555,9 @@ export const buildWithScope: { * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -584,7 +607,9 @@ export const succeed: { * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -610,7 +635,7 @@ export const succeedServices = (services: ServiceMap.ServiceMap): Layer * * @example * ```ts - * import { Layer } from "effect" + * import { Layer } from "effect/services" * * const emptyLayer = Layer.empty * ``` @@ -628,7 +653,9 @@ export const empty: Layer = succeedServices(ServiceMap.empty()) * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -657,7 +684,9 @@ export const sync: { * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -683,7 +712,9 @@ export const syncServices = (evaluate: LazyArg>): La * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -715,7 +746,9 @@ export const effect: { * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -741,7 +774,8 @@ export const effectServices = ( * * @example * ```ts - * import { Layer, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" * * const initLayer = Layer.effectDiscard( * Effect.sync(() => { @@ -765,7 +799,9 @@ export const effectDiscard = (effect: Effect): Layer Effect.Effect }>()("Database") {} * @@ -815,7 +851,9 @@ const mergeAllEffect = , ...Array Effect.Effect }>()("Database") {} * @@ -846,7 +884,9 @@ export const mergeAll = , ...Array Effect.Effect }>()("Database") {} * @@ -921,7 +961,9 @@ const provideWith = ( * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -1008,7 +1050,9 @@ export const provide: { * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Database extends ServiceMap.Key Effect.Effect }>()("Database") {} * @@ -1104,7 +1148,9 @@ export const provideMerge: { * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class Config extends ServiceMap.Key()("Config") {} * @@ -1182,7 +1228,10 @@ export const flatMap: { * * @example * ```ts - * import { Layer, ServiceMap, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { Data } from "effect/data" * * class DatabaseError extends Data.TaggedError("DatabaseError")<{ * message: string @@ -1256,7 +1305,10 @@ export { * * @example * ```ts - * import { Layer, ServiceMap, Effect, Data, Cause } from "effect" + * import { Effect, Cause } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { Data } from "effect/data" * * class DatabaseError extends Data.TaggedError("DatabaseError")<{ * message: string @@ -1326,7 +1378,10 @@ export const catchCause: { * * @example * ```ts - * import { Layer, ServiceMap, Effect, Ref } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { Ref } from "effect/concurrency" * * class Counter extends ServiceMap.Key Effect.Effect }>()("Counter") {} * @@ -1376,7 +1431,10 @@ export const fresh = (self: Layer): Layer => * * @example * ```ts - * import { Layer, ServiceMap, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" + * import { Console } from "effect/logging" * * class HttpServer extends ServiceMap.Key Effect.Effect @@ -1457,7 +1515,9 @@ export type PartialEffectful = Types.Simplify< * * @example * ```ts - * import { Layer, ServiceMap, Effect } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { ServiceMap } from "effect/services" * * class UserService extends ServiceMap.Key("effect/References/Tr * * @example * ```ts - * import { References, Effect } from "effect" + * import { Effect } from "effect" + * import { References } from "effect/services" * * const spanAnnotationExample = Effect.gen(function* () { * // Get current annotations (empty by default) @@ -222,7 +227,9 @@ export const TracerSpanAnnotations = ServiceMap.Reference>("ef * * @example * ```ts - * import { References, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { References } from "effect/services" + * import { Console } from "effect/logging" * * const logAnnotationExample = Effect.gen(function* () { * // Get current annotations (empty by default) @@ -344,7 +353,9 @@ export const CurrentLogAnnotations = ServiceMap.Reference> = * * @example * ```ts - * import { References, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { References } from "effect/services" + * import { Console } from "effect/logging" * * const logSpanExample = Effect.gen(function* () { * // Get current spans (empty by default) @@ -464,7 +477,9 @@ export const CurrentLogSpans = ServiceMap.Reference< * * @example * ```ts - * import { References, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { References } from "effect/services" + * import { Console } from "effect/logging" * * const configureMinimumLogging = Effect.gen(function* () { * // Get current minimum level (default is "Info") diff --git a/packages/effect/src/ServiceMap.ts b/packages/effect/src/services/ServiceMap.ts similarity index 91% rename from packages/effect/src/ServiceMap.ts rename to packages/effect/src/services/ServiceMap.ts index b037ee60a7..216ffabe3b 100644 --- a/packages/effect/src/ServiceMap.ts +++ b/packages/effect/src/services/ServiceMap.ts @@ -7,24 +7,24 @@ * * @since 4.0.0 */ -import type { EffectIterator, Yieldable } from "./Effect.ts" -import * as Equal from "./Equal.ts" -import { constant, dual, type LazyArg } from "./Function.ts" -import * as Hash from "./Hash.ts" -import type { Inspectable } from "./Inspectable.ts" -import { exitSucceed, PipeInspectableProto, withFiber, YieldableProto } from "./internal/core.ts" -import type { ErrorWithStackTraceLimit } from "./internal/tracer.ts" -import * as Option from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import { hasProperty } from "./Predicate.ts" -import type * as Types from "./Types.ts" +import * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" +import type { EffectIterator, Yieldable } from "../Effect.ts" +import { constant, dual, type LazyArg } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { exitSucceed, PipeInspectableProto, withFiber, YieldableProto } from "../internal/core.ts" +import type { ErrorWithStackTraceLimit } from "../internal/tracer.ts" +import type * as Types from "../types/Types.ts" /** * @since 4.0.0 * @category Symbols * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * console.log(ServiceMap.KeyTypeId) * // Output: "~effect/ServiceMap/Key" @@ -37,7 +37,7 @@ export const KeyTypeId: KeyTypeId = "~effect/ServiceMap/Key" * @category Symbols * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // KeyTypeId is a type representing the unique identifier for ServiceMap keys * type MyKeyTypeId = ServiceMap.KeyTypeId @@ -50,7 +50,7 @@ export type KeyTypeId = "~effect/ServiceMap/Key" * @category Models * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // Define a key for a database service * const DatabaseKey = ServiceMap.Key<{ query: (sql: string) => string }>("Database") @@ -80,7 +80,7 @@ export interface Key * @category Models * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // Define a key class for a logger service * class LoggerKey extends ServiceMap.Key void }>()("Logger") {} @@ -103,7 +103,7 @@ export interface KeyClass * @category Constructors * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // Create a simple key * const DatabaseKey = ServiceMap.Key<{ query: (sql: string) => string }>("Database") @@ -181,7 +181,7 @@ const KeyProto: any = { * @category Symbols * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * console.log(ServiceMap.ReferenceTypeId) * // Output: "~effect/ServiceMap/Reference" @@ -194,7 +194,7 @@ export const ReferenceTypeId: ReferenceTypeId = "~effect/ServiceMap/Reference" * @category Symbols * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // ReferenceTypeId is a type representing the unique identifier for ServiceMap references * type MyReferenceTypeId = ServiceMap.ReferenceTypeId @@ -207,7 +207,7 @@ export type ReferenceTypeId = "~effect/ServiceMap/Reference" * @category Models * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // Define a reference with a default value * const LoggerRef: ServiceMap.Reference<{ log: (msg: string) => void }> = @@ -229,7 +229,7 @@ export interface Reference extends Key { * @category Models * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // Extract service type from a key * type DatabaseService = ServiceMap.Key.Service @@ -246,7 +246,7 @@ export declare namespace Key { * @category Models * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // Variance interface is used internally for type inference * type MyVariance = ServiceMap.Key.Variance<"MyId", { value: number }> @@ -263,7 +263,7 @@ export declare namespace Key { * @category Models * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // Any represents any possible key type * const keys: ServiceMap.Key.Any[] = [ @@ -278,7 +278,7 @@ export declare namespace Key { * @category Models * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * const DatabaseKey = ServiceMap.Key<{ query: (sql: string) => string }>("Database") * @@ -293,7 +293,7 @@ export declare namespace Key { * @category Models * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * const DatabaseKey = ServiceMap.Key<{ query: (sql: string) => string }>("Database") * @@ -310,7 +310,7 @@ export declare namespace Key { * @category Symbols * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * console.log(ServiceMap.TypeId) * // Output: "~effect/ServiceMap" @@ -323,7 +323,7 @@ export const TypeId: TypeId = "~effect/ServiceMap" * @category Symbols * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // TypeId is a type representing the unique identifier for ServiceMap * type MyTypeId = ServiceMap.TypeId @@ -336,7 +336,7 @@ export type TypeId = "~effect/ServiceMap" * @category Models * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // Create a service map with multiple services * const Logger = ServiceMap.Key<{ log: (msg: string) => void }>("Logger") @@ -358,7 +358,7 @@ export interface ServiceMap extends Equal.Equal, Pipeable, Inspecta * @category Constructors * @example * ```ts - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // Create a service map from a Map (unsafe) * const map = new Map([[ @@ -414,7 +414,7 @@ const Proto: Omit, "unsafeMap"> = { * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * assert.strictEqual(ServiceMap.isServiceMap(ServiceMap.empty()), true) * ``` @@ -432,7 +432,7 @@ export const isServiceMap = (u: unknown): u is ServiceMap => hasProperty( * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * assert.strictEqual(ServiceMap.isKey(ServiceMap.Key("Key")), true) * ``` @@ -448,7 +448,7 @@ export const isKey = (u: unknown): u is Key => hasProperty(u, KeyTypeI * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * const LoggerRef = ServiceMap.Reference("Logger", { defaultValue: () => ({ log: (msg: string) => console.log(msg) }) }) * @@ -467,7 +467,7 @@ export const isReference = (u: unknown): u is Reference => hasProperty(u, R * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * assert.strictEqual(ServiceMap.isServiceMap(ServiceMap.empty()), true) * ``` @@ -484,7 +484,7 @@ const emptyServiceMap = unsafeMake(new Map()) * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * const Port = ServiceMap.Key<{ PORT: number }>("Port") * @@ -507,7 +507,8 @@ export const make = ( * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap, pipe } from "effect" + * import { pipe } from "effect" + * import { ServiceMap } from "effect/services" * * const Port = ServiceMap.Key<{ PORT: number }>("Port") * const Timeout = ServiceMap.Key<{ TIMEOUT: number }>("Timeout") @@ -553,7 +554,7 @@ export const add: { * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * const Logger = ServiceMap.Key<{ log: (msg: string) => void }>("Logger") * const Database = ServiceMap.Key<{ query: (sql: string) => string }>("Database") @@ -592,7 +593,7 @@ export const getOrElse: { * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * const Port = ServiceMap.Key<{ PORT: number }>("Port") * const Timeout = ServiceMap.Key<{ TIMEOUT: number }>("Timeout") @@ -624,7 +625,7 @@ export const unsafeGet: { * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * const LoggerRef = ServiceMap.Reference("Logger", { * defaultValue: () => ({ log: (msg: string) => console.log(msg) }) @@ -684,7 +685,8 @@ const serviceNotFoundError = (key: Key) => { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, ServiceMap } from "effect" + * import { pipe } from "effect" + * import { ServiceMap } from "effect/services" * * const Port = ServiceMap.Key<{ PORT: number }>("Port") * const Timeout = ServiceMap.Key<{ TIMEOUT: number }>("Timeout") @@ -715,7 +717,8 @@ export const get: { * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap, Option } from "effect" + * import { ServiceMap } from "effect/services" + * import { Option } from "effect/data" * * const Port = ServiceMap.Key<{ PORT: number }>("Port") * const Timeout = ServiceMap.Key<{ TIMEOUT: number }>("Timeout") @@ -748,7 +751,7 @@ export const getOption: { * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * const Port = ServiceMap.Key<{ PORT: number }>("Port") * const Timeout = ServiceMap.Key<{ TIMEOUT: number }>("Timeout") @@ -787,7 +790,9 @@ export const merge: { * @example * ```ts * import * as assert from "node:assert" - * import { pipe, ServiceMap, Option } from "effect" + * import { pipe } from "effect" + * import { ServiceMap } from "effect/services" + * import { Option } from "effect/data" * * const Port = ServiceMap.Key<{ PORT: number }>("Port") * const Timeout = ServiceMap.Key<{ TIMEOUT: number }>("Timeout") @@ -824,7 +829,9 @@ export const pick = >>( * @example * ```ts * import * as assert from "node:assert" - * import { pipe, ServiceMap, Option } from "effect" + * import { pipe } from "effect" + * import { ServiceMap } from "effect/services" + * import { Option } from "effect/data" * * const Port = ServiceMap.Key<{ PORT: number }>("Port") * const Timeout = ServiceMap.Key<{ TIMEOUT: number }>("Timeout") @@ -867,7 +874,7 @@ export const omit = >>( * @example * ```ts * import * as assert from "node:assert" - * import { ServiceMap } from "effect" + * import { ServiceMap } from "effect/services" * * // Create a reference with a default value * const LoggerRef = ServiceMap.Reference("Logger", { diff --git a/packages/effect/src/services/index.ts b/packages/effect/src/services/index.ts new file mode 100644 index 0000000000..6c777b19d9 --- /dev/null +++ b/packages/effect/src/services/index.ts @@ -0,0 +1,49 @@ +/** + * @since 4.0.0 + */ + +/** + * A `Layer` describes how to build one or more services in your + * application. Services can be injected into effects via + * `Effect.provideService`. Effects can require services via `Effect.service`. + * + * Layer can be thought of as recipes for producing bundles of services, given + * their dependencies (other services). + * + * Construction of services can be effectful and utilize resources that must be + * acquired and safely released when the services are done being utilized. + * + * By default layers are shared, meaning that if the same layer is used twice + * the layer will only be allocated a single time. + * + * Because of their excellent composition properties, layers are the idiomatic + * way in Effect-TS to create services that depend on other services. + * + * @since 2.0.0 + */ +export * as Layer from "./Layer.ts" + +/** + * This module provides a collection of reference implementations for commonly used + * Effect runtime configuration values. These references allow you to access and + * modify runtime behavior such as concurrency limits, scheduling policies, + * tracing configuration, and logging settings. + * + * References are special service instances that can be dynamically updated + * during runtime, making them ideal for configuration that may need to change + * based on application state or external conditions. + * + * @since 4.0.0 + */ +export * as References from "./References.ts" + +/** + * This module provides a data structure called `ServiceMap` that can be used for dependency injection in effectful + * programs. It is essentially a table mapping `Keys`s to their implementations (called `Service`s), and can be used to + * manage dependencies in a type-safe way. The `ServiceMap` data structure is essentially a way of providing access to a set + * of related services that can be passed around as a single unit. This module provides functions to create, modify, and + * query the contents of a `ServiceMap`, as well as a number of utility types for working with keys and services. + * + * @since 4.0.0 + */ +export * as ServiceMap from "./ServiceMap.ts" diff --git a/packages/effect/src/services/index.ts.tpl b/packages/effect/src/services/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/services/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/Channel.ts b/packages/effect/src/stream/Channel.ts similarity index 92% rename from packages/effect/src/Channel.ts rename to packages/effect/src/stream/Channel.ts index 274da7ba21..8a6e6f39dd 100644 --- a/packages/effect/src/Channel.ts +++ b/packages/effect/src/stream/Channel.ts @@ -30,7 +30,8 @@ * * @example * ```ts - * import { Channel, Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Effect } from "effect" * * // Simple channel that outputs numbers * const numberChannel = Channel.succeed(42) @@ -43,7 +44,8 @@ * * @example * ```ts - * import { Channel, Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Effect } from "effect" * * // Channel from an array of values * const arrayChannel = Channel.fromArray([1, 2, 3, 4, 5]) @@ -56,33 +58,33 @@ * * @since 2.0.0 */ -import type * as Arr from "./Array.ts" -import * as Cause from "./Cause.ts" -import * as Chunk from "./Chunk.ts" -import * as Effect from "./Effect.ts" -import * as Exit from "./Exit.ts" -import * as Fiber from "./Fiber.ts" -import * as Filter from "./Filter.ts" -import type { LazyArg } from "./Function.ts" -import { constTrue, dual, identity } from "./Function.ts" -import * as Iterable from "./Iterable.ts" -import * as Option from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" -import { hasProperty } from "./Predicate.ts" -import * as PubSub from "./PubSub.ts" -import * as Pull from "./Pull.ts" -import * as Queue from "./Queue.ts" -import * as Schedule from "./Schedule.ts" -import * as Scope from "./Scope.ts" -import * as ServiceMap from "./ServiceMap.ts" -import type * as Types from "./Types.ts" -import type * as Unify from "./Unify.ts" +import * as Cause from "../Cause.ts" +import type * as Arr from "../collections/Array.ts" +import * as Chunk from "../collections/Chunk.ts" +import * as Iterable from "../collections/Iterable.ts" +import * as PubSub from "../concurrency/PubSub.ts" +import * as Queue from "../concurrency/Queue.ts" +import * as Filter from "../data/Filter.ts" +import * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Effect from "../Effect.ts" +import * as Exit from "../Exit.ts" +import type { LazyArg } from "../Function.ts" +import { constTrue, dual, identity } from "../Function.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import * as Scope from "../resources/Scope.ts" +import * as Fiber from "../runtime/Fiber.ts" +import * as Schedule from "../scheduling/Schedule.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import * as Pull from "../stream/Pull.ts" +import type * as Types from "../types/Types.ts" +import type * as Unify from "../types/Unify.ts" /** * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * console.log(Channel.TypeId) // "~effect/Channel" * ``` @@ -95,7 +97,7 @@ export const TypeId: TypeId = "~effect/Channel" /** * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * // TypeId is used for type identification * type MyTypeId = Channel.TypeId // "~effect/Channel" @@ -111,7 +113,7 @@ export type TypeId = "~effect/Channel" * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * const channel = Channel.succeed(42) * console.log(Channel.isChannel(channel)) // true @@ -150,7 +152,7 @@ export const isChannel = ( * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * // A channel that outputs numbers and requires no environment * type NumberChannel = Channel.Channel @@ -190,7 +192,8 @@ export interface Channel< /** * @example * ```ts - * import { Channel, Unify } from "effect" + * import { Channel } from "effect/stream" + * import * as Unify from "effect/types/Unify" * * // ChannelUnify helps with type inference when using generic operations * // This is typically used internally by the Effect system @@ -213,7 +216,7 @@ export interface ChannelUnify extends Ef /** * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * // ChannelUnifyIgnore is used to control type unification behavior * // This is typically used internally by the Effect system @@ -230,7 +233,7 @@ export interface ChannelUnifyIgnore extends Effect.EffectUnifyIgnore { /** * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * // Variance interface defines the variance annotations for Channel types * // This ensures proper type safety for contravariant and covariant positions @@ -254,7 +257,7 @@ export interface Variance< /** * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * // VarianceStruct contains the actual variance markers for type checking * // This is used internally to ensure proper subtyping relationships @@ -305,7 +308,8 @@ const ChannelProto = { * * @example * ```ts - * import { Channel, Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Effect } from "effect" * * const channel = Channel.fromTransform((upstream, scope) => * Effect.succeed(upstream) @@ -339,7 +343,8 @@ export const fromTransform = ( * * @example * ```ts - * import { Channel, Queue } from "effect" + * import { Channel } from "effect/stream" + * import { Queue } from "effect/concurrency" * * const channel = Channel.callback((queue) => { * Queue.offer(queue, 1) @@ -463,7 +469,8 @@ export const callback = ( * * @example * ```ts - * import { Channel, Queue } from "effect" + * import { Channel } from "effect/stream" + * import { Queue } from "effect/concurrency" * * const channel = Channel.callbackArray((queue) => { * Queue.offer(queue, 1) @@ -489,7 +496,7 @@ export const callbackArray = ( * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * const channel = Channel.suspend(() => Channel.succeed(42)) * // The inner channel is not created until the suspended channel is run @@ -508,7 +515,8 @@ export const suspend = ( * * @example * ```ts - * import { Channel, Effect, Exit } from "effect" + * import { Effect, Exit } from "effect" + * import { Channel } from "effect/stream" * * const channel = Channel.acquireUseRelease( * Effect.succeed("resource"), @@ -543,7 +551,8 @@ export const acquireUseRelease = numbers[Symbol.iterator]()) @@ -602,7 +611,7 @@ export const fromIterator = (iterator: LazyArg>): Channel(array: ReadonlyArray): Channel => * * @example * ```ts - * import { Channel, Chunk } from "effect" + * import { Channel } from "effect/stream" + * import { Chunk } from "effect/collections" * * const chunk = Chunk.make(1, 2, 3) * const channel = Channel.fromChunk(chunk) @@ -639,7 +649,8 @@ export const fromChunk = (chunk: Chunk.Chunk): Channel => fromArray(Chu * * @example * ```ts - * import { Channel, Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Effect } from "effect" * * // Create a channel from a simple iterator * const numberIterator = (): Iterator => { @@ -660,7 +671,7 @@ export const fromChunk = (chunk: Chunk.Chunk): Channel => fromArray(Chu * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * // Create channel from a generator function * function* fibonacci(): Generator { @@ -710,7 +721,7 @@ export const fromIteratorArray = ( * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * const set = new Set([1, 2, 3]) * const channel = Channel.fromIterable(set) @@ -728,7 +739,7 @@ export const fromIterable = (iterable: Iterable): Channel( * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * const channel = Channel.succeed(42) * // Emits: 42 @@ -763,7 +774,7 @@ export const succeed = (value: A): Channel => fromEffect(Effect.succeed(va * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * const channel = Channel.end("done") * // Ends immediately with "done", emits nothing @@ -779,7 +790,7 @@ export const end = (value: A): Channel => fromPull(Effect.su * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * const channel = Channel.sync(() => Math.random()) * // Emits a random number computed when the channel runs @@ -795,7 +806,7 @@ export const sync = (evaluate: LazyArg): Channel => fromEffect(Effect.s * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * // Create an empty channel * const emptyChannel = Channel.empty @@ -819,7 +830,8 @@ export const empty: Channel = fromPull(Effect.succeed(Pull.haltVoid)) * * @example * ```ts - * import { Channel, Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Effect } from "effect" * * // Create a channel that never completes * const neverChannel = Channel.never @@ -845,7 +857,8 @@ export const never: Channel = fromPull(Effect.succeed(Effec * * @example * ```ts - * import { Channel, Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Effect } from "effect" * * // Create a channel that fails with a string error * const failedChannel = Channel.fail("Something went wrong") @@ -877,7 +890,7 @@ export const fail = (error: E): Channel => fromPull(Effect.f * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * // Create a channel that fails with a lazily computed error * const failedChannel = Channel.failSync(() => { @@ -907,7 +920,8 @@ export const failSync = (evaluate: LazyArg): Channel => f * * @example * ```ts - * import { Channel, Cause } from "effect" + * import { Cause } from "effect" + * import { Channel } from "effect/stream" * * // Create a channel that fails with a simple cause * const simpleCause = Cause.fail("Simple error") @@ -933,7 +947,8 @@ export const failCause = (cause: Cause.Cause): Channel => * * @example * ```ts - * import { Channel, Cause } from "effect" + * import { Cause } from "effect" + * import { Channel } from "effect/stream" * * // Create a channel that fails with a lazily computed cause * const failedChannel = Channel.failCauseSync(() => { @@ -960,7 +975,7 @@ export const failCauseSync = ( * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * // Create a channel that dies with a string defect * const diedChannel = Channel.die("Unrecoverable error") @@ -985,7 +1000,9 @@ export const die = (defect: unknown): Channel => failCause( * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class DatabaseError extends Data.TaggedError("DatabaseError")<{ * readonly message: string @@ -1035,7 +1052,10 @@ export const fromEffect = ( * * @example * ```ts - * import { Channel, Queue, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { Queue } from "effect/concurrency" * * class QueueError extends Data.TaggedError("QueueError")<{ * readonly reason: string @@ -1077,7 +1097,10 @@ export const fromQueue = ( * * @example * ```ts - * import { Channel, Queue, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { Queue } from "effect/concurrency" * * class ProcessingError extends Data.TaggedError("ProcessingError")<{ * readonly stage: string @@ -1122,7 +1145,10 @@ export const fromQueueArray = ( * * @example * ```ts - * import { Channel, PubSub, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { PubSub } from "effect/concurrency" * * class SubscriptionError extends Data.TaggedError("SubscriptionError")<{ * readonly reason: string @@ -1176,7 +1202,10 @@ export const fromSubscription = ( * * @example * ```ts - * import { Channel, PubSub, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { PubSub } from "effect/concurrency" * * class StreamError extends Data.TaggedError("StreamError")<{ * readonly message: string @@ -1202,7 +1231,10 @@ export const fromSubscription = ( * * @example * ```ts - * import { Channel, PubSub, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { PubSub } from "effect/concurrency" * * class BatchProcessingError extends Data.TaggedError("BatchProcessingError")<{ * readonly reason: string @@ -1227,7 +1259,10 @@ export const fromSubscription = ( * * @example * ```ts - * import { Channel, PubSub, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { PubSub } from "effect/concurrency" * * class MetricsError extends Data.TaggedError("MetricsError")<{ * readonly cause: string @@ -1285,7 +1320,10 @@ export const fromSubscriptionArray = ( * * @example * ```ts - * import { Channel, PubSub, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { PubSub } from "effect/concurrency" * * class StreamError extends Data.TaggedError("StreamError")<{ * readonly message: string @@ -1309,7 +1347,10 @@ export const fromSubscriptionArray = ( * * @example * ```ts - * import { Channel, PubSub, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { PubSub } from "effect/concurrency" * * class NotificationError extends Data.TaggedError("NotificationError")<{ * readonly reason: string @@ -1334,7 +1375,10 @@ export const fromSubscriptionArray = ( * * @example * ```ts - * import { Channel, PubSub, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { PubSub } from "effect/concurrency" * * class EventProcessingError extends Data.TaggedError("EventProcessingError")<{ * readonly eventType: string @@ -1388,7 +1432,10 @@ export const fromPubSub = ( * * @example * ```ts - * import { Channel, PubSub, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { PubSub } from "effect/concurrency" * * class BatchError extends Data.TaggedError("BatchError")<{ * readonly message: string @@ -1413,7 +1460,10 @@ export const fromPubSub = ( * * @example * ```ts - * import { Channel, PubSub, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { PubSub } from "effect/concurrency" * * class OrderProcessingError extends Data.TaggedError("OrderProcessingError")<{ * readonly orderId: string @@ -1453,7 +1503,10 @@ export const fromPubSub = ( * * @example * ```ts - * import { Channel, PubSub, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { PubSub } from "effect/concurrency" * * class LogProcessingError extends Data.TaggedError("LogProcessingError")<{ * readonly batchId: string @@ -1524,7 +1577,9 @@ export const fromSchedule = ( * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class TransformError extends Data.TaggedError("TransformError")<{ * readonly reason: string @@ -1589,7 +1644,9 @@ const concurrencyIsSequential = ( * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class NetworkError extends Data.TaggedError("NetworkError")<{ * readonly url: string @@ -1769,7 +1826,10 @@ const mapEffectConcurrent = < * * @example * ```ts - * import { Channel, Effect, Console, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Console } from "effect/logging" + * import { Data } from "effect/data" * * class LogError extends Data.TaggedError("LogError")<{ * readonly message: string @@ -1827,7 +1887,9 @@ export const tap: { * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class ProcessError extends Data.TaggedError("ProcessError")<{ * readonly cause: string @@ -2019,7 +2081,9 @@ const flatMapConcurrent = < * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class ConcatError extends Data.TaggedError("ConcatError")<{ * readonly reason: string @@ -2135,7 +2199,9 @@ export const concatWith: { * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class ConcatError extends Data.TaggedError("ConcatError")<{ * readonly reason: string @@ -2228,7 +2294,9 @@ export const concat: { * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class FlattenError extends Data.TaggedError("FlattenError")<{ * readonly cause: string @@ -2282,7 +2350,9 @@ export const flatten = < * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class FlattenError extends Data.TaggedError("FlattenError")<{ * readonly message: string @@ -2339,7 +2409,9 @@ export const flattenArray = < * * @example * ```ts - * import { Channel, Effect, Cause, Data } from "effect" + * import { Effect, Cause } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class ProcessError extends Data.TaggedError("ProcessError")<{ * readonly reason: string @@ -2664,7 +2736,9 @@ export const mapError: { * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class ValidationError extends Data.TaggedError("ValidationError")<{ * readonly field: string @@ -2703,7 +2777,9 @@ export const orDie = < * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class SwitchError extends Data.TaggedError("SwitchError")<{ * readonly reason: string @@ -2820,7 +2896,9 @@ export const switchMap: { * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class MergeAllError extends Data.TaggedError("MergeAllError")<{ * readonly reason: string @@ -2986,7 +3064,7 @@ export const mergeAll: { * * @example * ```ts - * import { Channel } from "effect" + * import { Channel } from "effect/stream" * * // Different halt strategies for channel merging * const leftFirst: Channel.HaltStrategy = "left" // Stop when left channel halts @@ -3006,7 +3084,9 @@ export type HaltStrategy = "left" | "right" | "both" | "either" * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class MergeError extends Data.TaggedError("MergeError")<{ * readonly source: string @@ -3172,7 +3252,9 @@ export const merge: { * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class PipeError extends Data.TaggedError("PipeError")<{ * readonly stage: string @@ -3219,7 +3301,9 @@ export const pipeTo: { * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class SourceError extends Data.TaggedError("SourceError")<{ * readonly code: number @@ -3280,7 +3364,10 @@ export const pipeToOrFail: { * * @example * ```ts - * import { Channel, Effect, Scope, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { Scope } from "effect/resources" * * class UnwrapError extends Data.TaggedError("UnwrapError")<{ * readonly reason: string @@ -3315,7 +3402,9 @@ export const unwrap = ( * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class DrainError extends Data.TaggedError("DrainError")<{ * readonly stage: string @@ -3555,7 +3654,10 @@ export const runDrain = ( * * @example * ```ts - * import { Channel, Effect, Console, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Console } from "effect/logging" + * import { Data } from "effect/data" * * class ForEachError extends Data.TaggedError("ForEachError")<{ * readonly element: unknown @@ -3599,7 +3701,9 @@ export const runForEach: { * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class CollectError extends Data.TaggedError("CollectError")<{ * readonly reason: string @@ -3630,7 +3734,9 @@ export const runCollect = ( * * @example * ```ts - * import { Channel, Effect, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" * * class FoldError extends Data.TaggedError("FoldError")<{ * readonly operation: string @@ -3686,7 +3792,10 @@ export const runFold: { * * @example * ```ts - * import { Channel, Effect, Scope, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { Scope } from "effect/resources" * * class PullError extends Data.TaggedError("PullError")<{ * readonly step: string @@ -3734,7 +3843,10 @@ export const toPull: ( * * @example * ```ts - * import { Channel, Effect, Scope, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { Scope } from "effect/resources" * * class ScopedPullError extends Data.TaggedError("ScopedPullError")<{ * readonly reason: string @@ -3764,7 +3876,10 @@ export const toPullScoped = ( * * @example * ```ts - * import { Channel, Effect, Queue, Data } from "effect" + * import { Effect } from "effect" + * import { Channel } from "effect/stream" + * import { Data } from "effect/data" + * import { Queue } from "effect/concurrency" * * class QueueError extends Data.TaggedError("QueueError")<{ * readonly operation: string diff --git a/packages/effect/src/Pull.ts b/packages/effect/src/stream/Pull.ts similarity index 87% rename from packages/effect/src/Pull.ts rename to packages/effect/src/stream/Pull.ts index 81c8897bd3..9ff663b560 100644 --- a/packages/effect/src/Pull.ts +++ b/packages/effect/src/stream/Pull.ts @@ -1,13 +1,13 @@ /** * @since 4.0.0 */ -import * as Cause from "./Cause.ts" -import type { Effect } from "./Effect.ts" -import * as Exit from "./Exit.ts" -import * as Filter from "./Filter.ts" -import { dual } from "./Function.ts" -import * as internalEffect from "./internal/effect.ts" -import { hasProperty } from "./Predicate.ts" +import * as Cause from "../Cause.ts" +import * as Filter from "../data/Filter.ts" +import { hasProperty } from "../data/Predicate.ts" +import type { Effect } from "../Effect.ts" +import * as Exit from "../Exit.ts" +import { dual } from "../Function.ts" +import * as internalEffect from "../internal/effect.ts" /** * A Pull is a specialized Effect that represents a pull-based stream operation. @@ -16,7 +16,8 @@ import { hasProperty } from "./Predicate.ts" * * @example * ```ts - * import { Pull, Effect } from "effect" + * import { Pull } from "effect/stream" + * import { Effect } from "effect" * * // A Pull that emits a single value * const pullValue: Pull.Pull = Effect.succeed(42) @@ -38,7 +39,8 @@ export interface Pull exte * * @example * ```ts - * import { Pull, Effect } from "effect" + * import { Pull } from "effect/stream" + * import { Effect } from "effect" * * type MyPull = Pull.Pull * type SuccessType = Pull.Success // number @@ -54,7 +56,8 @@ export type Success

= P extends Effect ? _A : n * * @example * ```ts - * import { Pull, Effect } from "effect" + * import { Pull } from "effect/stream" + * import { Effect } from "effect" * * type MyPull = Pull.Pull * type ErrorType = Pull.Error // string @@ -71,7 +74,8 @@ export type Error

= P extends Effect ? _E exten * * @example * ```ts - * import { Pull, Effect } from "effect" + * import { Pull } from "effect/stream" + * import { Effect } from "effect" * * type MyPull = Pull.Pull * type LeftoverType = Pull.Leftover // number @@ -88,7 +92,9 @@ export type Leftover

= P extends Effect ? _E ex * * @example * ```ts - * import { Pull, Effect, ServiceMap } from "effect" + * import { Pull } from "effect/stream" + * import { Effect } from "effect" + * import { ServiceMap } from "effect/services" * * interface MyService { * readonly value: number @@ -109,7 +115,7 @@ export type ServiceMap

= P extends Effect ? _R * * @example * ```ts - * import { Pull } from "effect" + * import { Pull } from "effect/stream" * * type ErrorUnion = string | Pull.Halt | Error * type WithoutHalt = Pull.ExcludeHalt // string | Error @@ -129,7 +135,7 @@ export type ExcludeHalt = Exclude> * * @example * ```ts - * import { Pull } from "effect" + * import { Pull } from "effect/stream" * * console.log(Pull.HaltTypeId) // "~effect/Pull/Halt" * ``` @@ -144,7 +150,7 @@ export const HaltTypeId: HaltTypeId = "~effect/Pull/Halt" * * @example * ```ts - * import { Pull } from "effect" + * import { Pull } from "effect/stream" * * type Id = Pull.HaltTypeId // "~effect/Pull/Halt" * ``` @@ -179,7 +185,7 @@ export class Halt { * * @example * ```ts - * import { Pull } from "effect" + * import { Pull } from "effect/stream" * * // Extract leftover type from halt * type MyHalt = Pull.Halt @@ -199,7 +205,7 @@ export declare namespace Halt { * * @example * ```ts - * import { Pull } from "effect" + * import { Pull } from "effect/stream" * * type MyHalt = Pull.Halt * type Leftover = Pull.Halt.Extract // string @@ -215,7 +221,7 @@ export declare namespace Halt { * * @example * ```ts - * import { Pull } from "effect" + * import { Pull } from "effect/stream" * * type ErrorUnion = string | Pull.Halt * type OnlyHalt = Pull.Halt.Only // Pull.Halt @@ -232,7 +238,8 @@ export declare namespace Halt { * * @example * ```ts - * import { Pull, Effect } from "effect" + * import { Pull } from "effect/stream" + * import { Effect } from "effect" * * const pullWithHalt = Pull.halt("stream ended") * const recovered = Pull.catchHalt(pullWithHalt, (leftover) => @@ -262,7 +269,7 @@ export const catchHalt: { * * @example * ```ts - * import { Pull } from "effect" + * import { Pull } from "effect/stream" * * const halt = new Pull.Halt("completed") * const regularError = new Error("failed") @@ -281,7 +288,8 @@ export const isHalt = (u: unknown): u is Halt => hasProperty(u, HaltTyp * * @example * ```ts - * import { Pull, Cause } from "effect" + * import { Pull } from "effect/stream" + * import { Cause } from "effect" * * const halt = new Pull.Halt("completed") * const causeWithHalt = Cause.fail(halt) @@ -301,7 +309,8 @@ export const isHaltCause = (cause: Cause.Cause): boolean => cause.failures * * @example * ```ts - * import { Pull, Cause } from "effect" + * import { Pull } from "effect/stream" + * import { Cause } from "effect" * * const halt = new Pull.Halt("completed") * const haltCause = Cause.fail(halt) @@ -347,7 +356,8 @@ export const filterNoHalt: ( * * @example * ```ts - * import { Pull, Cause } from "effect" + * import { Pull } from "effect/stream" + * import { Cause } from "effect" * * const halt = new Pull.Halt("stream completed") * const causeWithHalt = Cause.fail(halt) @@ -371,7 +381,8 @@ export const filterHaltLeftover: ( * * @example * ```ts - * import { Pull, Effect } from "effect" + * import { Pull } from "effect/stream" + * import { Effect } from "effect" * * // Create a halt with a string leftover * const haltWithMessage = Pull.halt("operation completed") @@ -390,7 +401,8 @@ export const halt = (leftover: L): Effect> => internalEffect.f * * @example * ```ts - * import { Pull, Effect } from "effect" + * import { Pull } from "effect/stream" + * import { Effect } from "effect" * * // Use the pre-defined halt with void * const completePull = Pull.haltVoid @@ -409,7 +421,8 @@ export const haltVoid: Effect> = internalEffect.fail(new Halt( * * @example * ```ts - * import { Pull, Cause, Exit } from "effect" + * import { Cause, Exit } from "effect" + * import { Pull } from "effect/stream" * * const halt = new Pull.Halt("completed") * const causeWithHalt = Cause.fail(halt) @@ -431,7 +444,8 @@ export const haltExitFromCause = (cause: Cause.Cause): Exit.Exit * @@ -35,7 +35,7 @@ export const TypeId: TypeId = "~effect/Sink" * * @example * ```ts - * import type { Sink } from "effect" + * import type * as Sink from "effect/stream/Sink" * * // Used for type-level programming * type SinkTypeId = Sink.TypeId @@ -55,7 +55,9 @@ export type TypeId = "~effect/Sink" * * @example * ```ts - * import { Sink, Stream, Effect } from "effect" + * import * as Sink from "effect/stream/Sink" + * import * as Stream from "effect/stream/Stream" + * import { Effect } from "effect" * * // Create a simple sink that always succeeds with a value * const sink: Sink.Sink = Sink.succeed(42) @@ -83,7 +85,9 @@ export interface Sink @@ -115,7 +119,7 @@ export interface SinkUnify extends Effec * * @example * ```ts - * import type { Sink } from "effect" + * import type * as Sink from "effect/stream/Sink" * * // Used internally by the type system * type IgnoreConfig = Sink.SinkUnifyIgnore @@ -133,7 +137,7 @@ export interface SinkUnifyIgnore extends Effect.EffectUnifyIgnore { * * @example * ```ts - * import type { Sink } from "effect" + * import type * as Sink from "effect/stream/Sink" * * // The Sink namespace contains internal type definitions * // These are used internally for type safety and variance @@ -150,7 +154,7 @@ export declare namespace Sink { * * @example * ```ts - * import type { Sink } from "effect" + * import type * as Sink from "effect/stream/Sink" * * // The variance interface is used internally * // It defines how type parameters behave in Sink @@ -169,7 +173,7 @@ export declare namespace Sink { * * @example * ```ts - * import type { Sink } from "effect" + * import type * as Sink from "effect/stream/Sink" * * // The variance structure is used internally by the type system * // It ensures proper type safety for Sink operations @@ -208,7 +212,8 @@ const SinkProto = { * * @example * ```ts - * import { Sink, Channel } from "effect" + * import { Sink } from "effect/stream" + * import { Channel } from "effect/stream" * * // Create a sink from a channel that ends immediately * const channel = Channel.end(42) @@ -231,7 +236,8 @@ export const fromChannel = ( * * @example * ```ts - * import { Sink, Channel } from "effect" + * import { Sink } from "effect/stream" + * import { Channel } from "effect/stream" * * // Create a sink and extract its channel * const sink = Sink.succeed(42) @@ -250,7 +256,9 @@ export const toChannel = ( * * @example * ```ts - * import { Sink, Stream, Effect } from "effect" + * import { Sink } from "effect/stream" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * // Create a sink that always yields the same value * const sink = Sink.succeed(42) @@ -273,7 +281,9 @@ export const succeed = (a: A): Sink => fromChannel(Channel.end(a)) * * @example * ```ts - * import { Sink, Stream, Effect } from "effect" + * import { Sink } from "effect/stream" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * // Create a sink that always fails * const sink = Sink.fail(new Error("Sink failed")) @@ -296,7 +306,9 @@ export const fail = (e: E): Sink => fromChannel(Cha * * @example * ```ts - * import { Sink, Stream, Effect } from "effect" + * import { Sink } from "effect/stream" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * // Create a sink that fails with a lazy error * const sink = Sink.failSync(() => new Error("Lazy error")) @@ -320,7 +332,9 @@ export const failSync = (evaluate: LazyArg): Sink(cause: Cause.Cause): Sink Cause.fail(new Error("Lazy cause"))) @@ -370,7 +386,9 @@ export const failCauseSync = (evaluate: LazyArg>): Sink => fromChannel(Channel.die(def * * @example * ```ts - * import { Sink, Stream, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { Sink, Stream } from "effect/stream" * * // Create a sink that logs each item * const sink = Sink.forEach((item: number) => Console.log(`Processing: ${item}`)) @@ -423,7 +443,9 @@ export const forEach = ( * * @example * ```ts - * import { Sink, Stream, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { Sink, Stream } from "effect/stream" * * // Create a sink that processes chunks * const sink = Sink.forEachChunk((chunk: readonly number[]) => @@ -455,7 +477,9 @@ export const forEachChunk = ( * * @example * ```ts - * import { Sink, Stream, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { Sink, Stream } from "effect/stream" * * // Create a sink from an effect that produces a sink * const sinkEffect = Effect.succeed(Sink.forEach((item: number) => Console.log(`Item: ${item}`))) diff --git a/packages/effect/src/Stream.ts b/packages/effect/src/stream/Stream.ts similarity index 89% rename from packages/effect/src/Stream.ts rename to packages/effect/src/stream/Stream.ts index 441ec70b61..253cec13c2 100644 --- a/packages/effect/src/Stream.ts +++ b/packages/effect/src/stream/Stream.ts @@ -1,35 +1,35 @@ /** * @since 2.0.0 */ -import * as Arr from "./Array.ts" -import * as Cause from "./Cause.ts" -import * as Channel from "./Channel.ts" -import * as Effect from "./Effect.ts" -import type * as Exit from "./Exit.ts" -import * as Fiber from "./Fiber.ts" -import type * as Filter from "./Filter.ts" -import type { LazyArg } from "./Function.ts" -import { dual, identity } from "./Function.ts" -import type { TypeLambda } from "./HKT.ts" -import * as Option from "./Option.ts" -import { type Pipeable, pipeArguments } from "./Pipeable.ts" -import { hasProperty } from "./Predicate.ts" -import type * as PubSub from "./PubSub.ts" -import * as Pull from "./Pull.ts" -import * as Queue from "./Queue.ts" -import * as Schedule from "./Schedule.ts" -import * as Scope from "./Scope.ts" -import * as ServiceMap from "./ServiceMap.ts" -import type * as Sink from "./Sink.ts" -import type { Covariant } from "./Types.ts" -import type * as Unify from "./Unify.ts" +import * as Cause from "../Cause.ts" +import * as Arr from "../collections/Array.ts" +import type * as PubSub from "../concurrency/PubSub.ts" +import * as Queue from "../concurrency/Queue.ts" +import type * as Filter from "../data/Filter.ts" +import * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Effect from "../Effect.ts" +import type * as Exit from "../Exit.ts" +import type { LazyArg } from "../Function.ts" +import { dual, identity } from "../Function.ts" +import { type Pipeable, pipeArguments } from "../interfaces/Pipeable.ts" +import * as Scope from "../resources/Scope.ts" +import * as Fiber from "../runtime/Fiber.ts" +import * as Schedule from "../scheduling/Schedule.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import * as Channel from "../stream/Channel.ts" +import * as Pull from "../stream/Pull.ts" +import type * as Sink from "../stream/Sink.ts" +import type { TypeLambda } from "../types/HKT.ts" +import type { Covariant } from "../types/Types.ts" +import type * as Unify from "../types/Unify.ts" /** * The type identifier for Stream. * * @example * ```ts - * import { Stream } from "effect" + * import * as Stream from "effect/stream/Stream" * * declare const stream: Stream.Stream * @@ -47,7 +47,7 @@ export const TypeId: TypeId = "~effect/Stream" * * @example * ```ts - * import type { Stream } from "effect" + * import type * as Stream from "effect/stream/Stream" * * // TypeId can be used in type-level operations * type StreamTypeId = Stream.TypeId @@ -78,7 +78,8 @@ export type TypeId = "~effect/Stream" * * @example * ```ts - * import { Effect, Stream } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * // Create a stream that emits numbers 1, 2, 3 * const stream: Stream.Stream = Stream.make(1, 2, 3) @@ -109,7 +110,8 @@ export interface Stream extends Variance @@ -132,7 +134,7 @@ export interface StreamUnify extends Eff * * @example * ```ts - * import type { Stream } from "effect" + * import type * as Stream from "effect/stream/Stream" * * // Used internally by the type system * // Users typically don't interact with this directly @@ -151,8 +153,8 @@ export interface StreamUnifyIgnore extends Effect.EffectUnifyIgnore { * * @example * ```ts - * import type { Kind } from "effect/HKT" - * import type { StreamTypeLambda } from "effect/Stream" + * import type { Kind } from "effect/types/HKT" + * import type { StreamTypeLambda } from "effect/stream/Stream" * * // Create a Stream type using the type lambda * type NumberStream = Kind @@ -193,7 +195,7 @@ export interface VarianceStruct { * * @example * ```ts - * import { Stream } from "effect" + * import { Stream } from "effect/stream" * * type NumberStream = Stream.Stream * type SuccessType = Stream.Success @@ -210,7 +212,7 @@ export type Success> = [T] extends [Stream * type ErrorType = Stream.Error @@ -227,7 +229,7 @@ export type Error> = [T] extends [Stream unknown } * type NumberStream = Stream.Stream @@ -252,7 +254,7 @@ const streamVariance = { * * @example * ```ts - * import { Stream } from "effect" + * import { Stream } from "effect/stream" * * const stream = Stream.make(1, 2, 3) * const notStream = { data: [1, 2, 3] } @@ -283,7 +285,8 @@ const StreamProto = { * * @example * ```ts - * import { Stream, Channel } from "effect" + * import { Stream } from "effect/stream" + * import { Channel } from "effect/stream" * * const myChannel = Channel.succeed([1, 2, 3] as const) * const stream = Stream.fromChannel(myChannel) @@ -318,7 +321,8 @@ export const fromEffect = (effect: Effect.Effect): Stream( * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const originalStream = Stream.make(1, 2, 3) * @@ -374,7 +379,7 @@ export const transformPull = ( * * @example * ```ts - * import { Stream } from "effect" + * import { Stream } from "effect/stream" * * const stream = Stream.make(1, 2, 3) * const channel = Stream.toChannel(stream) @@ -399,7 +404,9 @@ export const toChannel = ( * * @example * ```ts - * import { Stream, Queue, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const stream = Stream.callback((queue) => { * // Emit values to the stream @@ -430,7 +437,8 @@ export const callback = ( * * @example * ```ts - * import { Effect, Stream } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const emptyStream = Stream.empty * @@ -451,7 +459,8 @@ export const empty: Stream = fromChannel(Channel.empty) * * @example * ```ts - * import { Effect, Stream } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * // A Stream with a single number * const stream = Stream.succeed(3) @@ -470,7 +479,8 @@ export const succeed = (value: A): Stream => fromChannel(Channel.succeed(A * * @example * ```ts - * import { Effect, Stream } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make(1, 2, 3) * @@ -492,7 +502,8 @@ export const make = >(...values: As): Stream * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.sync(() => Math.random()) * @@ -513,7 +524,8 @@ export const sync = (evaluate: LazyArg): Stream => fromChannel(Channel. * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const lazyStream = Stream.suspend(() => { * console.log("Creating stream...") @@ -535,7 +547,8 @@ export const suspend = (stream: LazyArg>): Stream(error: E): Stream => fromChannel(Channel.fail( * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.failSync(() => new Error("Something went wrong")) * @@ -581,7 +595,9 @@ export const failSync = (evaluate: LazyArg): Stream => fromChann * * @example * ```ts - * import { Stream, Cause, Effect } from "effect" + * import { Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Cause } from "effect" * * const cause = Cause.fail("Database connection failed") * const stream = Stream.failCause(cause) @@ -600,7 +616,9 @@ export const failCause = (cause: Cause.Cause): Stream => fromCha * * @example * ```ts - * import { Stream, Cause, Effect } from "effect" + * import { Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Cause } from "effect" * * const stream = Stream.failCauseSync(() => * Cause.fail("Connection timeout after retries") @@ -625,7 +643,8 @@ export const failCauseSync = (evaluate: LazyArg>): Stream(iterator: IterableIterator, maxChunkSi * * @example * ```ts - * import { Effect, Stream } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const numbers = [1, 2, 3] * @@ -673,7 +693,8 @@ export const fromIterable = (iterable: Iterable): Stream => fromChannel * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const stream = Stream.fromArray(numbers) @@ -696,7 +717,9 @@ export const fromArray = (array: ReadonlyArray): Stream => * * @example * ```ts - * import { Stream, Queue, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" + * import { Queue } from "effect/concurrency" * * const program = Effect.gen(function* () { * const queue = yield* Queue.unbounded() @@ -721,7 +744,9 @@ export const fromQueue = (queue: Queue.Dequeue): Stream() @@ -747,7 +772,8 @@ export const fromPubSub = (pubsub: PubSub.PubSub, chunkSize?: number): Str * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const readableStream = new ReadableStream({ * start(controller) { @@ -810,7 +836,9 @@ export const fromSchedule = (schedule: Schedule.Schedule() @@ -835,7 +863,7 @@ export const fromSubscription = (pubsub: PubSub.Subscription, chunkSize?: * * @example * ```ts - * import { Stream } from "effect" + * import { Stream } from "effect/stream" * * // DOM element implementing EventListener * declare const button: HTMLButtonElement @@ -872,7 +900,8 @@ export interface EventListener { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * // In a browser environment * const clickStream = Stream.fromEventListener(document, "click") @@ -913,7 +942,9 @@ export const fromEventListener = ( * * @example * ```ts - * import { Effect, Option, Stream } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" +import * as Option from "effect/data/Option" * * const stream = Stream.paginate(0, (n) => [ * n, @@ -940,7 +971,9 @@ export const paginate = (s: S, f: (s: S) => readonly [A, Option.Option] * * @example * ```ts - * import { Stream, Option, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" +import * as Option from "effect/data/Option" * * const stream = Stream.paginateChunk(0, (n) => [ * [n], // emit single element as chunk @@ -966,7 +999,9 @@ export const paginateChunk = ( * * @example * ```ts - * import { Stream, Option, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" +import * as Option from "effect/data/Option" * * const stream = Stream.paginateChunkEffect(0, (n: number) => * Effect.succeed([ @@ -1010,7 +1045,9 @@ export const paginateChunkEffect = ( * * @example * ```ts - * import { Stream, Option, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" +import * as Option from "effect/data/Option" * * const stream = Stream.paginateEffect(0, (n: number) => * Effect.succeed([ @@ -1045,7 +1082,8 @@ export const paginateEffect = ( * * @example * ```ts - * import { Effect, Stream } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.range(1, 5) * @@ -1082,7 +1120,8 @@ export const range = ( * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * // A stream that never emits values or completes * const neverStream = Stream.never @@ -1102,7 +1141,8 @@ export const never: Stream = fromChannel(Channel.never) * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const effectThatCreatesStream = Effect.succeed( * Stream.make(1, 2, 3) @@ -1126,7 +1166,8 @@ export const unwrap = ( * * @example * ```ts - * import { Effect, Stream } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.fromArray([1, 2, 3]).pipe(Stream.map((n) => n + 1)) * @@ -1151,7 +1192,9 @@ export const map: { * * @example * ```ts - * import { Stream, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Console } from "effect/logging" * * const stream = Stream.make(1, 2, 3) * @@ -1211,7 +1254,9 @@ export const mapEffect: { * * @example * ```ts - * import { Console, Effect, Stream } from "effect" + * import { Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Console } from "effect/logging" * * const stream = Stream.fromArray([1, 2, 3]).pipe( * Stream.tap((n) => Console.log(`before mapping: ${n}`)), @@ -1264,7 +1309,8 @@ export const tap: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make(1, 2, 3) * @@ -1316,7 +1362,8 @@ export const flatMap: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const streamOfStreams = Stream.make( * Stream.make(1, 2), @@ -1361,7 +1408,8 @@ export const flatten: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream1 = Stream.make(1, 2, 3) * const stream2 = Stream.make(4, 5, 6) @@ -1389,7 +1437,9 @@ export const concat: { * * @example * ```ts - * import { Stream, Cause, Effect } from "effect" + * import { Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Cause } from "effect" * * const failingStream = Stream.make(1, 2).pipe( * Stream.concat(Stream.fail("Oops!")), @@ -1465,7 +1515,9 @@ export const mapError: { * * @example * ```ts - * import { Stream, Cause, Effect } from "effect" + * import { Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Cause } from "effect" * * const failingStream = Stream.fail("NetworkError") * @@ -1504,7 +1556,8 @@ export const catchCauseFilter: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const failingStream = Stream.fail("This will become a defect") * const stream = Stream.orDie(failingStream) @@ -1523,7 +1576,8 @@ export const orDie = (self: Stream): Stream => fr * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make(1, 2, 3, 4, 5) * @@ -1553,7 +1607,8 @@ export const take: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make(1, 2, 3, 4, 5, 6) * @@ -1615,7 +1670,8 @@ export const takeUntil: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make(1, 2, 3, 4, 5) * const result = Stream.takeUntilEffect(stream, (n) => @@ -1674,7 +1730,8 @@ export const takeUntilEffect: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make(1, 2, 3, 4, 5, 6) * const result = Stream.takeWhile(stream, (n) => n < 4) @@ -1703,7 +1760,8 @@ export const takeWhile: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make(1, 2, 3, 4, 5) * const result = Stream.takeWhileEffect(stream, (n) => @@ -1740,7 +1798,8 @@ export const takeWhileEffect: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make(1, 2, 3, 4, 5) * const result = Stream.drop(stream, 2) @@ -1779,7 +1838,8 @@ export const drop: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make(1, 2, 3, 4, 5) * const chunked = Stream.chunks(stream) @@ -1805,7 +1865,9 @@ export const chunks = (self: Stream): Stream, * * @example * ```ts - * import { Stream, Channel, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Stream, Channel } from "effect/stream" + * import { Console } from "effect/logging" * * // Create a channel that processes chunks - this is a conceptual example * // In practice, this function is primarily used with specialized channels @@ -1831,7 +1893,9 @@ export const chunks = (self: Stream): Stream, * * @example * ```ts - * import { Stream, Channel, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Stream, Channel } from "effect/stream" + * import { Console } from "effect/logging" * * // Practical example: combining two channels with pipeTo * declare const sourceChannel: Channel.Channel< @@ -1888,7 +1952,9 @@ export const pipeThroughChannel: { * * @example * ```ts - * import { Stream, Channel, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Stream, Channel } from "effect/stream" + * import { Console } from "effect/logging" * * // Channel that might fail during processing * declare const transformChannel: Channel.Channel< @@ -1910,7 +1976,9 @@ export const pipeThroughChannel: { * * @example * ```ts - * import { Stream, Channel, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Stream, Channel } from "effect/stream" + * import { Console } from "effect/logging" * * // Demonstrate error preservation: both stream and channel can fail * const failingStream = Stream.make(1, 2, 3).pipe( @@ -1957,7 +2025,8 @@ export const pipeThroughChannelOrFail: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const encoder = new TextEncoder() * const stream = Stream.make( @@ -1990,7 +2059,8 @@ export const decodeText: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make("Hello", " ", "World") * const encoded = Stream.encodeText(stream) @@ -2013,7 +2083,9 @@ export const encodeText = (self: Stream): Stream @@ -2077,7 +2149,8 @@ export const provideServices: { * * @example * ```ts - * import { Stream, Sink, Effect } from "effect" + * import { Effect } from "effect" + * import { Stream, Sink } from "effect/stream" * * const stream = Stream.make(1, 2, 3, 4, 5) * const collectSink = Sink.succeed(42) @@ -2112,7 +2185,8 @@ export const run: { * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make(1, 2, 3, 4, 5) * @@ -2142,7 +2216,8 @@ export const runCollect = (self: Stream): Effect.Effect(self: Stream): Effect.Effect @@ -2232,7 +2311,9 @@ export const runForEachChunk: { * * @example * ```ts - * import { Stream, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Console } from "effect/logging" * * const stream = Stream.make(1, 2, 3).pipe( * Stream.mapEffect((n) => Console.log(`Processing: ${n}`)) @@ -2257,7 +2338,9 @@ export const runDrain = (self: Stream): Effect.Effect( * * @example * ```ts - * import { Stream, Effect } from "effect" + * import { Stream } from "effect/stream" + * import { Effect } from "effect" * * const stream = Stream.make("Hello", " ", "World", "!") * const result = Stream.mkString(stream) @@ -2310,7 +2394,8 @@ export const mkString = (self: Stream): Effect.Effect` represents: + * - **OutElem**: The type of elements the channel outputs + * - **OutErr**: The type of errors the channel can produce + * - **OutDone**: The type of the final value when the channel completes + * - **InElem**: The type of elements the channel reads + * - **InErr**: The type of errors the channel can receive + * - **InDone**: The type of the final value from upstream + * - **Env**: The environment/context required by the channel + * + * ## Key Features + * + * - **Bi-directional**: Channels can both read and write + * - **Composable**: Channels can be piped, sequenced, and concatenated + * - **Resource-safe**: Automatic cleanup and resource management + * - **Error-handling**: Built-in error propagation and handling + * - **Concurrent**: Support for concurrent operations + * + * ## Composition Patterns + * + * 1. **Piping**: Connect channels where output of one becomes input of another + * 2. **Sequencing**: Use the result of one channel to create another + * 3. **Concatenating**: Combine multiple channels into a single channel + * + * @example + * ```ts + * import { Channel } from "effect/stream" + * import { Effect } from "effect" + * + * // Simple channel that outputs numbers + * const numberChannel = Channel.succeed(42) + * + * // Transform channel that doubles values + * const doubleChannel = Channel.map(numberChannel, (n) => n * 2) + * + * // Running the channel would output: 84 + * ``` + * + * @example + * ```ts + * import { Channel } from "effect/stream" + * import { Effect } from "effect" + * + * // Channel from an array of values + * const arrayChannel = Channel.fromArray([1, 2, 3, 4, 5]) + * + * // Transform the channel by mapping over values + * const transformedChannel = Channel.map(arrayChannel, (n) => n * 2) + * + * // This channel will output: 2, 4, 6, 8, 10 + * ``` + * + * @since 2.0.0 + */ +export * as Channel from "./Channel.ts" + +/** + * @since 4.0.0 + */ +export * as Pull from "./Pull.ts" + +/** + * @since 2.0.0 + */ +export * as Sink from "./Sink.ts" + +/** + * @since 2.0.0 + */ +export * as Stream from "./Stream.ts" diff --git a/packages/effect/src/stream/index.ts.tpl b/packages/effect/src/stream/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/stream/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/FastCheck.ts b/packages/effect/src/testing/FastCheck.ts similarity index 93% rename from packages/effect/src/FastCheck.ts rename to packages/effect/src/testing/FastCheck.ts index e2d3a236a6..dbde2f7772 100644 --- a/packages/effect/src/FastCheck.ts +++ b/packages/effect/src/testing/FastCheck.ts @@ -21,7 +21,7 @@ * * @example * ```ts - * import { FastCheck } from "effect" + * import { FastCheck } from "effect/testing/FastCheck" * * // Property: reverse of reverse should equal original * const reverseProp = FastCheck.property( @@ -39,7 +39,7 @@ * * @example * ```ts - * import { FastCheck } from "effect" + * import { FastCheck } from "effect/testing/FastCheck" * * // Test string concatenation properties * const concatProp = FastCheck.property( @@ -58,7 +58,7 @@ * * @example * ```ts - * import { FastCheck } from "effect" + * import { FastCheck } from "effect/testing/FastCheck" * * // Generate random data for testing * const personArbitrary = FastCheck.record({ diff --git a/packages/effect/src/TestClock.ts b/packages/effect/src/testing/TestClock.ts similarity index 90% rename from packages/effect/src/TestClock.ts rename to packages/effect/src/testing/TestClock.ts index 54c27c456c..1bbfcfe44c 100644 --- a/packages/effect/src/TestClock.ts +++ b/packages/effect/src/testing/TestClock.ts @@ -1,14 +1,14 @@ /** * @since 2.0.0 */ -import * as Arr from "./Array.ts" -import * as Clock from "./Clock.ts" -import * as Data from "./Data.ts" -import * as Duration from "./Duration.ts" -import * as Effect from "./Effect.ts" -import * as Fiber from "./Fiber.ts" -import * as Layer from "./Layer.ts" -import * as Order from "./Order.ts" +import * as Arr from "../collections/Array.ts" +import * as Data from "../data/Data.ts" +import * as Order from "../data/Order.ts" +import * as Effect from "../Effect.ts" +import * as Fiber from "../runtime/Fiber.ts" +import * as Layer from "../services/Layer.ts" +import * as Clock from "../time/Clock.ts" +import * as Duration from "../time/Duration.ts" /** * A `TestClock` simplifies deterministically and efficiently testing effects @@ -24,7 +24,11 @@ import * as Order from "./Order.ts" * * ```ts * import * as assert from "node:assert" - * import { Duration, Effect, Fiber, TestClock, Option, pipe } from "effect" + * import { Duration } from "effect/time" + * import { Effect, pipe } from "effect" + * import { Option } from "effect/data" + * import { Fiber } from "effect/runtime" + * import { TestClock } from "effect/testing" * * Effect.gen(function*() { * const fiber = yield* pipe( @@ -48,7 +52,8 @@ import * as Order from "./Order.ts" * * @example * ```ts - * import { Effect, TestClock } from "effect" + * import { Effect } from "effect" + * import { TestClock } from "effect/testing" * * const program = Effect.gen(function*() { * let executed = false @@ -92,7 +97,8 @@ export interface TestClock extends Clock.Clock { /** * @example * ```ts - * import { Effect, TestClock } from "effect" + * import { Effect } from "effect" + * import { TestClock } from "effect/testing" * * const program = Effect.gen(function*() { * // Create a TestClock with custom options @@ -113,7 +119,8 @@ export declare namespace TestClock { /** * @example * ```ts - * import { Effect, TestClock } from "effect" + * import { Effect } from "effect" + * import { TestClock } from "effect/testing" * * const program = Effect.gen(function*() { * // Create a TestClock with custom warning delay @@ -140,7 +147,8 @@ export declare namespace TestClock { /** * @example * ```ts - * import { Effect, TestClock } from "effect" + * import { Effect } from "effect" + * import { TestClock } from "effect/testing" * * const program = Effect.gen(function*() { * const testClock = yield* TestClock.make() @@ -184,7 +192,8 @@ const SleepOrder = Order.reverse(Order.struct({ * * @example * ```ts - * import { Effect, TestClock } from "effect" + * import { Effect } from "effect" + * import { TestClock } from "effect/testing" * * const program = Effect.gen(function*() { * // Create a TestClock with default settings @@ -338,7 +347,9 @@ export const make = Effect.fnUntraced(function*( * * @example * ```ts - * import { Effect, TestClock, Layer } from "effect" + * import { Effect } from "effect" + * import { Layer } from "effect/services" + * import { TestClock } from "effect/testing" * * // Create a TestClock layer * const testClockLayer = TestClock.layer() @@ -367,7 +378,8 @@ export const layer = (options?: TestClock.Options): Layer.Layer => * * @example * ```ts - * import { Effect, TestClock } from "effect" + * import { Effect } from "effect" + * import { TestClock } from "effect/testing" * * const program = Effect.gen(function*() { * // Use testClockWith to access the TestClock instance @@ -398,7 +410,8 @@ export const testClockWith = ( * * @example * ```ts - * import { Effect, TestClock } from "effect" + * import { Effect } from "effect" + * import { TestClock } from "effect/testing" * * const program = Effect.gen(function*() { * let executed = false @@ -429,7 +442,9 @@ export const adjust = (duration: Duration.DurationInput): Effect.Effect => * * @example * ```ts - * import { Effect, TestClock, Duration } from "effect" + * import { Duration } from "effect/time" + * import { Effect } from "effect" + * import { TestClock } from "effect/testing" * * const program = Effect.gen(function*() { * let executed = false @@ -461,7 +476,9 @@ export const setTime = (timestamp: number): Effect.Effect => * * @example * ```ts - * import { Effect, TestClock, Clock } from "effect" + * import { Effect } from "effect" + * import { Clock } from "effect/time" + * import { TestClock } from "effect/testing" * * const program = Effect.gen(function*() { * // Get the current test time (starts at epoch) diff --git a/packages/effect/src/TestConsole.ts b/packages/effect/src/testing/TestConsole.ts similarity index 87% rename from packages/effect/src/TestConsole.ts rename to packages/effect/src/testing/TestConsole.ts index f1621bb2ea..df4d02ec19 100644 --- a/packages/effect/src/TestConsole.ts +++ b/packages/effect/src/testing/TestConsole.ts @@ -1,11 +1,11 @@ /** * @since 4.0.0 */ -import * as Array from "./Array.ts" -import * as Console from "./Console.ts" -import * as Effect from "./Effect.ts" -import * as Layer from "./Layer.ts" -import * as Option from "./Option.ts" +import * as Array from "../collections/Array.ts" +import * as Option from "../data/Option.ts" +import * as Effect from "../Effect.ts" +import * as Console from "../logging/Console.ts" +import * as Layer from "../services/Layer.ts" /** * A `TestConsole` provides a testable implementation of the Console interface. @@ -17,7 +17,9 @@ import * as Option from "./Option.ts" * * @example * ```ts - * import { Console, Effect, TestConsole } from "effect" + * import { TestConsole } from "effect/testing" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function*() { * yield* Console.log("Hello, World!") @@ -53,7 +55,7 @@ export interface TestConsole extends Console.Console { * * @example * ```ts - * import { TestConsole } from "effect" + * import { TestConsole } from "effect/testing" * * // The TestConsole namespace provides types for testing * // Use TestConsole.make to create a test console instance @@ -70,7 +72,7 @@ export declare namespace TestConsole { * * @example * ```ts - * import { Console } from "effect" + * import { Console } from "effect/logging" * * // Method represents console method names like: * // "log", "error", "warn", "debug", "info", etc. @@ -88,7 +90,7 @@ export declare namespace TestConsole { * * @example * ```ts - * import { TestConsole } from "effect" + * import { TestConsole } from "effect/testing" * * // Entry represents captured console calls with their method and parameters * // Each entry contains: { method: string, parameters: ReadonlyArray } @@ -111,7 +113,9 @@ export declare namespace TestConsole { * * @example * ```ts - * import { Console, Effect, TestConsole } from "effect" + * import { TestConsole } from "effect/testing" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function*() { * yield* Console.log("Debug message") @@ -182,7 +186,8 @@ export const make = Effect.gen(function*() { * * @example * ```ts - * import { Effect, TestConsole } from "effect" + * import { TestConsole } from "effect/testing" + * import { Effect } from "effect" * * const program = TestConsole.testConsoleWith((testConsole) => * Effect.gen(function*() { @@ -211,7 +216,9 @@ export const testConsoleWith = (f: (console: TestConsole) => Effect.Eff * * @example * ```ts - * import { Console, Effect, TestConsole } from "effect" + * import { TestConsole } from "effect/testing" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function*() { * yield* Console.log("This will be captured") @@ -237,7 +244,9 @@ export const layer: Layer.Layer = Layer.effect(Console.Console, mak * * @example * ```ts - * import { Console, Effect, TestConsole } from "effect" + * import { TestConsole } from "effect/testing" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function*() { * yield* Console.log("First message") @@ -268,7 +277,9 @@ export const logLines: Effect.Effect, never, never> = tes * * @example * ```ts - * import { Console, Effect, TestConsole } from "effect" + * import { TestConsole } from "effect/testing" + * import { Effect } from "effect" + * import { Console } from "effect/logging" * * const program = Effect.gen(function*() { * yield* Console.error("Error message") diff --git a/packages/effect/src/testing/index.ts b/packages/effect/src/testing/index.ts new file mode 100644 index 0000000000..1409503a0e --- /dev/null +++ b/packages/effect/src/testing/index.ts @@ -0,0 +1,26 @@ +/** + * @since 4.0.0 + */ + +/** + * This module provides a re-export of the fast-check library for property-based testing. + * Fast-check is a property-based testing framework that generates random test cases + * to validate that properties hold true for a wide range of inputs. + * + * Property-based testing is a testing methodology where you specify properties that + * should hold true for your functions, and the framework generates many random test + * cases to try to find counterexamples. + * + * @since 3.10.0 + */ +export * as FastCheck from "./FastCheck.ts" + +/** + * @since 2.0.0 + */ +export * as TestClock from "./TestClock.ts" + +/** + * @since 4.0.0 + */ +export * as TestConsole from "./TestConsole.ts" diff --git a/packages/effect/src/testing/index.ts.tpl b/packages/effect/src/testing/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/testing/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/Clock.ts b/packages/effect/src/time/Clock.ts similarity index 86% rename from packages/effect/src/Clock.ts rename to packages/effect/src/time/Clock.ts index 1369d04a59..d095392d61 100644 --- a/packages/effect/src/Clock.ts +++ b/packages/effect/src/time/Clock.ts @@ -19,7 +19,8 @@ * * @example * ```ts - * import { Clock, Effect } from "effect" + * import { Effect } from "effect" + * import { Clock } from "effect/time" * * // Get current time in milliseconds * const getCurrentTime = Clock.currentTimeMillis @@ -38,7 +39,8 @@ * * @example * ```ts - * import { Clock, Effect } from "effect" + * import { Effect } from "effect" + * import { Clock } from "effect/time" * * // Using Clock service directly * const program = Effect.gen(function* () { @@ -56,10 +58,10 @@ * * @since 2.0.0 */ -import type * as Duration from "./Duration.ts" -import type { Effect } from "./Effect.ts" -import * as effect from "./internal/effect.ts" -import type * as ServiceMap from "./ServiceMap.ts" +import type { Effect } from "../Effect.ts" +import * as effect from "../internal/effect.ts" +import type * as ServiceMap from "../services/ServiceMap.ts" +import type * as Duration from "../time/Duration.ts" /** * Represents a time-based clock which provides functionality related to time @@ -67,8 +69,8 @@ import type * as ServiceMap from "./ServiceMap.ts" * * @example * ```ts - * import * as Clock from "effect/Clock" - * import * as Effect from "effect/Effect" + * import { Effect } from "effect" + * import { Clock } from "effect/time" * * const clockOperations = Effect.gen(function* () { * const currentTime = yield* Clock.currentTimeMillis @@ -110,7 +112,8 @@ export interface Clock { * * @example * ```ts - * import { Clock, Effect } from "effect" + * import { Effect } from "effect" + * import { Clock } from "effect/time" * * const program = Effect.gen(function* () { * const clock = yield* Clock.Clock @@ -128,7 +131,8 @@ export const Clock: ServiceMap.Reference = effect.ClockRef * * @example * ```ts - * import { Clock, Effect } from "effect" + * import { Effect } from "effect" + * import { Clock } from "effect/time" * * const program = Clock.clockWith((clock) => * Effect.sync(() => { @@ -149,7 +153,8 @@ export const clockWith: (f: (clock: Clock) => Effect) => Effec * * @example * ```ts - * import { Clock, Effect } from "effect" + * import { Effect } from "effect" + * import { Clock } from "effect/time" * * const program = Effect.gen(function* () { * const currentTime = yield* Clock.currentTimeMillis @@ -168,7 +173,8 @@ export const currentTimeMillis: Effect = effect.currentTimeMillis * * @example * ```ts - * import { Clock, Effect } from "effect" + * import { Effect } from "effect" + * import { Clock } from "effect/time" * * const program = Effect.gen(function* () { * const currentTime = yield* Clock.currentTimeNanos diff --git a/packages/effect/src/Cron.ts b/packages/effect/src/time/Cron.ts similarity index 93% rename from packages/effect/src/Cron.ts rename to packages/effect/src/time/Cron.ts index 11c9d2e53e..92eaabe0e6 100644 --- a/packages/effect/src/Cron.ts +++ b/packages/effect/src/time/Cron.ts @@ -1,21 +1,21 @@ /** * @since 2.0.0 */ -import * as Arr from "./Array.ts" -import type * as DateTime from "./DateTime.ts" -import * as Equal from "./Equal.ts" -import * as equivalence from "./Equivalence.ts" -import { constVoid, dual, pipe } from "./Function.ts" -import * as Hash from "./Hash.ts" -import { format, type Inspectable, NodeInspectSymbol } from "./Inspectable.ts" -import * as dateTime from "./internal/dateTime.ts" -import * as N from "./Number.ts" -import * as Option from "./Option.ts" -import { type Pipeable, pipeArguments } from "./Pipeable.ts" -import { hasProperty } from "./Predicate.ts" -import * as Result from "./Result.ts" -import * as String from "./String.ts" -import type { Mutable } from "./Types.ts" +import * as Arr from "../collections/Array.ts" +import * as equivalence from "../data/Equivalence.ts" +import * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Result from "../data/Result.ts" +import { constVoid, dual, pipe } from "../Function.ts" +import * as Equal from "../interfaces/Equal.ts" +import * as Hash from "../interfaces/Hash.ts" +import { format, type Inspectable, NodeInspectSymbol } from "../interfaces/Inspectable.ts" +import { type Pipeable, pipeArguments } from "../interfaces/Pipeable.ts" +import * as dateTime from "../internal/dateTime.ts" +import * as N from "../primitives/Number.ts" +import * as String from "../primitives/String.ts" +import type * as DateTime from "../time/DateTime.ts" +import type { Mutable } from "../types/Types.ts" /** * Unique identifier for the Cron type. @@ -25,7 +25,7 @@ import type { Mutable } from "./Types.ts" * * @example * ```ts - * import { Cron } from "effect" + * import { Cron } from "effect/time" * * const cronInstance = Cron.make({ * minutes: [0], @@ -51,7 +51,7 @@ export const TypeId: TypeId = "~effect/Cron" * * @example * ```ts - * import { Cron } from "effect" + * import { Cron } from "effect/time" * * // The TypeId is part of the Cron interface * const cron: Cron.Cron = Cron.make({ @@ -77,7 +77,7 @@ export type TypeId = "~effect/Cron" * * @example * ```ts - * import { Cron } from "effect" + * import { Cron } from "effect/time" * * // Create a cron that runs at 9 AM on weekdays * const weekdayMorning = Cron.make({ @@ -174,7 +174,7 @@ const CronProto = { * * @example * ```ts - * import { Cron } from "effect" + * import { Cron } from "effect/time" * * const cron = Cron.make({ * minutes: [0], @@ -203,7 +203,7 @@ export const isCron = (u: unknown): u is Cron => hasProperty(u, TypeId) * * @example * ```ts - * import { Cron } from "effect" + * import { Cron } from "effect/time" * * // Every day at midnight * const midnight = Cron.make({ @@ -299,7 +299,8 @@ const nextLookupTable = (values: ReadonlyArray, size: number): Array { * * @example * ```ts - * import { Cron, Result } from "effect" + * import { Cron } from "effect/time" + * import { Result } from "effect/data" * * const result = Cron.parse("invalid cron expression") * if (Result.isFailure(result)) { @@ -412,7 +416,8 @@ export const isCronParseError = (u: unknown): u is CronParseError => hasProperty * @example * ```ts * import * as assert from "node:assert" - * import { Cron, Result } from "effect" + * import { Cron } from "effect/time" + * import { Result } from "effect/data" * * // At 04:00 on every day-of-month from 8 through 14. * assert.deepStrictEqual(Cron.parse("0 0 4 8-14 * *"), Result.succeed(Cron.make({ @@ -463,7 +468,7 @@ export const parse = (cron: string, tz?: DateTime.TimeZone | string): Result.Res * * @example * ```ts - * import { Cron } from "effect" + * import { Cron } from "effect/time" * * // At 04:00 on every day-of-month from 8 through 14 * const cron = Cron.unsafeParse("0 0 4 8-14 * *") @@ -489,7 +494,8 @@ export const unsafeParse = (cron: string, tz?: DateTime.TimeZone | string): Cron * * @example * ```ts - * import { Cron, Result } from "effect" + * import { Cron } from "effect/time" + * import { Result } from "effect/data" * * const cron = Result.getOrThrow(Cron.parse("0 0 4 8-14 * *")) * @@ -555,7 +561,8 @@ const daysInMonth = (date: Date): number => * * @example * ```ts - * import { Cron, Result } from "effect" + * import { Cron } from "effect/time" + * import { Result } from "effect/data" * * const cron = Result.getOrThrow(Cron.parse("0 0 4 8-14 * *")) * @@ -703,7 +710,8 @@ export const next = (cron: Cron, now?: DateTime.DateTime.Input): Date => { * * @example * ```ts - * import { Cron, Result } from "effect" + * import { Cron } from "effect/time" + * import { Result } from "effect/data" * * const cron = Result.getOrThrow(Cron.parse("0 0 9 * * 1-5")) // 9 AM weekdays * @@ -733,7 +741,8 @@ export const sequence = function*(cron: Cron, now?: DateTime.DateTime.Input): It * * @example * ```ts - * import { Cron, Equivalence } from "effect" + * import { Cron } from "effect/time" + * import * as Equivalence from "effect/data/Equivalence" * * const cron1 = Cron.make({ * minutes: [0, 30], @@ -778,7 +787,7 @@ const restrictionsEquals = (self: ReadonlySet, that: ReadonlySet * * @example * ```ts - * import { Cron } from "effect" + * import { Cron } from "effect/time" * * const cron1 = Cron.make({ * minutes: [0], diff --git a/packages/effect/src/DateTime.ts b/packages/effect/src/time/DateTime.ts similarity index 91% rename from packages/effect/src/DateTime.ts rename to packages/effect/src/time/DateTime.ts index 94d48be845..7b5aac1eda 100644 --- a/packages/effect/src/DateTime.ts +++ b/packages/effect/src/time/DateTime.ts @@ -1,25 +1,25 @@ /** * @since 3.6.0 */ -import type { IllegalArgumentError } from "./Cause.ts" -import type * as Duration from "./Duration.ts" -import * as Effect from "./Effect.ts" -import type * as equivalence from "./Equivalence.ts" -import { dual, type LazyArg } from "./Function.ts" -import type { Inspectable } from "./Inspectable.ts" -import * as Internal from "./internal/dateTime.ts" -import { provideService } from "./internal/effect.ts" -import * as Layer from "./Layer.ts" -import type * as Option from "./Option.ts" -import type * as order from "./Order.ts" -import type { Pipeable } from "./Pipeable.ts" -import type * as Result from "./Result.ts" -import * as ServiceMap from "./ServiceMap.ts" +import type { IllegalArgumentError } from "../Cause.ts" +import type * as equivalence from "../data/Equivalence.ts" +import type * as Option from "../data/Option.ts" +import type * as order from "../data/Order.ts" +import type * as Result from "../data/Result.ts" +import * as Effect from "../Effect.ts" +import { dual, type LazyArg } from "../Function.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import * as Internal from "../internal/dateTime.ts" +import { provideService } from "../internal/effect.ts" +import * as Layer from "../services/Layer.ts" +import * as ServiceMap from "../services/ServiceMap.ts" +import type * as Duration from "../time/Duration.ts" /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * console.log(DateTime.TypeId) // "~effect/DateTime" * ``` @@ -32,7 +32,7 @@ export const TypeId: TypeId = Internal.TypeId /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * type MyTypeId = DateTime.TypeId // "~effect/DateTime" * ``` @@ -48,7 +48,7 @@ export type TypeId = "~effect/DateTime" * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // Create a UTC DateTime * const utc: DateTime.DateTime = DateTime.unsafeNow() @@ -67,7 +67,7 @@ export type DateTime = Utc | Zoned /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const utc = DateTime.unsafeNow() * @@ -89,7 +89,7 @@ export interface Utc extends DateTime.Proto { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const zoned = DateTime.unsafeMakeZoned(new Date(), { * timeZone: "Europe/London" @@ -117,7 +117,7 @@ export interface Zoned extends DateTime.Proto { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // The DateTime namespace contains types and utilities * const dt = DateTime.unsafeNow() @@ -131,7 +131,7 @@ export declare namespace DateTime { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // All valid inputs for DateTime constructors * const date = new Date() @@ -156,7 +156,7 @@ export declare namespace DateTime { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // When making from a zoned DateTime, preserves the zone * const zoned = DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" }) @@ -174,7 +174,7 @@ export declare namespace DateTime { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeNow() * @@ -191,7 +191,7 @@ export declare namespace DateTime { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeNow() * @@ -216,7 +216,7 @@ export declare namespace DateTime { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeNow() * @@ -241,7 +241,7 @@ export declare namespace DateTime { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-01-15T14:30:45.123Z") * const parts = DateTime.toParts(dt) @@ -271,7 +271,7 @@ export declare namespace DateTime { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const parts = { * year: 2024, @@ -300,7 +300,7 @@ export declare namespace DateTime { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeNow() * @@ -331,7 +331,7 @@ export declare namespace DateTime { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // All DateTime instances implement Proto * const dt = DateTime.unsafeNow() @@ -357,7 +357,7 @@ export declare namespace DateTime { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * console.log(DateTime.TimeZoneTypeId) // "~effect/DateTime/TimeZone" * ``` @@ -370,7 +370,7 @@ export const TimeZoneTypeId: TimeZoneTypeId = Internal.TimeZoneTypeId /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * type MyTimeZoneTypeId = DateTime.TimeZoneTypeId // "~effect/DateTime/TimeZone" * ``` @@ -383,7 +383,7 @@ export type TimeZoneTypeId = "~effect/DateTime/TimeZone" /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // Create different types of time zones * const offsetZone: DateTime.TimeZone = DateTime.zoneMakeOffset(3 * 60 * 60 * 1000) @@ -401,7 +401,7 @@ export type TimeZone = TimeZone.Offset | TimeZone.Named /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // The TimeZone namespace contains time zone-related types * type Offset = DateTime.TimeZone.Offset @@ -415,7 +415,7 @@ export declare namespace TimeZone { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const zone = DateTime.zoneMakeOffset(0) * @@ -433,7 +433,7 @@ export declare namespace TimeZone { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // Create an offset time zone (+3 hours) * const zone = DateTime.zoneMakeOffset(3 * 60 * 60 * 1000) @@ -455,7 +455,7 @@ export declare namespace TimeZone { /** * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const zone = DateTime.zoneUnsafeMakeNamed("Europe/London") * @@ -485,7 +485,7 @@ export declare namespace TimeZone { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * console.log(DateTime.isDateTime(DateTime.unsafeNow())) // true * console.log(DateTime.isDateTime(new Date())) // false @@ -502,7 +502,7 @@ export const isDateTime: (u: unknown) => u is DateTime = Internal.isDateTime * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const zone = DateTime.zoneMakeOffset(3 * 60 * 60 * 1000) * console.log(DateTime.isTimeZone(zone)) // true @@ -519,7 +519,7 @@ export const isTimeZone: (u: unknown) => u is TimeZone = Internal.isTimeZone * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const offsetZone = DateTime.zoneMakeOffset(3 * 60 * 60 * 1000) * const namedZone = DateTime.zoneUnsafeMakeNamed("Europe/London") @@ -538,7 +538,7 @@ export const isTimeZoneOffset: (u: unknown) => u is TimeZone.Offset = Internal.i * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const offsetZone = DateTime.zoneMakeOffset(3 * 60 * 60 * 1000) * const namedZone = DateTime.zoneUnsafeMakeNamed("Europe/London") @@ -557,7 +557,7 @@ export const isTimeZoneNamed: (u: unknown) => u is TimeZone.Named = Internal.isT * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const utc = DateTime.unsafeNow() * const zoned = DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" }) @@ -576,7 +576,7 @@ export const isUtc: (self: DateTime) => self is Utc = Internal.isUtc * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const utc = DateTime.unsafeNow() * const zoned = DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" }) @@ -602,7 +602,7 @@ export const isZoned: (self: DateTime) => self is Zoned = Internal.isZoned * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const utc = DateTime.unsafeMake("2024-01-01T12:00:00Z") * const zoned = DateTime.unsafeMakeZoned("2024-01-01T12:00:00Z", { @@ -625,7 +625,8 @@ export const Equivalence: equivalence.Equivalence = Internal.Equivalen * * @example * ```ts - * import { DateTime, Array } from "effect" + * import { DateTime } from "effect/time" + * import { Array } from "effect/collections" * * const dates = [ * DateTime.unsafeMake("2024-03-01"), @@ -651,7 +652,7 @@ export const Order: order.Order = Internal.Order * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const min = DateTime.unsafeMake("2024-01-01") * const max = DateTime.unsafeMake("2024-12-31") @@ -685,7 +686,7 @@ export const clamp: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const date = new Date("2024-01-01T12:00:00Z") * const dateTime = DateTime.unsafeFromDate(date) @@ -711,7 +712,7 @@ export const unsafeFromDate: (date: Date) => Utc = Internal.unsafeFromDate * @category constructors * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // from Date * DateTime.unsafeMake(new Date()) @@ -736,7 +737,7 @@ export const unsafeMake: (input: A) => DateTime.Preser * @category constructors * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" }) * ``` @@ -757,7 +758,7 @@ export const unsafeMakeZoned: (input: DateTime.Input, options?: { * @category constructors * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * DateTime.makeZoned(new Date(), { timeZone: "Europe/London" }) * ``` @@ -785,7 +786,7 @@ export const makeZoned: ( * @category constructors * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // from Date * DateTime.make(new Date()) @@ -806,7 +807,8 @@ export const make: (input: A) => Option.Option Option.Option = Inte * @category constructors * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * const now = yield* DateTime.now @@ -847,7 +850,7 @@ export const now: Effect.Effect = Internal.now * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const now = DateTime.unsafeNow() * console.log(DateTime.formatIso(now)) @@ -869,7 +872,8 @@ export const unsafeNow: LazyArg = Internal.unsafeNow * @category time zones * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * const now = yield* DateTime.now @@ -898,7 +902,8 @@ export const setZone: { * @category time zones * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * const now = yield* DateTime.now @@ -924,7 +929,7 @@ export const setZoneOffset: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const londonZone = DateTime.zoneUnsafeMakeNamed("Europe/London") * console.log(DateTime.zoneToString(londonZone)) // "Europe/London" @@ -949,7 +954,7 @@ export const zoneUnsafeMakeNamed: (zoneId: string) => TimeZone.Named = Internal. * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // Create a time zone with +3 hours offset * const zone = DateTime.zoneMakeOffset(3 * 60 * 60 * 1000) @@ -971,7 +976,8 @@ export const zoneMakeOffset: (offset: number) => TimeZone.Offset = Internal.zone * * @example * ```ts - * import { DateTime, Option } from "effect" + * import { DateTime } from "effect/time" + * import { Option } from "effect/data" * * const validZone = DateTime.zoneMakeNamed("Europe/London") * console.log(Option.isSome(validZone)) // true @@ -992,7 +998,8 @@ export const zoneMakeNamed: (zoneId: string) => Option.Option = * * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * const program = Effect.gen(function* () { * const zone = yield* DateTime.zoneMakeNamedEffect("Europe/London") @@ -1015,7 +1022,7 @@ export const zoneMakeNamedEffect: (zoneId: string) => Effect.Effect TimeZone.Named = Internal.zoneMakeLocal * * @example * ```ts - * import { DateTime, Option } from "effect" + * import { DateTime } from "effect/time" + * import { Option } from "effect/data" * * const namedZone = DateTime.zoneFromString("Europe/London") * const offsetZone = DateTime.zoneFromString("+03:00") @@ -1059,7 +1067,8 @@ export const zoneFromString: (zone: string) => Option.Option = Interna * @category time zones * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * // Outputs "+03:00" * DateTime.zoneToString(DateTime.zoneMakeOffset(3 * 60 * 60 * 1000)) @@ -1078,7 +1087,8 @@ export const zoneToString: (self: TimeZone) => string = Internal.zoneToString * @category time zones * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * const now = yield* DateTime.now @@ -1104,7 +1114,8 @@ export const setZoneNamed: { * @category time zones * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * const now = yield* DateTime.now @@ -1136,7 +1147,8 @@ export const unsafeSetZoneNamed: { * @category comparisons * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * const now = yield* DateTime.now @@ -1165,7 +1177,8 @@ export const distance: { * @category comparisons * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * const now = yield* DateTime.now @@ -1191,7 +1204,8 @@ export const distanceDurationResult: { * @category comparisons * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * const now = yield* DateTime.now @@ -1212,7 +1226,7 @@ export const distanceDuration: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const date1 = DateTime.unsafeMake("2024-01-01") * const date2 = DateTime.unsafeMake("2024-02-01") @@ -1234,7 +1248,7 @@ export const min: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const date1 = DateTime.unsafeMake("2024-01-01") * const date2 = DateTime.unsafeMake("2024-02-01") @@ -1256,7 +1270,7 @@ export const max: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const date1 = DateTime.unsafeMake("2024-02-01") * const date2 = DateTime.unsafeMake("2024-01-01") @@ -1278,7 +1292,7 @@ export const greaterThan: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const date1 = DateTime.unsafeMake("2024-01-01") * const date2 = DateTime.unsafeMake("2024-01-01") @@ -1302,7 +1316,7 @@ export const greaterThanOrEqualTo: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const date1 = DateTime.unsafeMake("2024-01-01") * const date2 = DateTime.unsafeMake("2024-02-01") @@ -1324,7 +1338,7 @@ export const lessThan: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const date1 = DateTime.unsafeMake("2024-01-01") * const date2 = DateTime.unsafeMake("2024-01-01") @@ -1348,7 +1362,7 @@ export const lessThanOrEqualTo: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const min = DateTime.unsafeMake("2024-01-01") * const max = DateTime.unsafeMake("2024-12-31") @@ -1372,7 +1386,8 @@ export const between: { * * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * const program = Effect.gen(function* () { * const futureDate = DateTime.add(yield* DateTime.now, { hours: 1 }) @@ -1393,7 +1408,7 @@ export const isFuture: (self: DateTime) => Effect.Effect = Internal.isF * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const now = DateTime.unsafeNow() * const futureDate = DateTime.add(now, { hours: 1 }) @@ -1414,7 +1429,8 @@ export const unsafeIsFuture: (self: DateTime) => boolean = Internal.unsafeIsFutu * * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * const program = Effect.gen(function* () { * const pastDate = DateTime.subtract(yield* DateTime.now, { hours: 1 }) @@ -1435,7 +1451,7 @@ export const isPast: (self: DateTime) => Effect.Effect = Internal.isPas * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const now = DateTime.unsafeNow() * const pastDate = DateTime.subtract(now, { hours: 1 }) @@ -1460,7 +1476,7 @@ export const unsafeIsPast: (self: DateTime) => boolean = Internal.unsafeIsPast * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMakeZoned("2024-01-01T12:00:00Z", { * timeZone: "Europe/London" @@ -1483,7 +1499,7 @@ export const toDateUtc: (self: DateTime) => Date = Internal.toDateUtc * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const utc = DateTime.unsafeMake("2024-01-01T12:00:00Z") * const zoned = DateTime.unsafeMakeZoned("2024-01-01T12:00:00Z", { @@ -1507,7 +1523,7 @@ export const toDate: (self: DateTime) => Date = Internal.toDate * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const zoned = DateTime.unsafeMakeZoned("2024-01-01T12:00:00Z", { * timeZone: "Europe/London" @@ -1529,7 +1545,7 @@ export const zonedOffset: (self: Zoned) => number = Internal.zonedOffset * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const zoned = DateTime.unsafeMakeZoned("2024-01-01T12:00:00Z", { * timeZone: DateTime.zoneMakeOffset(3 * 60 * 60 * 1000) // +3 hours @@ -1551,7 +1567,7 @@ export const zonedOffsetIso: (self: Zoned) => string = Internal.zonedOffsetIso * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-01-01T00:00:00Z") * const epochMillis = DateTime.toEpochMillis(dt) @@ -1573,7 +1589,7 @@ export const toEpochMillis: (self: DateTime) => number = Internal.toEpochMillis * @category conversions * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // returns "2024-01-01T00:00:00Z" * DateTime.unsafeMakeZoned("2024-01-01T05:00:00Z", { @@ -1598,7 +1614,7 @@ export const removeTime: (self: DateTime) => Utc = Internal.removeTime * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-01-01T12:30:45.123Z") * const parts = DateTime.toParts(dt) @@ -1628,7 +1644,7 @@ export const toParts: (self: DateTime) => DateTime.PartsWithWeekday = Internal.t * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const zoned = DateTime.unsafeMakeZoned("2024-01-01T12:30:45.123Z", { * timeZone: "Europe/London" @@ -1654,7 +1670,7 @@ export const toPartsUtc: (self: DateTime) => DateTime.PartsWithWeekday = Interna * @example * ```ts * import * as assert from "node:assert" - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const now = DateTime.unsafeMake({ year: 2024 }) * const year = DateTime.getPartUtc(now, "year") @@ -1676,7 +1692,7 @@ export const getPartUtc: { * @example * ```ts * import * as assert from "node:assert" - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const now = DateTime.unsafeMakeZoned({ year: 2024 }, { timeZone: "Europe/London" }) * const year = DateTime.getPart(now, "year") @@ -1695,7 +1711,7 @@ export const getPart: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-01-01T12:00:00Z") * const updated = DateTime.setParts(dt, { @@ -1722,7 +1738,7 @@ export const setParts: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-01-01T12:00:00Z") * const updated = DateTime.setPartsUtc(dt, { @@ -1748,7 +1764,8 @@ export const setPartsUtc: { /** * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * const program = Effect.gen(function* () { * // Access the current time zone service @@ -1774,7 +1791,8 @@ export class CurrentTimeZone extends ServiceMap.Key() * @category current time zone * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * const now = yield* DateTime.now @@ -1794,7 +1812,8 @@ export const setZoneCurrent = (self: DateTime): Effect.Effect( * @category current time zone * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * // will use the system's local time zone @@ -1865,7 +1886,8 @@ export const withCurrentZoneOffset: { * @category current time zone * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * // will use the "Europe/London" time zone @@ -1897,7 +1919,8 @@ export const withCurrentZoneNamed: { * @category current time zone * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * Effect.gen(function* () { * // will use the "Europe/London" time zone @@ -1919,7 +1942,7 @@ export const nowInCurrentZone: Effect.Effect = Ef * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-01-01T12:00:00Z") * @@ -1944,7 +1967,7 @@ export const mutate: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMakeZoned("2024-01-01T12:00:00Z", { * timeZone: "Europe/London" @@ -1973,7 +1996,7 @@ export const mutateUtc: { * @category mapping * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // add 10 milliseconds * DateTime.unsafeMake(0).pipe( @@ -1994,7 +2017,7 @@ export const mapEpochMillis: { * @category mapping * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // get the time zone adjusted date in milliseconds * DateTime.unsafeMakeZoned(0, { timeZone: "Europe/London" }).pipe( @@ -2015,7 +2038,7 @@ export const withDate: { * @category mapping * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // get the date in milliseconds * DateTime.unsafeMake(0).pipe( @@ -2033,7 +2056,7 @@ export const withDateUtc: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt1 = DateTime.unsafeNow() // Utc * const dt2 = DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" }) // Zoned @@ -2074,7 +2097,7 @@ export const match: { * @category math * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // add 5 minutes * DateTime.unsafeMake(0).pipe( @@ -2094,7 +2117,7 @@ export const addDuration: { * @category math * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // subtract 5 minutes * DateTime.unsafeMake(0).pipe( @@ -2117,7 +2140,7 @@ export const subtractDuration: { * @category math * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // add 5 minutes * DateTime.unsafeMake(0).pipe( @@ -2137,7 +2160,7 @@ export const add: { * @category math * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // subtract 5 minutes * DateTime.unsafeMake(0).pipe( @@ -2160,7 +2183,7 @@ export const subtract: { * @category math * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // returns "2024-01-01T00:00:00Z" * DateTime.unsafeMake("2024-01-01T12:00:00Z").pipe( @@ -2191,7 +2214,7 @@ export const startOf: { * @category math * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // returns "2024-01-01T23:59:59.999Z" * DateTime.unsafeMake("2024-01-01T12:00:00Z").pipe( @@ -2222,7 +2245,7 @@ export const endOf: { * @category math * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * // returns "2024-01-02T00:00:00Z" * DateTime.unsafeMake("2024-01-01T12:01:00Z").pipe( @@ -2257,7 +2280,7 @@ export const nearest: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMakeZoned("2024-06-15T14:30:00Z", { * timeZone: "Europe/London" @@ -2300,7 +2323,7 @@ export const format: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-06-15T14:30:00Z") * @@ -2344,7 +2367,7 @@ export const formatLocal: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMakeZoned("2024-06-15T14:30:00Z", { * timeZone: "Europe/London" @@ -2389,7 +2412,7 @@ export const formatUtc: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-06-15T14:30:00Z") * @@ -2422,7 +2445,7 @@ export const formatIntl: { * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-01-01T12:30:45.123Z") * console.log(DateTime.formatIso(dt)) // "2024-01-01T12:30:45.123Z" @@ -2445,7 +2468,7 @@ export const formatIso: (self: DateTime) => string = Internal.formatIso * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-01-01T23:30:00Z") * console.log(DateTime.formatIsoDate(dt)) // "2024-01-01" @@ -2468,7 +2491,7 @@ export const formatIsoDate: (self: DateTime) => string = Internal.formatIsoDate * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const dt = DateTime.unsafeMake("2024-01-01T23:30:00Z") * console.log(DateTime.formatIsoDateUtc(dt)) // "2024-01-01" @@ -2492,7 +2515,7 @@ export const formatIsoDateUtc: (self: DateTime) => string = Internal.formatIsoDa * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const utc = DateTime.unsafeMake("2024-01-01T12:00:00Z") * console.log(DateTime.formatIsoOffset(utc)) // "2024-01-01T12:00:00.000Z" @@ -2515,7 +2538,7 @@ export const formatIsoOffset: (self: DateTime) => string = Internal.formatIsoOff * * @example * ```ts - * import { DateTime } from "effect" + * import { DateTime } from "effect/time" * * const zoned = DateTime.unsafeMakeZoned("2024-06-15T14:30:45.123Z", { * timeZone: "Europe/London" @@ -2544,7 +2567,9 @@ export const formatIsoZoned: (self: Zoned) => string = Internal.formatIsoZoned * * @example * ```ts - * import { DateTime, Effect, Layer } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" + * import { Layer } from "effect/services" * * const zone = DateTime.zoneUnsafeMakeNamed("Europe/London") * const layer = DateTime.layerCurrentZone(zone) @@ -2570,7 +2595,8 @@ export const layerCurrentZone = (zone: TimeZone): Layer.Layer = * * @example * ```ts - * import { DateTime, Effect } from "effect" + * import { DateTime } from "effect/time" + * import { Effect } from "effect" * * // Create a layer for UTC+3 * const layer = DateTime.layerCurrentZoneOffset(3 * 60 * 60 * 1000) @@ -2597,7 +2623,8 @@ export const layerCurrentZoneOffset = (offset: number): Layer.Layer { * * @example * ```ts - * import { Duration, Option } from "effect" + * import { Duration } from "effect/time" + * import { Option } from "effect/data" * * const valid = Duration.decodeUnknown(1000) * console.log(Option.isSome(valid)) // true @@ -362,7 +365,7 @@ const make = (input: number | bigint): Duration => { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.isDuration(Duration.seconds(1))) // true * console.log(Duration.isDuration(1000)) // false @@ -378,7 +381,7 @@ export const isDuration = (u: unknown): u is Duration => hasProperty(u, TypeId) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.isFinite(Duration.seconds(5))) // true * console.log(Duration.isFinite(Duration.infinity)) // false @@ -394,7 +397,7 @@ export const isFinite = (self: Duration): boolean => self.value._tag !== "Infini * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.isZero(Duration.zero)) // true * console.log(Duration.isZero(Duration.seconds(1))) // false @@ -422,7 +425,7 @@ export const isZero = (self: Duration): boolean => { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.toMillis(Duration.zero)) // 0 * ``` @@ -437,7 +440,7 @@ export const zero: Duration = make(0) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.toMillis(Duration.infinity)) // Infinity * ``` @@ -452,7 +455,7 @@ export const infinity: Duration = make(Infinity) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const duration = Duration.nanos(BigInt(500_000_000)) * console.log(Duration.toMillis(duration)) // 500 @@ -468,7 +471,7 @@ export const nanos = (nanos: bigint): Duration => make(nanos) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const duration = Duration.micros(BigInt(500_000)) * console.log(Duration.toMillis(duration)) // 500 @@ -484,7 +487,7 @@ export const micros = (micros: bigint): Duration => make(micros * bigint1e3) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const duration = Duration.millis(1000) * console.log(Duration.toMillis(duration)) // 1000 @@ -500,7 +503,7 @@ export const millis = (millis: number): Duration => make(millis) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const duration = Duration.seconds(30) * console.log(Duration.toMillis(duration)) // 30000 @@ -516,7 +519,7 @@ export const seconds = (seconds: number): Duration => make(seconds * 1000) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const duration = Duration.minutes(5) * console.log(Duration.toMillis(duration)) // 300000 @@ -532,7 +535,7 @@ export const minutes = (minutes: number): Duration => make(minutes * 60_000) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const duration = Duration.hours(2) * console.log(Duration.toMillis(duration)) // 7200000 @@ -548,7 +551,7 @@ export const hours = (hours: number): Duration => make(hours * 3_600_000) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const duration = Duration.days(1) * console.log(Duration.toMillis(duration)) // 86400000 @@ -564,7 +567,7 @@ export const days = (days: number): Duration => make(days * 86_400_000) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const duration = Duration.weeks(1) * console.log(Duration.toMillis(duration)) // 604800000 @@ -580,7 +583,7 @@ export const weeks = (weeks: number): Duration => make(weeks * 604_800_000) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.toMillis(Duration.seconds(5))) // 5000 * console.log(Duration.toMillis(Duration.minutes(2))) // 120000 @@ -600,7 +603,7 @@ export const toMillis = (self: DurationInput): number => * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.toSeconds(Duration.millis(5000))) // 5 * console.log(Duration.toSeconds(Duration.minutes(2))) // 120 @@ -620,7 +623,7 @@ export const toSeconds = (self: DurationInput): number => * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.toMinutes(Duration.seconds(120))) // 2 * console.log(Duration.toMinutes(Duration.hours(1))) // 60 @@ -640,7 +643,7 @@ export const toMinutes = (self: DurationInput): number => * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.toHours(Duration.minutes(120))) // 2 * console.log(Duration.toHours(Duration.days(1))) // 24 @@ -660,7 +663,7 @@ export const toHours = (self: DurationInput): number => * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.toDays(Duration.hours(48))) // 2 * console.log(Duration.toDays(Duration.weeks(1))) // 7 @@ -680,7 +683,7 @@ export const toDays = (self: DurationInput): number => * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * console.log(Duration.toWeeks(Duration.days(14))) // 2 * console.log(Duration.toWeeks(Duration.days(7))) // 1 @@ -702,7 +705,8 @@ export const toWeeks = (self: DurationInput): number => * * @example * ```ts - * import { Duration, Option } from "effect" + * import { Duration } from "effect/time" + * import { Option } from "effect/data" * * const duration = Duration.seconds(1) * const nanos = Duration.toNanos(duration) @@ -735,7 +739,7 @@ export const toNanos = (self: DurationInput): Option.Option => { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const duration = Duration.seconds(2) * const nanos = Duration.unsafeToNanos(duration) @@ -769,7 +773,7 @@ export const unsafeToNanos = (self: DurationInput): bigint => { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const duration = Duration.millis(1500) * const hrtime = Duration.toHrTime(duration) @@ -802,7 +806,7 @@ export const toHrTime = (self: DurationInput): [seconds: number, nanos: number] * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const result = Duration.match(Duration.seconds(5), { * onMillis: (millis) => `${millis} milliseconds`, @@ -851,7 +855,7 @@ export const match: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const sum = Duration.matchWith(Duration.seconds(3), Duration.seconds(2), { * onMillis: (a, b) => a + b, @@ -915,7 +919,7 @@ export const matchWith: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const durations = [Duration.seconds(3), Duration.seconds(1), Duration.seconds(2)] * const sorted = durations.sort((a, b) => Duration.Order(a, b)) @@ -937,7 +941,7 @@ export const Order: order.Order = order.make((self, that) => * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const isInRange = Duration.between(Duration.seconds(3), { * minimum: Duration.seconds(2), @@ -965,7 +969,7 @@ export const between: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const isEqual = Duration.Equivalence(Duration.seconds(5), Duration.millis(5000)) * console.log(isEqual) // true @@ -987,7 +991,7 @@ const _min = order.min(Order) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const shorter = Duration.min(Duration.seconds(5), Duration.seconds(3)) * console.log(Duration.toSeconds(shorter)) // 3 @@ -1008,7 +1012,7 @@ const _max = order.max(Order) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const longer = Duration.max(Duration.seconds(5), Duration.seconds(3)) * console.log(Duration.toSeconds(longer)) // 5 @@ -1029,7 +1033,7 @@ const _clamp = order.clamp(Order) * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const clamped = Duration.clamp(Duration.seconds(10), { * minimum: Duration.seconds(2), @@ -1067,7 +1071,8 @@ export const clamp: { * * @example * ```ts - * import { Duration, Option } from "effect" + * import { Duration } from "effect/time" + * import { Option } from "effect/data" * * const half = Duration.divide(Duration.seconds(10), 2) * console.log(Option.map(half, Duration.toSeconds)) // Some(5) @@ -1110,7 +1115,7 @@ export const divide: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const half = Duration.unsafeDivide(Duration.seconds(10), 2) * console.log(Duration.toSeconds(half)) // 5 @@ -1146,7 +1151,7 @@ export const unsafeDivide: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const doubled = Duration.times(Duration.seconds(5), 2) * console.log(Duration.toSeconds(doubled)) // 10 @@ -1172,7 +1177,7 @@ export const times: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const result = Duration.subtract(Duration.seconds(10), Duration.seconds(3)) * console.log(Duration.toSeconds(result)) // 7 @@ -1198,7 +1203,7 @@ export const subtract: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const total = Duration.sum(Duration.seconds(5), Duration.seconds(3)) * console.log(Duration.toSeconds(total)) // 8 @@ -1224,7 +1229,7 @@ export const sum: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const isLess = Duration.lessThan(Duration.seconds(3), Duration.seconds(5)) * console.log(isLess) // true @@ -1250,7 +1255,7 @@ export const lessThan: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const isLessOrEqual = Duration.lessThanOrEqualTo(Duration.seconds(5), Duration.seconds(5)) * console.log(isLessOrEqual) // true @@ -1276,7 +1281,7 @@ export const lessThanOrEqualTo: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const isGreater = Duration.greaterThan(Duration.seconds(5), Duration.seconds(3)) * console.log(isGreater) // true @@ -1302,7 +1307,7 @@ export const greaterThan: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const isGreaterOrEqual = Duration.greaterThanOrEqualTo(Duration.seconds(5), Duration.seconds(5)) * console.log(isGreaterOrEqual) // true @@ -1328,7 +1333,7 @@ export const greaterThanOrEqualTo: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * const isEqual = Duration.equals(Duration.seconds(5), Duration.millis(5000)) * console.log(isEqual) // true @@ -1347,7 +1352,7 @@ export const equals: { * * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * // Create a complex duration by adding multiple parts * const duration = Duration.sum( @@ -1428,7 +1433,7 @@ export const parts = (self: DurationInput): { * @category conversions * @example * ```ts - * import { Duration } from "effect" + * import { Duration } from "effect/time" * * Duration.format(Duration.millis(1000)) // "1s" * Duration.format(Duration.millis(1001)) // "1s 1ms" diff --git a/packages/effect/src/time/index.ts b/packages/effect/src/time/index.ts new file mode 100644 index 0000000000..1967ad85c4 --- /dev/null +++ b/packages/effect/src/time/index.ts @@ -0,0 +1,124 @@ +/** + * @since 4.0.0 + */ + +/** + * The `Clock` module provides functionality for time-based operations in Effect applications. + * It offers precise time measurements, scheduling capabilities, and controlled time management + * for testing scenarios. + * + * The Clock service is a core component of the Effect runtime, providing: + * - Current time access in milliseconds and nanoseconds + * - Sleep operations for delaying execution + * - Time-based scheduling primitives + * - Testable time control through `TestClock` + * + * ## Key Features + * + * - **Precise timing**: Access to both millisecond and nanosecond precision + * - **Sleep operations**: Non-blocking sleep with proper interruption handling + * - **Service integration**: Seamless integration with Effect's dependency injection + * - **Testable**: Mock time control for deterministic testing + * - **Resource-safe**: Automatic cleanup of time-based resources + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Clock } from "effect/time" + * + * // Get current time in milliseconds + * const getCurrentTime = Clock.currentTimeMillis + * + * // Sleep for 1 second + * const sleep1Second = Effect.sleep("1 seconds") + * + * // Measure execution time + * const measureTime = Effect.gen(function* () { + * const start = yield* Clock.currentTimeMillis + * yield* Effect.sleep("100 millis") + * const end = yield* Clock.currentTimeMillis + * return end - start + * }) + * ``` + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Clock } from "effect/time" + * + * // Using Clock service directly + * const program = Effect.gen(function* () { + * const clock = yield* Clock.Clock + * const currentTime = yield* clock.currentTimeMillis + * console.log(`Current time: ${currentTime}`) + * + * // Sleep for 500ms + * yield* Effect.sleep("500 millis") + * + * const afterSleep = yield* clock.currentTimeMillis + * console.log(`After sleep: ${afterSleep}`) + * }) + * ``` + * + * @since 2.0.0 + */ +export * as Clock from "./Clock.ts" + +/** + * @since 2.0.0 + */ +export * as Cron from "./Cron.ts" + +/** + * @since 3.6.0 + */ +export * as DateTime from "./DateTime.ts" + +/** + * This module provides utilities for working with durations of time. A `Duration` + * is an immutable data type that represents a span of time with high precision, + * supporting operations from nanoseconds to weeks. + * + * Durations support: + * - **High precision**: Nanosecond-level accuracy using BigInt + * - **Multiple formats**: Numbers (millis), BigInt (nanos), tuples, strings + * - **Arithmetic operations**: Add, subtract, multiply, divide + * - **Comparisons**: Equal, less than, greater than + * - **Conversions**: Between different time units + * - **Human-readable formatting**: Pretty printing and parsing + * + * @example + * ```ts + * import { Effect } from "effect" + * import { Duration } from "effect/time" + * + * // Creating durations + * const oneSecond = Duration.seconds(1) + * const fiveMinutes = Duration.minutes(5) + * const oneHour = Duration.decode("1 hour") + * const precise = Duration.nanos(BigInt(123456789)) + * + * // Arithmetic operations + * const total = Duration.sum(Duration.sum(oneSecond, fiveMinutes), oneHour) + * const double = Duration.times(oneSecond, 2) + * const half = Duration.divide(oneSecond, 2) + * + * // Comparisons + * const isLonger = Duration.greaterThan(fiveMinutes, oneSecond) // true + * const isEqual = Duration.equals(oneSecond, Duration.millis(1000)) // true + * + * // Converting and formatting + * console.log(Duration.toMillis(oneSecond)) // 1000 + * console.log(Duration.format(fiveMinutes)) // "5m" + * + * // Using with Effects + * const program = Effect.gen(function* () { + * console.log("Starting...") + * yield* Effect.sleep(Duration.seconds(2)) + * console.log("Done!") + * }) + * ``` + * + * @since 2.0.0 + */ +export * as Duration from "./Duration.ts" diff --git a/packages/effect/src/time/index.ts.tpl b/packages/effect/src/time/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/time/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/TxChunk.ts b/packages/effect/src/transactions/TxChunk.ts similarity index 87% rename from packages/effect/src/TxChunk.ts rename to packages/effect/src/transactions/TxChunk.ts index 15d96dabda..208baa2c00 100644 --- a/packages/effect/src/TxChunk.ts +++ b/packages/effect/src/transactions/TxChunk.ts @@ -9,22 +9,22 @@ * * @since 4.0.0 */ -import * as Chunk from "./Chunk.ts" -import * as Effect from "./Effect.ts" -import { dual } from "./Function.ts" -import type { Inspectable } from "./Inspectable.ts" -import { format, NodeInspectSymbol, toJSON } from "./Inspectable.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" -import * as TxRef from "./TxRef.ts" -import type { NoInfer } from "./Types.ts" +import * as Chunk from "../collections/Chunk.ts" +import * as Effect from "../Effect.ts" +import { dual } from "../Function.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import { format, NodeInspectSymbol, toJSON } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import * as TxRef from "../transactions/TxRef.ts" +import type { NoInfer } from "../types/Types.ts" /** * Unique identifier for TxChunk instances. * * @example * ```ts - * import { TxChunk } from "effect" + * import { TxChunk } from "effect/transactions" * * // Access the TypeId for runtime type checking * declare const txChunk: TxChunk.TxChunk @@ -41,7 +41,7 @@ export const TypeId: TypeId = "~effect/TxChunk" * * @example * ```ts - * import { TxChunk } from "effect" + * import { TxChunk } from "effect/transactions" * * // Use TypeId for type guards * const isTxChunk = (value: unknown): value is TxChunk.TxChunk => { @@ -64,7 +64,9 @@ export type TypeId = "~effect/TxChunk" * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a transactional chunk @@ -124,7 +126,9 @@ const TxChunkProto = { * @category Constructors * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a TxChunk with initial values @@ -150,7 +154,8 @@ export const make = (initial: Chunk.Chunk): Effect.Effect> => * @category Constructors * @example * ```ts - * import { Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create an empty TxChunk @@ -181,7 +186,9 @@ export const empty = (): Effect.Effect> => * @category Constructors * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create TxChunk from array @@ -215,7 +222,8 @@ export const fromIterable = (iterable: Iterable): Effect.Effect * * @example * ```ts - * import { Chunk, TxChunk, TxRef } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk, TxRef } from "effect/transactions" * * // Create a TxChunk from an existing TxRef (advanced usage) * const ref = TxRef.unsafeMake(Chunk.fromIterable([1, 2, 3])) @@ -245,7 +253,9 @@ export const unsafeMake = (ref: TxRef.TxRef>): TxChunk => { * @category Combinators * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3]) @@ -287,7 +297,9 @@ export const modify: { * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3]) @@ -318,7 +330,9 @@ export const update: { * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3]) @@ -346,7 +360,9 @@ export const get = (self: TxChunk): Effect.Effect> => TxRef * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3]) @@ -376,7 +392,9 @@ export const set: { * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3]) @@ -408,7 +426,9 @@ export const append: { * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([2, 3, 4]) @@ -437,7 +457,8 @@ export const prepend: { * * @example * ```ts - * import { Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3, 4, 5]) @@ -464,7 +485,8 @@ export const size = (self: TxChunk): Effect.Effect => * * @example * ```ts - * import { Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const emptyChunk = yield* TxChunk.empty() @@ -490,7 +512,8 @@ export const isEmpty = (self: TxChunk): Effect.Effect => * * @example * ```ts - * import { Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const emptyChunk = yield* TxChunk.empty() @@ -519,7 +542,9 @@ export const isNonEmpty = (self: TxChunk): Effect.Effect => * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3, 4, 5]) @@ -548,7 +573,9 @@ export const take: { * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3, 4, 5]) @@ -577,7 +604,9 @@ export const drop: { * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3, 4, 5, 6, 7]) @@ -611,7 +640,9 @@ export const slice: { * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3, 4]) @@ -644,7 +675,9 @@ export const map: { * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3, 4, 5, 6]) @@ -680,7 +713,9 @@ export const filter: { * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([1, 2, 3]) @@ -715,7 +750,9 @@ export const appendAll: { * * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk = yield* TxChunk.fromIterable([4, 5, 6]) @@ -752,7 +789,9 @@ export const prependAll: { * @category Combinators * @example * ```ts - * import { Chunk, Effect, TxChunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxChunk } from "effect/transactions" * * const program = Effect.gen(function* () { * const txChunk1 = yield* TxChunk.fromIterable([1, 2, 3]) diff --git a/packages/effect/src/TxHashMap.ts b/packages/effect/src/transactions/TxHashMap.ts similarity index 92% rename from packages/effect/src/TxHashMap.ts rename to packages/effect/src/transactions/TxHashMap.ts index a1b63ed1d3..842b5b0981 100644 --- a/packages/effect/src/TxHashMap.ts +++ b/packages/effect/src/transactions/TxHashMap.ts @@ -2,22 +2,22 @@ * @since 2.0.0 */ -import * as Effect from "./Effect.ts" -import { dual } from "./Function.ts" -import * as HashMap from "./HashMap.ts" -import type { Inspectable } from "./Inspectable.ts" -import { format, NodeInspectSymbol, toJSON } from "./Inspectable.ts" -import * as Option from "./Option.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" -import * as TxRef from "./TxRef.ts" +import * as HashMap from "../collections/HashMap.ts" +import * as Option from "../data/Option.ts" +import * as Effect from "../Effect.ts" +import { dual } from "../Function.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import { format, NodeInspectSymbol, toJSON } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import * as TxRef from "../transactions/TxRef.ts" /** * Unique identifier for TxHashMap instances. * * @example * ```ts - * import { TxHashMap } from "effect" + * import { TxHashMap } from "effect/transactions" * * // The TypeId constant can be used for runtime identification * console.log(TxHashMap.TypeId) // "~effect/TxHashMap" @@ -38,7 +38,8 @@ export const TypeId: "~effect/TxHashMap" = "~effect/TxHashMap" as const * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * // Use TypeId for type guards in runtime checks * const validateTxHashMap = (value: unknown): value is TxHashMap.TxHashMap => { @@ -82,7 +83,9 @@ const TxHashMapProto = { * * @example * ```ts - * import { TxHashMap, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a transactional hash map @@ -123,7 +126,9 @@ export interface TxHashMap extends Inspectable, Pipeable { * * @example * ```ts - * import { TxHashMap, HashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { HashMap } from "effect/collections" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a transactional inventory map @@ -154,7 +159,8 @@ export declare namespace TxHashMap { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a user map to extract key type from @@ -182,7 +188,8 @@ export declare namespace TxHashMap { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a product catalog TxHashMap @@ -214,7 +221,8 @@ export declare namespace TxHashMap { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a configuration TxHashMap @@ -250,7 +258,8 @@ export declare namespace TxHashMap { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create an empty transactional hash map @@ -284,7 +293,9 @@ export const empty = (): Effect.Effect> => * * @example * ```ts - * import { TxHashMap, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a user directory @@ -322,7 +333,8 @@ export const make = (...entries: Array): Effect.Effect(entries: Iterable): Effect.E * * @example * ```ts - * import { TxHashMap, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const userMap = yield* TxHashMap.make( @@ -409,7 +423,9 @@ export const get: { * * @example * ```ts - * import { TxHashMap, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const inventory = yield* TxHashMap.make( @@ -449,7 +465,8 @@ export const set: { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const permissions = yield* TxHashMap.make( @@ -494,7 +511,8 @@ export const has: { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const cache = yield* TxHashMap.make( @@ -549,7 +567,8 @@ export const remove: { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const sessionMap = yield* TxHashMap.make( @@ -584,7 +603,8 @@ export const clear = (self: TxHashMap): Effect.Effect => TxRef * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const metrics = yield* TxHashMap.make( @@ -622,7 +642,8 @@ export const size = (self: TxHashMap): Effect.Effect => * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Start with empty map @@ -656,7 +677,8 @@ export const isEmpty = (self: TxHashMap): Effect.Effect => * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const inventory = yield* TxHashMap.make(["laptop", 5]) @@ -685,7 +707,9 @@ export const isNonEmpty = (self: TxHashMap): Effect.Effect * * @example * ```ts - * import { TxHashMap, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const counters = yield* TxHashMap.make( @@ -741,7 +765,9 @@ export const modify: { * * @example * ```ts - * import { TxHashMap, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const storage = yield* TxHashMap.make(["file1.txt", "content1"], ["access_count", 0]) @@ -798,7 +824,9 @@ export const modifyAt: { * * @example * ```ts - * import { TxHashMap, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const userRoles = yield* TxHashMap.make( @@ -834,7 +862,8 @@ export const keys = (self: TxHashMap): Effect.Effect> => * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const scores = yield* TxHashMap.make( @@ -870,7 +899,8 @@ export const values = (self: TxHashMap): Effect.Effect> => * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const config = yield* TxHashMap.make( @@ -907,7 +937,9 @@ export const entries = (self: TxHashMap): Effect.Effect(self: TxHashMap): Effect.Effect(value: unknown): value is TxHashMap => { * * @example * ```ts - * import { TxHashMap, Hash, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" + * import { Hash } from "effect/interfaces" * * const program = Effect.gen(function* () { * // Create a cache with user sessions @@ -1188,7 +1228,9 @@ export const getHash: { * * @example * ```ts - * import { TxHashMap, Hash, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" + * import { Hash } from "effect/interfaces" * * const program = Effect.gen(function* () { * // Create an access control map @@ -1240,7 +1282,8 @@ export const hasHash: { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a user profile map @@ -1299,7 +1342,8 @@ export const map: { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a product inventory @@ -1366,7 +1410,8 @@ export const filter: { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a sales data map @@ -1432,7 +1477,9 @@ export const reduce: { * * @example * ```ts - * import { TxHashMap, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a mixed data map @@ -1496,7 +1543,8 @@ export const filterMap: { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a user status map @@ -1546,7 +1594,9 @@ export const hasBy: { * * @example * ```ts - * import { TxHashMap, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a task priority map @@ -1596,7 +1646,8 @@ export const findFirst: { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a product inventory @@ -1645,7 +1696,8 @@ export const some: { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a user permissions map @@ -1695,7 +1747,9 @@ export const every: { * * @example * ```ts - * import { TxHashMap, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a log processing map @@ -1751,7 +1805,8 @@ export const forEach: { * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a department-employee map @@ -1829,7 +1884,9 @@ export const flatMap: { * * @example * ```ts - * import { TxHashMap, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a map with optional user data @@ -1878,7 +1935,8 @@ export const compact = (self: TxHashMap>): Effect.Effe * * @example * ```ts - * import { TxHashMap, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashMap } from "effect/transactions" * * const program = Effect.gen(function* () { * const settings = yield* TxHashMap.make( @@ -1914,7 +1972,8 @@ export const toEntries = (self: TxHashMap): Effect.Effect(value: unknown): value is TxHashSet.TxHashSet => { @@ -95,7 +96,8 @@ const TxHashSetProto = { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a transactional hash set @@ -136,7 +138,9 @@ export interface TxHashSet extends Inspectable, Pipeable { * * @example * ```ts - * import { TxHashSet, HashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { HashSet } from "effect/collections/HashSet" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a transactional color set @@ -160,7 +164,7 @@ export declare namespace TxHashSet { /** * @example * ```ts - * import { TxHashSet } from "effect" + * import { TxHashSet } from "effect/transactions" * * const fruits = TxHashSet.make("apple", "banana", "cherry") * @@ -189,7 +193,8 @@ const makeTxHashSet = (ref: TxRef.TxRef>): TxHashSet => * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const txSet = yield* TxHashSet.empty() @@ -218,7 +223,8 @@ export const empty = (): Effect.Effect> => * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const fruits = yield* TxHashSet.make("apple", "banana", "cherry") @@ -249,7 +255,8 @@ export const make = >( * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const fromArray = yield* TxHashSet.fromIterable(["a", "b", "c", "b", "a"]) @@ -279,7 +286,9 @@ export const fromIterable = (values: Iterable): Effect.Effect * * @example * ```ts - * import { TxHashSet, HashSet, Effect } from "effect" + * import { Effect } from "effect" + * import * as HashSet from "effect/collections/HashSet" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const hashSet = HashSet.make("x", "y", "z") @@ -309,7 +318,9 @@ export const fromHashSet = (hashSet: HashSet.HashSet): Effect.Effect => typeof u === * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const txSet = yield* TxHashSet.make("a", "b") @@ -370,7 +382,8 @@ export const add: { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const txSet = yield* TxHashSet.make("a", "b", "c") @@ -412,7 +425,9 @@ export const remove: { * * @example * ```ts - * import { TxHashSet, Effect, Equal, Hash } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" + * import { Equal, Hash } from "effect/interfaces" * * const program = Effect.gen(function* () { * const txSet = yield* TxHashSet.make("apple", "banana", "cherry") @@ -458,7 +473,8 @@ export const has: { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const empty = yield* TxHashSet.empty() @@ -486,7 +502,8 @@ export const size = (self: TxHashSet): Effect.Effect => * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const empty = yield* TxHashSet.empty() @@ -514,7 +531,8 @@ export const isEmpty = (self: TxHashSet): Effect.Effect => * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const txSet = yield* TxHashSet.make("a", "b", "c") @@ -536,7 +554,8 @@ export const clear = (self: TxHashSet): Effect.Effect => TxRef.set(s * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const set1 = yield* TxHashSet.make("a", "b") @@ -573,7 +592,8 @@ export const union: { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const set1 = yield* TxHashSet.make("a", "b", "c") @@ -610,7 +630,8 @@ export const intersection: { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const set1 = yield* TxHashSet.make("a", "b", "c") @@ -647,7 +668,8 @@ export const difference: { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const small = yield* TxHashSet.make("a", "b") @@ -684,7 +706,8 @@ export const isSubset: { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const numbers = yield* TxHashSet.make(1, 2, 3, 4, 5) @@ -717,7 +740,8 @@ export const some: { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const numbers = yield* TxHashSet.make(2, 4, 6, 8) @@ -750,7 +774,8 @@ export const every: { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const numbers = yield* TxHashSet.make(1, 2, 3) @@ -791,7 +816,8 @@ export const map: { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const numbers = yield* TxHashSet.make(1, 2, 3, 4, 5, 6) @@ -834,7 +860,8 @@ export const filter: { * * @example * ```ts - * import { TxHashSet, Effect } from "effect" + * import { Effect } from "effect" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const numbers = yield* TxHashSet.make(1, 2, 3, 4, 5) @@ -868,7 +895,9 @@ export const reduce: { * * @example * ```ts - * import { TxHashSet, HashSet, Effect } from "effect" + * import { Effect } from "effect" + * import * as HashSet from "effect/collections/HashSet" + * import { TxHashSet } from "effect/transactions" * * const program = Effect.gen(function* () { * const txSet = yield* TxHashSet.make("x", "y", "z") diff --git a/packages/effect/src/TxQueue.ts b/packages/effect/src/transactions/TxQueue.ts similarity index 91% rename from packages/effect/src/TxQueue.ts rename to packages/effect/src/transactions/TxQueue.ts index 8007e968bc..53e5199779 100644 --- a/packages/effect/src/TxQueue.ts +++ b/packages/effect/src/transactions/TxQueue.ts @@ -9,17 +9,17 @@ * * @since 4.0.0 */ -import * as Cause from "./Cause.ts" -import * as Chunk from "./Chunk.ts" -import * as Effect from "./Effect.ts" -import { dual } from "./Function.ts" -import type { Inspectable } from "./Inspectable.ts" -import { format, NodeInspectSymbol, toJSON } from "./Inspectable.ts" -import * as Option from "./Option.ts" -import { hasProperty } from "./Predicate.ts" -import * as TxChunk from "./TxChunk.ts" -import * as TxRef from "./TxRef.ts" -import type * as Types from "./Types.ts" +import * as Cause from "../Cause.ts" +import * as Chunk from "../collections/Chunk.ts" +import * as Option from "../data/Option.ts" +import { hasProperty } from "../data/Predicate.ts" +import * as Effect from "../Effect.ts" +import { dual } from "../Function.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import { format, NodeInspectSymbol, toJSON } from "../interfaces/Inspectable.ts" +import * as TxChunk from "../transactions/TxChunk.ts" +import * as TxRef from "../transactions/TxRef.ts" +import type * as Types from "../types/Types.ts" /** * Represents the state of a transactional queue with sophisticated lifecycle management. @@ -31,7 +31,8 @@ import type * as Types from "./Types.ts" * * @example * ```ts - * import { TxQueue, Cause } from "effect" + * import { Cause } from "effect" + * import { TxQueue } from "effect/transactions" * * // State progression example * declare const state: TxQueue.State @@ -66,7 +67,7 @@ export type State<_A, E> = * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Access the EnqueueTypeId for runtime type checking * declare const enqueue: TxQueue.TxEnqueue @@ -83,7 +84,7 @@ export const EnqueueTypeId: EnqueueTypeId = "~effect/TxQueue/Enqueue" * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Use the type for branded interfaces * declare const enqueueId: TxQueue.EnqueueTypeId @@ -100,7 +101,7 @@ export type EnqueueTypeId = "~effect/TxQueue/Enqueue" * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Access the DequeueTypeId for runtime type checking * declare const dequeue: TxQueue.TxDequeue @@ -117,7 +118,7 @@ export const DequeueTypeId: DequeueTypeId = "~effect/TxQueue/Dequeue" * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Use the type for branded interfaces * declare const dequeueId: TxQueue.DequeueTypeId @@ -134,7 +135,7 @@ export type DequeueTypeId = "~effect/TxQueue/Dequeue" * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Access the TypeId for runtime type checking * declare const queue: TxQueue.TxQueue @@ -151,7 +152,7 @@ export const TypeId: TypeId = "~effect/TxQueue" * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Use the type for branded interfaces * declare const queueId: TxQueue.TypeId @@ -168,7 +169,7 @@ export type TypeId = "~effect/TxQueue" * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Use variance types for type-level operations * declare const variance: TxQueue.TxEnqueue.Variance @@ -183,7 +184,7 @@ export declare namespace TxEnqueue { * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Demonstrates contravariant type behavior for both A and E * declare const variance: TxQueue.TxEnqueue.Variance @@ -203,7 +204,7 @@ export declare namespace TxEnqueue { * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Use variance types for type-level operations * declare const variance: TxQueue.TxDequeue.Variance @@ -218,7 +219,7 @@ export declare namespace TxDequeue { * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Demonstrates covariant type behavior for both A and E * declare const variance: TxQueue.TxDequeue.Variance @@ -238,7 +239,7 @@ export declare namespace TxDequeue { * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Use variance types for type-level operations * declare const variance: TxQueue.TxQueue.Variance @@ -253,7 +254,7 @@ export declare namespace TxQueue { * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * // Demonstrates invariant type behavior for both A and E * declare const variance: TxQueue.TxQueue.Variance @@ -289,7 +290,8 @@ export interface TxQueueState extends Inspectable { * * @example * ```ts - * import { TxQueue, Effect, Cause } from "effect" + * import { Effect, Cause } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * // Queue without error channel @@ -321,7 +323,8 @@ export interface TxEnqueue extends TxQueueState { * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * // Queue without error channel @@ -352,7 +355,8 @@ export interface TxDequeue extends TxQueueState { * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a bounded transactional queue (E defaults to never) @@ -384,7 +388,7 @@ export interface TxQueue extends TxEnqueue, Tx * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * declare const someValue: unknown * @@ -404,7 +408,7 @@ export const isTxEnqueue = (u: unknown): u is TxEnqueu * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * declare const someValue: unknown * @@ -424,7 +428,7 @@ export const isTxDequeue = (u: unknown): u is TxDequeu * * @example * ```ts - * import { TxQueue } from "effect" + * import { TxQueue } from "effect/transactions" * * declare const someValue: unknown * @@ -474,7 +478,8 @@ const TxQueueProto = { * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a bounded queue (E defaults to never) @@ -516,7 +521,8 @@ export const bounded = (capacity: number): Effect.Effect(): Effect.Effect> * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a dropping queue with capacity 2 @@ -598,7 +605,8 @@ export const dropping = (capacity: number): Effect.Effect< * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a sliding queue with capacity 2 @@ -644,7 +652,8 @@ export const sliding = (capacity: number): Effect.Effect(10) @@ -707,7 +716,9 @@ export const offer: { * * @example * ```ts - * import { TxQueue, Effect, Chunk } from "effect" + * import { Effect } from "effect" + * import { Chunk } from "effect/collections" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -751,7 +762,8 @@ export const offerAll: { * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -809,7 +821,9 @@ export const take = (self: TxDequeue): Effect.Effect => * * @example * ```ts - * import { TxQueue, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -857,7 +871,8 @@ export const poll = (self: TxDequeue): Effect.Effect(10) @@ -930,7 +945,8 @@ export const takeAll = (self: TxDequeue): Effect.Effect(5) @@ -1016,7 +1032,8 @@ export const takeN: { * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1102,7 +1119,8 @@ export const takeBetween: { * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1154,7 +1172,8 @@ export const peek = (self: TxDequeue): Effect.Effect => * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1175,7 +1194,8 @@ export const size = (self: TxQueueState): Effect.Effect => TxChunk.size( * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1199,7 +1219,8 @@ export const isEmpty = (self: TxQueueState): Effect.Effect => TxChunk.i * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(2) @@ -1233,7 +1254,8 @@ export const isFull = (self: TxQueueState): Effect.Effect => * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1259,7 +1281,8 @@ export const interrupt = (self: TxEnqueue): Effect.Effect = * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1301,7 +1324,8 @@ export const fail: { * * @example * ```ts - * import { TxQueue, Effect, Cause } from "effect" + * import { Effect, Cause } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1351,7 +1375,8 @@ export const failCause: { * * @example * ```ts - * import { TxQueue, Effect, Cause } from "effect" + * import { Effect, Cause } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1385,7 +1410,8 @@ export const end = (self: TxEnqueue): Eff * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1417,7 +1443,8 @@ export const clear = (self: TxEnqueue): Effect.Effect => TxChu * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1452,7 +1479,8 @@ export const shutdown = (self: TxEnqueue): Effect.Effect => * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1480,7 +1508,8 @@ export const isOpen = (self: TxQueueState): Effect.Effect => * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1509,7 +1538,8 @@ export const isClosing = (self: TxQueueState): Effect.Effect => * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1537,7 +1567,8 @@ export const isDone = (self: TxQueueState): Effect.Effect => * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) @@ -1561,7 +1592,8 @@ export const isShutdown = (self: TxQueueState): Effect.Effect => isDone * * @example * ```ts - * import { TxQueue, Effect } from "effect" + * import { Effect } from "effect" + * import { TxQueue } from "effect/transactions" * * const program = Effect.gen(function* () { * const queue = yield* TxQueue.bounded(10) diff --git a/packages/effect/src/TxRef.ts b/packages/effect/src/transactions/TxRef.ts similarity index 89% rename from packages/effect/src/TxRef.ts rename to packages/effect/src/transactions/TxRef.ts index 246c98e678..d8b13adb70 100644 --- a/packages/effect/src/TxRef.ts +++ b/packages/effect/src/transactions/TxRef.ts @@ -8,16 +8,16 @@ * * @since 4.0.0 */ -import * as Effect from "./Effect.ts" -import { dual } from "./Function.ts" -import type { NoInfer } from "./Types.ts" +import * as Effect from "../Effect.ts" +import { dual } from "../Function.ts" +import type { NoInfer } from "../types/Types.ts" /** * @since 4.0.0 * @category Symbols * @example * ```ts - * import { TxRef } from "effect" + * import { TxRef } from "effect/transactions" * * declare const ref: TxRef.TxRef * @@ -32,7 +32,7 @@ export const TypeId: TypeId = "~effect/TxRef" * @category Symbols * @example * ```ts - * import { TxRef } from "effect" + * import { TxRef } from "effect/transactions" * * // Use TypeId for type guards or branding * const checkTxRef = (value: unknown): value is TxRef.TxRef => { @@ -54,7 +54,8 @@ export type TypeId = "~effect/TxRef" * @category Models * @example * ```ts - * import { Effect, TxRef } from "effect" + * import { Effect } from "effect" + * import { TxRef } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a transactional reference @@ -86,7 +87,8 @@ export interface TxRef { * @category Constructors * @example * ```ts - * import { Effect, TxRef } from "effect" + * import { Effect } from "effect" + * import { TxRef } from "effect/transactions" * * const program = Effect.gen(function* () { * // Create a transactional reference with initial value @@ -113,7 +115,7 @@ export const make = (initial: A) => Effect.sync(() => unsafeMake(initial)) * @category Constructors * @example * ```ts - * import { TxRef } from "effect" + * import { TxRef } from "effect/transactions" * * // Create a TxRef synchronously (unsafe - use make instead in Effect contexts) * const counter = TxRef.unsafeMake(0) @@ -138,7 +140,8 @@ export const unsafeMake = (initial: A): TxRef => ({ * @category Combinators * @example * ```ts - * import { Effect, TxRef } from "effect" + * import { Effect } from "effect" + * import { TxRef } from "effect/transactions" * * const program = Effect.gen(function* () { * const counter = yield* TxRef.make(0) @@ -179,7 +182,8 @@ export const modify: { * @category Combinators * @example * ```ts - * import { Effect, TxRef } from "effect" + * import { Effect } from "effect" + * import { TxRef } from "effect/transactions" * * const program = Effect.gen(function* () { * const counter = yield* TxRef.make(10) @@ -208,7 +212,8 @@ export const update: { * @category Combinators * @example * ```ts - * import { Effect, TxRef } from "effect" + * import { Effect } from "effect" + * import { TxRef } from "effect/transactions" * * const program = Effect.gen(function* () { * const counter = yield* TxRef.make(42) @@ -231,7 +236,8 @@ export const get = (self: TxRef): Effect.Effect => modify(self, (curren * @category Combinators * @example * ```ts - * import { Effect, TxRef } from "effect" + * import { Effect } from "effect" + * import { TxRef } from "effect/transactions" * * const program = Effect.gen(function* () { * const counter = yield* TxRef.make(0) diff --git a/packages/effect/src/TxSemaphore.ts b/packages/effect/src/transactions/TxSemaphore.ts similarity index 88% rename from packages/effect/src/TxSemaphore.ts rename to packages/effect/src/transactions/TxSemaphore.ts index 19601fd65a..7fb2395e55 100644 --- a/packages/effect/src/TxSemaphore.ts +++ b/packages/effect/src/transactions/TxSemaphore.ts @@ -2,20 +2,20 @@ * @since 4.0.0 */ -import * as Effect from "./Effect.ts" -import type { Inspectable } from "./Inspectable.ts" -import { NodeInspectSymbol, toJSON } from "./Inspectable.ts" -import type { Pipeable } from "./Pipeable.ts" -import { pipeArguments } from "./Pipeable.ts" -import type * as Scope from "./Scope.ts" -import * as TxRef from "./TxRef.ts" +import * as Effect from "../Effect.ts" +import type { Inspectable } from "../interfaces/Inspectable.ts" +import { NodeInspectSymbol, toJSON } from "../interfaces/Inspectable.ts" +import type { Pipeable } from "../interfaces/Pipeable.ts" +import { pipeArguments } from "../interfaces/Pipeable.ts" +import type * as Scope from "../resources/Scope.ts" +import * as TxRef from "../transactions/TxRef.ts" /** * Unique identifier for TxSemaphore instances. * * @example * ```ts - * import { TxSemaphore } from "effect" + * import { TxSemaphore } from "effect/transactions" * * // The TypeId constant can be used for runtime identification * console.log(TxSemaphore.TypeId) // "~effect/TxSemaphore" @@ -47,7 +47,8 @@ export type TypeId = typeof TypeId * * @example * ```ts - * import { TxSemaphore, Effect } from "effect" + * import { Effect } from "effect" + * import { TxSemaphore } from "effect/transactions" * * // Create a semaphore with 3 permits for managing concurrent database connections * const program = Effect.gen(function* () { @@ -102,7 +103,9 @@ const makeTxSemaphore = (permitsRef: TxRef.TxRef, capacity: number): TxS * * @example * ```ts - * import { TxSemaphore, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" * * // Create a semaphore for managing concurrent access to a resource pool * const program = Effect.gen(function* () { @@ -140,7 +143,9 @@ export const make = (permits: number): Effect.Effect => * * @example * ```ts - * import { TxSemaphore, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" * * const program = Effect.gen(function* () { * const semaphore = yield* TxSemaphore.make(5) @@ -172,7 +177,9 @@ export const available = (self: TxSemaphore): Effect.Effect => TxRef.get * * @example * ```ts - * import { TxSemaphore, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" * * const program = Effect.gen(function* () { * const semaphore = yield* TxSemaphore.make(10) @@ -201,7 +208,9 @@ export const capacity = (self: TxSemaphore): Effect.Effect => Effect.suc * * @example * ```ts - * import { TxSemaphore, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" * * const program = Effect.gen(function* () { * const semaphore = yield* TxSemaphore.make(2) @@ -242,7 +251,9 @@ export const acquire = (self: TxSemaphore): Effect.Effect => * * @example * ```ts - * import { TxSemaphore, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" * * const program = Effect.gen(function* () { * const semaphore = yield* TxSemaphore.make(5) @@ -284,7 +295,9 @@ export const acquireN = (self: TxSemaphore, n: number): Effect.Effect => { * * @example * ```ts - * import { TxSemaphore, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" * * const program = Effect.gen(function* () { * const semaphore = yield* TxSemaphore.make(1) @@ -319,7 +332,9 @@ export const tryAcquire = (self: TxSemaphore): Effect.Effect => * * @example * ```ts - * import { TxSemaphore, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" * * const program = Effect.gen(function* () { * const semaphore = yield* TxSemaphore.make(3) @@ -358,7 +373,9 @@ export const tryAcquireN = (self: TxSemaphore, n: number): Effect.Effect => * * @example * ```ts - * import { TxSemaphore, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" * * const program = Effect.gen(function* () { * const semaphore = yield* TxSemaphore.make(5) @@ -433,7 +452,9 @@ export const releaseN = (self: TxSemaphore, n: number): Effect.Effect => { * * @example * ```ts - * import { TxSemaphore, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" * * const program = Effect.gen(function* () { * const semaphore = yield* TxSemaphore.make(2) @@ -480,7 +501,9 @@ export const withPermit = ( * * @example * ```ts - * import { TxSemaphore, Effect, Console } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" * * const program = Effect.gen(function* () { * const semaphore = yield* TxSemaphore.make(5) @@ -528,7 +551,10 @@ export const withPermits = ( * * @example * ```ts - * import { TxSemaphore, Effect, Console, Scope } from "effect" + * import { Effect } from "effect" + * import { Console } from "effect/logging" + * import { TxSemaphore } from "effect/transactions" + * import { Scope } from "effect/resources" * * const program = Effect.gen(function* () { * const semaphore = yield* TxSemaphore.make(3) @@ -568,7 +594,8 @@ export const withPermitScoped = (self: TxSemaphore): Effect.Effect>` internally to ensure all operations + * are performed atomically within transactions. + * + * Accessed values are tracked by the transaction in order to detect conflicts and to track changes. + * A transaction will retry whenever a conflict is detected or whenever the transaction explicitly + * calls `Effect.retryTransaction` and any of the accessed TxChunk values change. + * + * @since 4.0.0 + */ +export * as TxChunk from "./TxChunk.ts" + +/** + * @since 2.0.0 + */ +export * as TxHashMap from "./TxHashMap.ts" + +/** + * @since 2.0.0 + */ +export * as TxHashSet from "./TxHashSet.ts" + +/** + * TxQueue is a transactional queue data structure that provides Software Transactional Memory (STM) + * semantics for queue operations. It uses TxRef for transactional state management and supports + * multiple queue strategies: bounded, unbounded, dropping, and sliding. + * + * Accessed values are tracked by the transaction in order to detect conflicts and to track changes. + * A transaction will retry whenever a conflict is detected or whenever the transaction explicitly + * calls `Effect.retryTransaction` and any of the accessed TxQueue values change. + * + * @since 4.0.0 + */ +export * as TxQueue from "./TxQueue.ts" + +/** + * TxRef is a transactional value, it can be read and modified within the body of a transaction. + * + * Accessed values are tracked by the transaction in order to detect conflicts and in order to + * track changes, a transaction will retry whenever a conflict is detected or whenever the + * transaction explicitely calls to `Effect.retryTransaction` and any of the accessed TxRef values + * change. + * + * @since 4.0.0 + */ +export * as TxRef from "./TxRef.ts" + +/** + * @since 4.0.0 + */ +export * as TxSemaphore from "./TxSemaphore.ts" diff --git a/packages/effect/src/transactions/index.ts.tpl b/packages/effect/src/transactions/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/transactions/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/HKT.ts b/packages/effect/src/types/HKT.ts similarity index 94% rename from packages/effect/src/HKT.ts rename to packages/effect/src/types/HKT.ts index 0676ce311f..0430880f99 100644 --- a/packages/effect/src/HKT.ts +++ b/packages/effect/src/types/HKT.ts @@ -12,7 +12,7 @@ * * @example * ```ts - * import { HKT } from "effect" + * import { HKT } from "effect/types" * * // Define a TypeLambda for Array * interface ArrayTypeLambda extends HKT.TypeLambda { @@ -31,7 +31,7 @@ * * @since 2.0.0 */ -import type * as Types from "./Types.ts" +import type * as Types from "../types/Types.ts" /** * A unique symbol used to identify TypeClass implementations. @@ -42,7 +42,7 @@ import type * as Types from "./Types.ts" * * @example * ```ts - * import { HKT } from "effect" + * import { HKT } from "effect/types" * * interface MyTypeClass extends HKT.TypeClass { * // TypeClass methods here @@ -66,7 +66,7 @@ export declare const URI: unique symbol * * @example * ```ts - * import { HKT } from "effect" + * import { HKT } from "effect/types" * * // Define a Functor type class * interface Functor extends HKT.TypeClass { @@ -107,7 +107,8 @@ export interface TypeClass { * * @example * ```ts - * import { HKT, Effect } from "effect" + * import { Effect } from "effect" + * import { HKT } from "effect/types" * * // TypeLambda for Array * interface ArrayTypeLambda extends HKT.TypeLambda { @@ -148,7 +149,9 @@ export interface TypeLambda { * * @example * ```ts - * import { HKT, Effect, Option } from "effect" + * import { Effect } from "effect" + * import { Option } from "effect/data" + * import { HKT } from "effect/types" * * // Define TypeLambdas * interface OptionTypeLambda extends HKT.TypeLambda { diff --git a/packages/effect/src/Types.ts b/packages/effect/src/types/Types.ts similarity index 90% rename from packages/effect/src/Types.ts rename to packages/effect/src/types/Types.ts index e633d80293..224cc5beae 100644 --- a/packages/effect/src/Types.ts +++ b/packages/effect/src/types/Types.ts @@ -16,7 +16,7 @@ type _TupleOf> = R["length"] exten * * @example * ```ts - * import { TupleOf } from "effect/Types" + * import { TupleOf } from "effect/types/Types" * * // A tuple with exactly 3 numbers * const example1: TupleOf<3, number> = [1, 2, 3]; // valid @@ -42,7 +42,7 @@ export type TupleOf = N extends N ? number extends N ? Arra * * @example * ```ts - * import { TupleOfAtLeast } from "effect/Types" + * import { TupleOfAtLeast } from "effect/types/Types" * * // A tuple with at least 3 numbers * const example1: TupleOfAtLeast<3, number> = [1, 2, 3]; // valid @@ -60,7 +60,7 @@ export type TupleOfAtLeast = [...TupleOf, ...Array * Returns the tags in a type. * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Res = Types.Tags // "a" | "b" * ``` @@ -74,7 +74,7 @@ export type Tags = E extends { readonly _tag: string } ? E["_tag"] : never * Excludes the tagged object from the type. * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Res = Types.ExcludeTag // string | { _tag: "b" } * ``` @@ -89,7 +89,7 @@ export type ExcludeTag = Exclude * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Res = Types.ExtractTag<{ _tag: "a", a: number } | { _tag: "b", b: number }, "b"> // { _tag: "b", b: number } * ``` @@ -104,7 +104,7 @@ export type ExtractTag = Extract * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Union = { a: string } | { b: number } * type Intersection = Types.UnionToIntersection // { a: string } & { b: number } @@ -121,7 +121,7 @@ export type UnionToIntersection = (T extends any ? (x: T) => any : never) ext * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Res = Types.Simplify<{ a: number } & { b: number }> // { a: number; b: number; } * ``` @@ -138,7 +138,7 @@ export type Simplify = { * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Res1 = Types.Equals<{ a: number }, { a: number }> // true * type Res2 = Types.Equals<{ a: number }, { b: number }> // false @@ -157,7 +157,7 @@ export type Equals = (() => T extends X ? 1 : 2) extends < * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Result1 = Types.EqualsWith // "yes" * type Result2 = Types.EqualsWith // "no" @@ -173,7 +173,7 @@ export type EqualsWith = (() => T extends A ? 1 : 2) extends ( * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Res1 = Types.Has<{ a: number }, "a" | "b"> // true * type Res2 = Types.Has<{ c: number }, "a" | "b"> // false @@ -191,7 +191,7 @@ export type Has = (Key extends infer K ? K extends keyof * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * type MergeLeft = Types.MergeLeft<{ a: number, b: number; }, { a: string }> // { a: number; b: number; } * ``` * @@ -205,7 +205,7 @@ export type MergeLeft = MergeRight * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * type MergeRight = Types.MergeRight<{ a: number, b: number; }, { a: string }> // { a: string; b: number; } * ``` * @@ -224,7 +224,7 @@ export type MergeRight = Simplify< * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Result = Types.MergeRecord<{ a: number, b: number }, { a: string, c: boolean }> // { a: number; b: number; c: boolean } * ``` @@ -239,7 +239,7 @@ export type MergeRecord = MergeLeft * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * const unbounded: Types.Concurrency = "unbounded" * const inherit: Types.Concurrency = "inherit" @@ -256,7 +256,7 @@ export type Concurrency = number | "unbounded" | "inherit" * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type MutableStruct = Types.Mutable<{ readonly a: string; readonly b: number }> // { a: string; b: number; } * @@ -279,7 +279,7 @@ export type Mutable = { * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type DeepMutableStruct = Types.DeepMutable<{ * readonly a: string; @@ -301,7 +301,7 @@ export type DeepMutable = T extends ReadonlyMap ? Map(value: T, noInfer: Types.NoInfer): T * @@ -320,7 +320,7 @@ export type NoInfer = [A][A extends any ? 0 : never] * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * // Invariant type for phantom types * type UserId = Types.Invariant @@ -343,7 +343,7 @@ export type Invariant = (_: A) => A /** * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type MyInvariant = Types.Invariant * type ExtractedType = Types.Invariant.Type // number @@ -356,7 +356,7 @@ export declare namespace Invariant { /** * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type MyInvariant = Types.Invariant * type ExtractedType = Types.Invariant.Type // number @@ -373,7 +373,7 @@ export declare namespace Invariant { * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * // Covariant type for producer types * type Producer = Types.Covariant @@ -392,7 +392,7 @@ export type Covariant = (_: never) => A /** * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type MyCovariant = Types.Covariant * type ExtractedType = Types.Covariant.Type // string @@ -405,7 +405,7 @@ export declare namespace Covariant { /** * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type MyCovariant = Types.Covariant * type ExtractedType = Types.Covariant.Type // string @@ -422,7 +422,7 @@ export declare namespace Covariant { * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * // Contravariant type for consumer types * type Consumer = Types.Contravariant @@ -441,7 +441,7 @@ export type Contravariant = (_: A) => void /** * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type MyContravariant = Types.Contravariant * type ExtractedType = Types.Contravariant.Type // string @@ -454,7 +454,7 @@ export declare namespace Contravariant { /** * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type MyContravariant = Types.Contravariant * type ExtractedType = Types.Contravariant.Type // string @@ -471,7 +471,7 @@ export declare namespace Contravariant { * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type EmptyResult = Types.MatchRecord<{}, "empty", "not empty"> // "empty" * type NonEmptyResult = Types.MatchRecord<{ a: number }, "empty", "not empty"> // "not empty" @@ -487,7 +487,7 @@ export type MatchRecord = {} extends S ? onTrue : onFalse * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Result = Types.NotFunction void)> // string | number * type NoFunctions = Types.NotFunction // string @@ -504,7 +504,7 @@ export type NotFunction = T extends Function ? never : T * * @example * ```ts - * import type { Types } from "effect" + * import type { Types } from "effect/types" * * type Expected = { a: number; b: string } * type Input = { a: number; b: string; c: boolean } diff --git a/packages/effect/src/Unify.ts b/packages/effect/src/types/Unify.ts similarity index 95% rename from packages/effect/src/Unify.ts rename to packages/effect/src/types/Unify.ts index 18fd5f1028..101447be9f 100644 --- a/packages/effect/src/Unify.ts +++ b/packages/effect/src/types/Unify.ts @@ -2,7 +2,7 @@ * @since 2.0.0 */ -import { identity } from "./Function.ts" +import { identity } from "../Function.ts" /** * A unique symbol used to identify unification behavior in Effect types. @@ -12,7 +12,7 @@ import { identity } from "./Function.ts" * * @example * ```ts - * import { Unify } from "effect" + * import { Unify } from "effect/types" * * // The unifySymbol is used internally in Effect types * // to enable automatic type unification @@ -35,7 +35,7 @@ export declare const unifySymbol: unique symbol * * @example * ```ts - * import { Unify } from "effect" + * import { Unify } from "effect/types" * * // The unifySymbol type is used in type declarations * // to enable unification behavior @@ -57,7 +57,7 @@ export type unifySymbol = typeof unifySymbol * * @example * ```ts - * import { Unify } from "effect" + * import { Unify } from "effect/types" * * // The typeSymbol is used internally in Effect types * // to store type information for unification @@ -80,7 +80,7 @@ export declare const typeSymbol: unique symbol * * @example * ```ts - * import { Unify } from "effect" + * import { Unify } from "effect/types" * * // The typeSymbol type is used in type declarations * // to store type information for unification @@ -103,7 +103,7 @@ export type typeSymbol = typeof typeSymbol * * @example * ```ts - * import { Unify } from "effect" + * import { Unify } from "effect/types" * * // The ignoreSymbol is used internally in Effect types * // to mark types that should be ignored during unification @@ -126,7 +126,7 @@ export declare const ignoreSymbol: unique symbol * * @example * ```ts - * import { Unify } from "effect" + * import { Unify } from "effect/types" * * // The ignoreSymbol type is used in type declarations * // to mark types that should be ignored during unification @@ -171,7 +171,7 @@ type FilterOut = A extends any ? typeSymbol extends keyof A ? never : A : nev * * @example * ```ts - * import * as Unify from "effect/Unify" + * import * as Unify from "effect/types/Unify" * * // Example of types that can be unified * type UnifiableA = { @@ -212,7 +212,7 @@ export type Unify = Values< * * @example * ```ts - * import { Unify } from "effect" + * import { Unify } from "effect/types" * * // Unify a simple value * const unifiedValue = Unify.unify("hello") diff --git a/packages/effect/src/types/index.ts b/packages/effect/src/types/index.ts new file mode 100644 index 0000000000..9598a15f1b --- /dev/null +++ b/packages/effect/src/types/index.ts @@ -0,0 +1,50 @@ +/** + * @since 4.0.0 + */ + +/** + * This module provides utilities for Higher-Kinded Types (HKT) in TypeScript. + * + * Higher-Kinded Types are types that take other types as parameters, similar to how + * functions take values as parameters. They enable generic programming over type + * constructors, allowing you to write code that works with any container type + * (like Array, Option, Effect, etc.) in a uniform way. + * + * The HKT system in Effect uses TypeLambdas to encode type-level functions that + * can represent complex type relationships with multiple type parameters, including + * contravariant, covariant, and invariant positions. + * + * @example + * ```ts + * import { HKT } from "effect/types" + * + * // Define a TypeLambda for Array + * interface ArrayTypeLambda extends HKT.TypeLambda { + * readonly type: Array + * } + * + * // Use Kind to get the concrete type + * type MyArray = HKT.Kind + * // MyArray is Array + * + * // Define a TypeClass that works with any HKT + * interface Functor extends HKT.TypeClass { + * map(fa: HKT.Kind, f: (a: A) => B): HKT.Kind + * } + * ``` + * + * @since 2.0.0 + */ +export * as HKT from "./HKT.ts" + +/** + * A collection of types that are commonly used types. + * + * @since 2.0.0 + */ +export * as Types from "./Types.ts" + +/** + * @since 2.0.0 + */ +export * as Unify from "./Unify.ts" diff --git a/packages/effect/src/types/index.ts.tpl b/packages/effect/src/types/index.ts.tpl new file mode 100644 index 0000000000..c2aac82f76 --- /dev/null +++ b/packages/effect/src/types/index.ts.tpl @@ -0,0 +1,3 @@ +/** + * @since 4.0.0 + */ diff --git a/packages/effect/src/unstable/http/Cookies.ts b/packages/effect/src/unstable/http/Cookies.ts index edb5df5282..4b9a8b4955 100644 --- a/packages/effect/src/unstable/http/Cookies.ts +++ b/packages/effect/src/unstable/http/Cookies.ts @@ -1,18 +1,18 @@ /** * @since 4.0.0 */ -import * as Data from "../../Data.ts" -import * as Duration from "../../Duration.ts" +import * as Data from "../../data/Data.ts" +import * as Option from "../../data/Option.ts" +import * as Predicate from "../../data/Predicate.ts" +import * as Record from "../../data/Record.ts" +import * as Result from "../../data/Result.ts" import { dual, identity } from "../../Function.ts" -import * as Inspectable from "../../Inspectable.ts" -import * as Option from "../../Option.ts" -import { type Pipeable, pipeArguments } from "../../Pipeable.ts" -import * as Predicate from "../../Predicate.ts" -import * as Record from "../../Record.ts" -import * as Result from "../../Result.ts" +import * as Inspectable from "../../interfaces/Inspectable.ts" +import { type Pipeable, pipeArguments } from "../../interfaces/Pipeable.ts" import * as Schema from "../../schema/Schema.ts" import * as Transformation from "../../schema/Transformation.ts" -import type * as Types from "../../Types.ts" +import * as Duration from "../../time/Duration.ts" +import type * as Types from "../../types/Types.ts" /** * @since 4.0.0 @@ -48,7 +48,7 @@ export interface Cookies extends Pipeable, Inspectable.Inspectable { export const schema: Schema.Codec = Schema.declareRefinement({ is: isCookies, annotations: { - id: "Cookies", + identifier: "Cookies", defaultJsonSerializer: () => Schema.link()( Schema.Array(Schema.String), diff --git a/packages/effect/src/unstable/http/Etag.ts b/packages/effect/src/unstable/http/Etag.ts index bd8b64fb3f..1acf7e20d1 100644 --- a/packages/effect/src/unstable/http/Etag.ts +++ b/packages/effect/src/unstable/http/Etag.ts @@ -2,9 +2,9 @@ * @since 4.0.0 */ import * as Effect from "../../Effect.ts" -import * as Layer from "../../Layer.ts" import type * as FileSystem from "../../platform/FileSystem.ts" -import * as ServiceMap from "../../ServiceMap.ts" +import * as Layer from "../../services/Layer.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" import type * as Body from "./HttpBody.ts" /** diff --git a/packages/effect/src/unstable/http/FetchHttpClient.ts b/packages/effect/src/unstable/http/FetchHttpClient.ts index d2a33421e2..e1c34c3014 100644 --- a/packages/effect/src/unstable/http/FetchHttpClient.ts +++ b/packages/effect/src/unstable/http/FetchHttpClient.ts @@ -2,9 +2,9 @@ * @since 1.0.0 */ import * as Effect from "../../Effect.ts" -import type * as Layer from "../../Layer.ts" -import * as ServiceMap from "../../ServiceMap.ts" -import * as Stream from "../../Stream.ts" +import type * as Layer from "../../services/Layer.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import * as Stream from "../../stream/Stream.ts" import * as Headers from "./Headers.ts" import * as HttpClient from "./HttpClient.ts" import { RequestError } from "./HttpClientError.ts" diff --git a/packages/effect/src/unstable/http/Headers.ts b/packages/effect/src/unstable/http/Headers.ts index 80bca45fbf..cb71b4374a 100644 --- a/packages/effect/src/unstable/http/Headers.ts +++ b/packages/effect/src/unstable/http/Headers.ts @@ -1,20 +1,20 @@ /** * @since 4.0.0 */ -import * as Equal from "../../Equal.ts" -import type { Equivalence as Equivalence_ } from "../../Equivalence.ts" +import type { Equivalence as Equivalence_ } from "../../data/Equivalence.ts" +import type * as Option from "../../data/Option.ts" +import * as Predicate from "../../data/Predicate.ts" +import * as Record from "../../data/Record.ts" +import * as Redacted from "../../data/Redacted.ts" import { dual } from "../../Function.ts" -import * as Hash from "../../Hash.ts" -import { type Redactable, symbolRedactable } from "../../Inspectable.ts" -import type * as Option from "../../Option.ts" -import * as Predicate from "../../Predicate.ts" -import * as Record from "../../Record.ts" -import * as Redacted from "../../Redacted.ts" +import * as Equal from "../../interfaces/Equal.ts" +import * as Hash from "../../interfaces/Hash.ts" +import { type Redactable, symbolRedactable } from "../../interfaces/Inspectable.ts" +import * as String from "../../primitives/String.ts" import * as Schema from "../../schema/Schema.ts" import * as Transformation from "../../schema/Transformation.ts" -import * as ServiceMap from "../../ServiceMap.ts" -import * as String from "../../String.ts" -import type { Mutable } from "../../Types.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import type { Mutable } from "../../types/Types.ts" /** * @since 4.0.0 @@ -82,7 +82,7 @@ export interface schema extends Schema.declareRefinement {} export const schema: schema = Schema.declareRefinement({ is: isHeaders, annotations: { - id: "Headers", + identifier: "Headers", equivalence: { _tag: "declaration", declaration: () => Equivalence diff --git a/packages/effect/src/unstable/http/HttpBody.ts b/packages/effect/src/unstable/http/HttpBody.ts index 1dfd829e9d..fb829a0632 100644 --- a/packages/effect/src/unstable/http/HttpBody.ts +++ b/packages/effect/src/unstable/http/HttpBody.ts @@ -1,17 +1,17 @@ /** * @since 4.0.0 */ -import * as Data from "../../Data.ts" +import * as Data from "../../data/Data.ts" +import * as Predicate from "../../data/Predicate.ts" import * as Effect from "../../Effect.ts" -import * as Inspectable from "../../Inspectable.ts" +import * as Inspectable from "../../interfaces/Inspectable.ts" import * as FileSystem from "../../platform/FileSystem.ts" import type * as PlatformError from "../../platform/PlatformError.ts" -import * as Predicate from "../../Predicate.ts" import type { ParseOptions } from "../../schema/AST.ts" import type { Issue } from "../../schema/Issue.ts" import * as Schema from "../../schema/Schema.ts" import * as Serializer from "../../schema/Serializer.ts" -import type * as Stream_ from "../../Stream.ts" +import type * as Stream_ from "../../stream/Stream.ts" import * as UrlParams from "./UrlParams.ts" /** diff --git a/packages/effect/src/unstable/http/HttpClient.ts b/packages/effect/src/unstable/http/HttpClient.ts index f229002739..3696e727ec 100644 --- a/packages/effect/src/unstable/http/HttpClient.ts +++ b/packages/effect/src/unstable/http/HttpClient.ts @@ -1,25 +1,25 @@ /** * @since 4.0.0 */ -import type { NonEmptyReadonlyArray } from "../../Array.ts" import * as Cause from "../../Cause.ts" +import type { NonEmptyReadonlyArray } from "../../collections/Array.ts" +import * as Ref from "../../concurrency/Ref.ts" +import type * as Filter from "../../data/Filter.ts" +import * as Predicate from "../../data/Predicate.ts" +import * as Result from "../../data/Result.ts" import * as Effect from "../../Effect.ts" import * as Exit from "../../Exit.ts" -import type { Fiber } from "../../Fiber.ts" -import type * as Filter from "../../Filter.ts" import { constFalse, constTrue, dual } from "../../Function.ts" -import * as Inspectable from "../../Inspectable.ts" -import * as Layer from "../../Layer.ts" -import { type Pipeable, pipeArguments } from "../../Pipeable.ts" -import * as Predicate from "../../Predicate.ts" -import * as Ref from "../../Ref.ts" -import * as Result from "../../Result.ts" -import * as Schedule from "../../Schedule.ts" -import type * as Scope from "../../Scope.ts" -import * as ServiceMap from "../../ServiceMap.ts" -import * as Stream from "../../Stream.ts" -import * as Tracer from "../../Tracer.ts" -import type { ExcludeTag, ExtractTag, NoExcessProperties, NoInfer, Tags } from "../../Types.ts" +import * as Inspectable from "../../interfaces/Inspectable.ts" +import { type Pipeable, pipeArguments } from "../../interfaces/Pipeable.ts" +import * as Tracer from "../../observability/Tracer.ts" +import type * as Scope from "../../resources/Scope.ts" +import type { Fiber } from "../../runtime/Fiber.ts" +import * as Schedule from "../../scheduling/Schedule.ts" +import * as Layer from "../../services/Layer.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import * as Stream from "../../stream/Stream.ts" +import type { ExcludeTag, ExtractTag, NoExcessProperties, NoInfer, Tags } from "../../types/Types.ts" import * as Cookies from "./Cookies.ts" import * as Headers from "./Headers.ts" import * as Error from "./HttpClientError.ts" diff --git a/packages/effect/src/unstable/http/HttpClientError.ts b/packages/effect/src/unstable/http/HttpClientError.ts index fc3f27fa6c..e6fcd8e1cf 100644 --- a/packages/effect/src/unstable/http/HttpClientError.ts +++ b/packages/effect/src/unstable/http/HttpClientError.ts @@ -1,8 +1,8 @@ /** * @since 4.0.0 */ -import * as Data from "../../Data.ts" -import { hasProperty } from "../../Predicate.ts" +import * as Data from "../../data/Data.ts" +import { hasProperty } from "../../data/Predicate.ts" import type * as HttpClientRequest from "./HttpClientRequest.ts" import type * as ClientResponse from "./HttpClientResponse.ts" diff --git a/packages/effect/src/unstable/http/HttpClientRequest.ts b/packages/effect/src/unstable/http/HttpClientRequest.ts index c7cf57bf0a..a447d32771 100644 --- a/packages/effect/src/unstable/http/HttpClientRequest.ts +++ b/packages/effect/src/unstable/http/HttpClientRequest.ts @@ -1,19 +1,19 @@ /** * @since 4.0.0 */ +import * as Option from "../../data/Option.ts" +import { hasProperty } from "../../data/Predicate.ts" +import * as Redacted from "../../data/Redacted.ts" +import * as Result from "../../data/Result.ts" import * as Effect from "../../Effect.ts" import { dual } from "../../Function.ts" -import * as Inspectable from "../../Inspectable.ts" -import * as Option from "../../Option.ts" -import { type Pipeable, pipeArguments } from "../../Pipeable.ts" +import * as Inspectable from "../../interfaces/Inspectable.ts" +import { type Pipeable, pipeArguments } from "../../interfaces/Pipeable.ts" import type * as FileSystem from "../../platform/FileSystem.ts" import type * as PlatformError from "../../platform/PlatformError.ts" -import { hasProperty } from "../../Predicate.ts" -import * as Redacted from "../../Redacted.ts" -import * as Result from "../../Result.ts" import type { ParseOptions } from "../../schema/AST.ts" import type * as Schema from "../../schema/Schema.ts" -import type * as Stream from "../../Stream.ts" +import type * as Stream from "../../stream/Stream.ts" import * as Headers from "./Headers.ts" import * as HttpBody from "./HttpBody.ts" import type { HttpMethod } from "./HttpMethod.ts" diff --git a/packages/effect/src/unstable/http/HttpClientResponse.ts b/packages/effect/src/unstable/http/HttpClientResponse.ts index b52091beee..ba4a871821 100644 --- a/packages/effect/src/unstable/http/HttpClientResponse.ts +++ b/packages/effect/src/unstable/http/HttpClientResponse.ts @@ -1,15 +1,15 @@ /** * @since 4.0.0 */ +import * as Option from "../../data/Option.ts" import * as Effect from "../../Effect.ts" import { dual } from "../../Function.ts" -import * as Inspectable from "../../Inspectable.ts" -import * as Option from "../../Option.ts" +import * as Inspectable from "../../interfaces/Inspectable.ts" import type { ParseOptions } from "../../schema/AST.ts" import * as Schema from "../../schema/Schema.ts" import * as Serializer from "../../schema/Serializer.ts" -import * as Stream from "../../Stream.ts" -import type { Unify } from "../../Unify.ts" +import * as Stream from "../../stream/Stream.ts" +import type { Unify } from "../../types/Unify.ts" import * as Cookies from "./Cookies.ts" import * as Headers from "./Headers.ts" import * as Error from "./HttpClientError.ts" diff --git a/packages/effect/src/unstable/http/HttpEffect.ts b/packages/effect/src/unstable/http/HttpEffect.ts index 76313a9da8..5a3c6e5bae 100644 --- a/packages/effect/src/unstable/http/HttpEffect.ts +++ b/packages/effect/src/unstable/http/HttpEffect.ts @@ -1,15 +1,15 @@ /** * @since 4.0.0 */ +import * as Option from "../../data/Option.ts" import * as Effect from "../../Effect.ts" import * as Exit from "../../Exit.ts" -import * as Fiber from "../../Fiber.ts" import { dual } from "../../Function.ts" -import * as Layer from "../../Layer.ts" -import * as Option from "../../Option.ts" -import * as Scope from "../../Scope.ts" -import * as ServiceMap from "../../ServiceMap.ts" -import * as Stream from "../../Stream.ts" +import * as Scope from "../../resources/Scope.ts" +import * as Fiber from "../../runtime/Fiber.ts" +import * as Layer from "../../services/Layer.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import * as Stream from "../../stream/Stream.ts" import * as HttpBody from "./HttpBody.ts" import { type HttpMiddleware, tracer } from "./HttpMiddleware.ts" import type { HttpServerError } from "./HttpServerError.ts" diff --git a/packages/effect/src/unstable/http/HttpIncomingMessage.ts b/packages/effect/src/unstable/http/HttpIncomingMessage.ts index b33b36d4c2..2216b65fb6 100644 --- a/packages/effect/src/unstable/http/HttpIncomingMessage.ts +++ b/packages/effect/src/unstable/http/HttpIncomingMessage.ts @@ -1,16 +1,16 @@ /** * @since 4.0.0 */ +import * as Option from "../../data/Option.ts" +import { hasProperty } from "../../data/Predicate.ts" import * as Effect from "../../Effect.ts" -import * as Inspectable from "../../Inspectable.ts" -import * as Option from "../../Option.ts" +import * as Inspectable from "../../interfaces/Inspectable.ts" import type * as FileSystem from "../../platform/FileSystem.ts" -import { hasProperty } from "../../Predicate.ts" import type { ParseOptions } from "../../schema/AST.ts" import * as Schema from "../../schema/Schema.ts" import * as Serializer from "../../schema/Serializer.ts" -import * as ServiceMap from "../../ServiceMap.ts" -import type * as Stream from "../../Stream.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import type * as Stream from "../../stream/Stream.ts" import type * as Headers from "./Headers.ts" import * as UrlParams from "./UrlParams.ts" diff --git a/packages/effect/src/unstable/http/HttpMiddleware.ts b/packages/effect/src/unstable/http/HttpMiddleware.ts index d1af3caa8f..86b3c1e664 100644 --- a/packages/effect/src/unstable/http/HttpMiddleware.ts +++ b/packages/effect/src/unstable/http/HttpMiddleware.ts @@ -2,12 +2,12 @@ * @since 4.0.0 */ import * as Effect from "effect/Effect" +import * as Option from "../../data/Option.ts" +import type { Predicate } from "../../data/Predicate.ts" +import type { ReadonlyRecord } from "../../data/Record.ts" import { constFalse } from "../../Function.ts" -import * as Layer from "../../Layer.ts" -import * as Option from "../../Option.ts" -import type { Predicate } from "../../Predicate.ts" -import type { ReadonlyRecord } from "../../Record.ts" -import * as ServiceMap from "../../ServiceMap.ts" +import * as Layer from "../../services/Layer.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" import * as Headers from "./Headers.ts" import type { PreResponseHandler } from "./HttpEffect.ts" import { causeResponseStripped, exitResponse } from "./HttpServerError.ts" diff --git a/packages/effect/src/unstable/http/HttpPlatform.ts b/packages/effect/src/unstable/http/HttpPlatform.ts index c42c5022f4..612e7691e9 100644 --- a/packages/effect/src/unstable/http/HttpPlatform.ts +++ b/packages/effect/src/unstable/http/HttpPlatform.ts @@ -3,11 +3,11 @@ */ import * as Effect from "../../Effect.ts" import { identity } from "../../Function.ts" -import * as Layer from "../../Layer.ts" import * as FileSystem from "../../platform/FileSystem.ts" import type { PlatformError } from "../../platform/PlatformError.ts" -import * as ServiceMap from "../../ServiceMap.ts" -import * as Stream from "../../Stream.ts" +import * as Layer from "../../services/Layer.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import * as Stream from "../../stream/Stream.ts" import * as Etag from "./Etag.ts" import * as Headers from "./Headers.ts" import type * as Body from "./HttpBody.ts" diff --git a/packages/effect/src/unstable/http/HttpRouter.ts b/packages/effect/src/unstable/http/HttpRouter.ts index 7f2156c8b0..aaaf1a0345 100644 --- a/packages/effect/src/unstable/http/HttpRouter.ts +++ b/packages/effect/src/unstable/http/HttpRouter.ts @@ -1,18 +1,18 @@ /** * @since 4.0.0 */ -import * as Arr from "../../Array.ts" +import * as Arr from "../../collections/Array.ts" +import * as Option from "../../data/Option.ts" +import type { ReadonlyRecord } from "../../data/Record.ts" import * as Effect from "../../Effect.ts" import { compose, dual, identity } from "../../Function.ts" -import * as Layer from "../../Layer.ts" -import * as Option from "../../Option.ts" -import type { ReadonlyRecord } from "../../Record.ts" +import * as Tracer from "../../observability/Tracer.ts" +import * as Scope from "../../resources/Scope.ts" import type { ParseOptions } from "../../schema/AST.ts" import * as Schema from "../../schema/Schema.ts" -import * as Scope from "../../Scope.ts" -import * as ServiceMap from "../../ServiceMap.ts" -import * as Tracer from "../../Tracer.ts" -import type * as Types from "../../Types.ts" +import * as Layer from "../../services/Layer.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import type * as Types from "../../types/Types.ts" import * as FindMyWay from "./FindMyWay.ts" import * as HttpEffect from "./HttpEffect.ts" import type * as HttpMethod from "./HttpMethod.ts" @@ -374,8 +374,8 @@ export const schemaPathParams = ( * Create a layer that adds a single route to the HTTP router. * * ```ts - * import * as Effect from "effect/Effect" + * import { Effect } from "effect" * import * as HttpRouter from "effect/unstable/http/HttpRouter" * import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse" * @@ -423,7 +423,7 @@ export const add = ( * Create a layer that adds multiple routes to the HTTP router. * * ```ts - * import * as Effect from "effect/Effect" + * import { Effect } from "effect" * import * as HttpRouter from "effect/unstable/http/HttpRouter" * import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse" * @@ -754,9 +754,9 @@ export interface Middleware< * import * as HttpRouter from "effect/unstable/http/HttpRouter" * import * as HttpMiddleware from "effect/unstable/http/HttpMiddleware" * import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse" - * import * as ServiceMap from "effect/ServiceMap" - * import * as Effect from "effect/Effect" - * import * as Layer from "effect/Layer" + * import * as ServiceMap from "effect/services/ServiceMap" + * import { Effect } from "effect" + * import * as Layer from "effect/services/Layer" * * // Here we are defining a CORS middleware * const CorsMiddleware = HttpRouter.middleware(HttpMiddleware.cors()).layer @@ -1039,10 +1039,10 @@ export const cors = ( * A middleware that disables the logger for some routes. * * ```ts - * import * as Effect from "effect/Effect" + * import { Effect } from "effect" * import * as HttpRouter from "effect/unstable/http/HttpRouter" * import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse" - * import * as Layer from "effect/Layer" + * import * as Layer from "effect/services/Layer" * * const Route = HttpRouter.add("GET", "/hello", Effect.succeed(HttpServerResponse.text("Hello, World!"))).pipe( * // disable the logger for this route diff --git a/packages/effect/src/unstable/http/HttpServer.ts b/packages/effect/src/unstable/http/HttpServer.ts index 6537e24676..18d1c4ffc1 100644 --- a/packages/effect/src/unstable/http/HttpServer.ts +++ b/packages/effect/src/unstable/http/HttpServer.ts @@ -3,11 +3,11 @@ */ import * as Effect from "../../Effect.ts" import { dual } from "../../Function.ts" -import * as Layer from "../../Layer.ts" import * as FileSystem from "../../platform/FileSystem.ts" import * as Path from "../../platform/Path.ts" -import type * as Scope from "../../Scope.ts" -import * as ServiceMap from "../../ServiceMap.ts" +import type * as Scope from "../../resources/Scope.ts" +import * as Layer from "../../services/Layer.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" import * as Etag from "./Etag.ts" import * as HttpClient from "./HttpClient.ts" import * as ClientRequest from "./HttpClientRequest.ts" diff --git a/packages/effect/src/unstable/http/HttpServerError.ts b/packages/effect/src/unstable/http/HttpServerError.ts index dd11cd0685..443a72273e 100644 --- a/packages/effect/src/unstable/http/HttpServerError.ts +++ b/packages/effect/src/unstable/http/HttpServerError.ts @@ -1,13 +1,13 @@ /** * @since 4.0.0 */ -import * as Arr from "../../Array.ts" import * as Cause from "../../Cause.ts" -import * as Data from "../../Data.ts" +import * as Arr from "../../collections/Array.ts" +import * as Data from "../../data/Data.ts" +import * as Option from "../../data/Option.ts" +import { hasProperty } from "../../data/Predicate.ts" import * as Effect from "../../Effect.ts" import type * as Exit from "../../Exit.ts" -import * as Option from "../../Option.ts" -import { hasProperty } from "../../Predicate.ts" import type * as Request from "./HttpServerRequest.ts" import * as Respondable from "./HttpServerRespondable.ts" import * as Response from "./HttpServerResponse.ts" diff --git a/packages/effect/src/unstable/http/HttpServerRequest.ts b/packages/effect/src/unstable/http/HttpServerRequest.ts index 3c3b11557d..b9ab605bc9 100644 --- a/packages/effect/src/unstable/http/HttpServerRequest.ts +++ b/packages/effect/src/unstable/http/HttpServerRequest.ts @@ -1,19 +1,19 @@ /** * @since 4.0.0 */ -import type * as Arr from "../../Array.ts" -import * as Channel from "../../Channel.ts" +import type * as Arr from "../../collections/Array.ts" +import * as Option from "../../data/Option.ts" +import type { ReadonlyRecord } from "../../data/Record.ts" import * as Effect from "../../Effect.ts" -import * as Inspectable from "../../Inspectable.ts" -import * as Option from "../../Option.ts" +import * as Inspectable from "../../interfaces/Inspectable.ts" import type * as FileSystem from "../../platform/FileSystem.ts" import type * as Path from "../../platform/Path.ts" -import type { ReadonlyRecord } from "../../Record.ts" +import type * as Scope from "../../resources/Scope.ts" import type { ParseOptions } from "../../schema/AST.ts" import * as Schema from "../../schema/Schema.ts" -import type * as Scope from "../../Scope.ts" -import * as ServiceMap from "../../ServiceMap.ts" -import * as Stream from "../../Stream.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import * as Channel from "../../stream/Channel.ts" +import * as Stream from "../../stream/Stream.ts" import * as Socket from "../socket/Socket.ts" import * as Cookies from "./Cookies.ts" import * as Headers from "./Headers.ts" diff --git a/packages/effect/src/unstable/http/HttpServerRespondable.ts b/packages/effect/src/unstable/http/HttpServerRespondable.ts index 70f297e763..5bcdb86615 100644 --- a/packages/effect/src/unstable/http/HttpServerRespondable.ts +++ b/packages/effect/src/unstable/http/HttpServerRespondable.ts @@ -2,8 +2,8 @@ * @since 4.0.0 */ import * as Cause from "../../Cause.ts" +import { hasProperty } from "../../data/Predicate.ts" import * as Effect from "../../Effect.ts" -import { hasProperty } from "../../Predicate.ts" import * as Schema from "../../schema/Schema.ts" import type { HttpServerResponse } from "./HttpServerResponse.ts" import * as Response from "./HttpServerResponse.ts" diff --git a/packages/effect/src/unstable/http/HttpServerResponse.ts b/packages/effect/src/unstable/http/HttpServerResponse.ts index e274b45b36..796904672c 100644 --- a/packages/effect/src/unstable/http/HttpServerResponse.ts +++ b/packages/effect/src/unstable/http/HttpServerResponse.ts @@ -1,19 +1,19 @@ /** * @since 4.0.0 */ +import { hasProperty } from "../../data/Predicate.ts" import * as Effect from "../../Effect.ts" import { dual } from "../../Function.ts" -import { ServiceMap } from "../../index.ts" -import * as Inspectable from "../../Inspectable.ts" +import * as Inspectable from "../../interfaces/Inspectable.ts" +import type { Pipeable } from "../../interfaces/Pipeable.ts" import { PipeInspectableProto } from "../../internal/core.ts" -import type { Pipeable } from "../../Pipeable.ts" import type * as FileSystem from "../../platform/FileSystem.ts" import type { PlatformError } from "../../platform/PlatformError.ts" -import { hasProperty } from "../../Predicate.ts" import type { ParseOptions } from "../../schema/AST.ts" import type * as Schema from "../../schema/Schema.ts" -import * as Stream from "../../Stream.ts" -import type { Mutable } from "../../Types.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import * as Stream from "../../stream/Stream.ts" +import type { Mutable } from "../../types/Types.ts" import * as Cookies from "./Cookies.ts" import * as Headers from "./Headers.ts" import * as Body from "./HttpBody.ts" diff --git a/packages/effect/src/unstable/http/HttpTraceContext.ts b/packages/effect/src/unstable/http/HttpTraceContext.ts index 8c287c2643..21665cb7f1 100644 --- a/packages/effect/src/unstable/http/HttpTraceContext.ts +++ b/packages/effect/src/unstable/http/HttpTraceContext.ts @@ -1,8 +1,8 @@ /** * @since 4.0.0 */ -import * as Option from "../../Option.ts" -import * as Tracer from "../../Tracer.ts" +import * as Option from "../../data/Option.ts" +import * as Tracer from "../../observability/Tracer.ts" import * as Headers from "./Headers.ts" /** diff --git a/packages/effect/src/unstable/http/Multipart.ts b/packages/effect/src/unstable/http/Multipart.ts index 291390d127..760fe191ea 100644 --- a/packages/effect/src/unstable/http/Multipart.ts +++ b/packages/effect/src/unstable/http/Multipart.ts @@ -1,24 +1,24 @@ /** * @since 4.0.0 */ -import * as Arr from "../../Array.ts" -import * as Channel from "../../Channel.ts" +import * as Arr from "../../collections/Array.ts" +import * as Option from "../../data/Option.ts" +import * as Predicate from "../../data/Predicate.ts" import * as Effect from "../../Effect.ts" import * as Exit from "../../Exit.ts" import { constant, dual } from "../../Function.ts" -import * as Inspectable from "../../Inspectable.ts" -import * as Option from "../../Option.ts" +import * as Inspectable from "../../interfaces/Inspectable.ts" import * as FileSystem from "../../platform/FileSystem.ts" import * as Path from "../../platform/Path.ts" -import * as Predicate from "../../Predicate.ts" -import * as Pull from "../../Pull.ts" +import type * as Scope from "../../resources/Scope.ts" import type { ParseOptions } from "../../schema/AST.ts" import * as Check from "../../schema/Check.ts" import * as Schema from "../../schema/Schema.ts" import * as Transformation from "../../schema/Transformation.ts" -import type * as Scope from "../../Scope.ts" -import * as ServiceMap from "../../ServiceMap.ts" -import * as Stream from "../../Stream.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import * as Channel from "../../stream/Channel.ts" +import * as Pull from "../../stream/Pull.ts" +import * as Stream from "../../stream/Stream.ts" import * as IncomingMessage from "./HttpIncomingMessage.ts" import * as MP from "./Multipasta.ts" @@ -170,7 +170,7 @@ export interface FileSchema extends Schema.declareRefinement {} export const FileSchema: FileSchema = Schema.declareRefinement({ is: isPersistedFile, annotations: { - id: "PersistedFile", + identifier: "PersistedFile", jsonSchema: { _tag: "override", override: () => ({ diff --git a/packages/effect/src/unstable/http/Template.ts b/packages/effect/src/unstable/http/Template.ts index 5b75a73e17..db391b4451 100644 --- a/packages/effect/src/unstable/http/Template.ts +++ b/packages/effect/src/unstable/http/Template.ts @@ -1,10 +1,10 @@ /** * @since 4.0.0 */ +import * as Option from "../../data/Option.ts" import * as Effect from "../../Effect.ts" import * as Exit from "../../Exit.ts" -import * as Option from "../../Option.ts" -import * as Stream from "../../Stream.ts" +import * as Stream from "../../stream/Stream.ts" /** * @category models diff --git a/packages/effect/src/unstable/http/UrlParams.ts b/packages/effect/src/unstable/http/UrlParams.ts index 92bd80da2d..15f4fce475 100644 --- a/packages/effect/src/unstable/http/UrlParams.ts +++ b/packages/effect/src/unstable/http/UrlParams.ts @@ -1,27 +1,27 @@ /** * @since 4.0.0 */ -import * as Arr from "../../Array.ts" -import * as Data from "../../Data.ts" +import * as Arr from "../../collections/Array.ts" +import * as Data from "../../data/Data.ts" +import * as Equivalence_ from "../../data/Equivalence.ts" +import * as Option from "../../data/Option.ts" +import { hasProperty } from "../../data/Predicate.ts" +import type { ReadonlyRecord } from "../../data/Record.ts" +import * as Result from "../../data/Result.ts" +import * as Tuple from "../../data/Tuple.ts" import * as Effect from "../../Effect.ts" -import * as Equal from "../../Equal.ts" -import * as Equivalence_ from "../../Equivalence.ts" import { dual } from "../../Function.ts" -import * as Hash from "../../Hash.ts" -import { type Inspectable } from "../../Inspectable.ts" +import * as Equal from "../../interfaces/Equal.ts" +import * as Hash from "../../interfaces/Hash.ts" +import { type Inspectable } from "../../interfaces/Inspectable.ts" +import type { Pipeable } from "../../interfaces/Pipeable.ts" import { PipeInspectableProto } from "../../internal/core.ts" -import * as Option from "../../Option.ts" -import type { Pipeable } from "../../Pipeable.ts" -import { hasProperty } from "../../Predicate.ts" -import type { ReadonlyRecord } from "../../Record.ts" -import * as Result from "../../Result.ts" +import * as String$ from "../../primitives/String.ts" import type * as Annotations from "../../schema/Annotations.ts" import type * as AST from "../../schema/AST.ts" import * as Issue from "../../schema/Issue.ts" import * as Schema from "../../schema/Schema.ts" import * as Transformation from "../../schema/Transformation.ts" -import * as String$ from "../../String.ts" -import * as Tuple from "../../Tuple.ts" /** * @since 4.0.0 @@ -166,7 +166,7 @@ export interface schema extends Schema.declareRefinement {} export const schema: schema = Schema.declareRefinement({ is: isUrlParams, annotations: { - id: "UrlParams", + identifier: "UrlParams", equivalence: { _tag: "declaration", declaration: () => Equivalence diff --git a/packages/effect/src/unstable/socket/Socket.ts b/packages/effect/src/unstable/socket/Socket.ts index c6452f6882..a893fde385 100644 --- a/packages/effect/src/unstable/socket/Socket.ts +++ b/packages/effect/src/unstable/socket/Socket.ts @@ -1,22 +1,22 @@ /** * @since 4.0.0 */ -import type { NonEmptyReadonlyArray } from "../../Array.ts" -import * as Channel from "../../Channel.ts" -import * as Data from "../../Data.ts" -import * as Deferred from "../../Deferred.ts" -import type { DurationInput } from "../../Duration.ts" +import type { NonEmptyReadonlyArray } from "../../collections/Array.ts" +import * as Deferred from "../../concurrency/Deferred.ts" +import * as FiberSet from "../../concurrency/FiberSet.ts" +import * as Queue from "../../concurrency/Queue.ts" +import * as Data from "../../data/Data.ts" +import * as Filter from "../../data/Filter.ts" +import * as Predicate from "../../data/Predicate.ts" import * as Effect from "../../Effect.ts" import * as Exit from "../../Exit.ts" -import * as FiberSet from "../../FiberSet.ts" -import * as Filter from "../../Filter.ts" import { dual } from "../../Function.ts" -import * as Layer from "../../Layer.ts" -import * as Predicate from "../../Predicate.ts" -import * as Pull from "../../Pull.ts" -import * as Queue from "../../Queue.ts" -import * as Scope from "../../Scope.ts" -import * as ServiceMap from "../../ServiceMap.ts" +import * as Scope from "../../resources/Scope.ts" +import * as Layer from "../../services/Layer.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" +import * as Channel from "../../stream/Channel.ts" +import * as Pull from "../../stream/Pull.ts" +import type { DurationInput } from "../../time/Duration.ts" /** * @since 4.0.0 diff --git a/packages/effect/src/unstable/socket/SocketServer.ts b/packages/effect/src/unstable/socket/SocketServer.ts index 502d5fb062..b8305ee037 100644 --- a/packages/effect/src/unstable/socket/SocketServer.ts +++ b/packages/effect/src/unstable/socket/SocketServer.ts @@ -1,9 +1,9 @@ /** * @since 4.0.0 */ -import * as Data from "../../Data.ts" +import * as Data from "../../data/Data.ts" import type * as Effect from "../../Effect.ts" -import * as ServiceMap from "../../ServiceMap.ts" +import * as ServiceMap from "../../services/ServiceMap.ts" import type * as Socket from "./Socket.ts" /** diff --git a/packages/effect/src/unstable/tracing/Otlp.ts b/packages/effect/src/unstable/tracing/Otlp.ts index c6500688c3..9a71bcb372 100644 --- a/packages/effect/src/unstable/tracing/Otlp.ts +++ b/packages/effect/src/unstable/tracing/Otlp.ts @@ -1,9 +1,9 @@ /** * @since 4.0.0 */ -import type * as Duration from "../../Duration.ts" -import * as Layer from "../../Layer.ts" -import type * as Tracer from "../../Tracer.ts" +import type * as Tracer from "../../observability/Tracer.ts" +import * as Layer from "../../services/Layer.ts" +import type * as Duration from "../../time/Duration.ts" import type * as Headers from "../http/Headers.ts" import type * as HttpClient from "../http/HttpClient.ts" import * as OtlpLogger from "./OtlpLogger.ts" diff --git a/packages/effect/src/unstable/tracing/OtlpLogger.ts b/packages/effect/src/unstable/tracing/OtlpLogger.ts index 777a09baa2..db2f683c3f 100644 --- a/packages/effect/src/unstable/tracing/OtlpLogger.ts +++ b/packages/effect/src/unstable/tracing/OtlpLogger.ts @@ -1,16 +1,16 @@ /** * @since 4.0.0 */ -import * as Arr from "../../Array.ts" import * as Cause from "../../Cause.ts" -import * as Duration from "../../Duration.ts" +import * as Arr from "../../collections/Array.ts" import * as Effect from "../../Effect.ts" import * as Exporter from "../../internal/tracing/otlpExporter.ts" -import type * as Layer from "../../Layer.ts" -import * as Logger from "../../Logger.ts" -import type * as LogLevel from "../../LogLevel.ts" -import { CurrentLogAnnotations, CurrentLogSpans } from "../../References.ts" -import type * as Scope from "../../Scope.ts" +import * as Logger from "../../logging/Logger.ts" +import type * as LogLevel from "../../logging/LogLevel.ts" +import type * as Scope from "../../resources/Scope.ts" +import type * as Layer from "../../services/Layer.ts" +import { CurrentLogAnnotations, CurrentLogSpans } from "../../services/References.ts" +import * as Duration from "../../time/Duration.ts" import type * as Headers from "../http/Headers.ts" import type * as HttpClient from "../http/HttpClient.ts" import type { AnyValue, Fixed64, KeyValue, Resource } from "./OtlpResource.ts" diff --git a/packages/effect/src/unstable/tracing/OtlpMetrics.ts b/packages/effect/src/unstable/tracing/OtlpMetrics.ts index b040cedce4..723fe03649 100644 --- a/packages/effect/src/unstable/tracing/OtlpMetrics.ts +++ b/packages/effect/src/unstable/tracing/OtlpMetrics.ts @@ -1,14 +1,14 @@ /** * @since 4.0.0 */ -import * as Arr from "../../Array.ts" -import { Clock } from "../../Clock.ts" -import * as Duration from "../../Duration.ts" +import * as Arr from "../../collections/Array.ts" import * as Effect from "../../Effect.ts" import * as Exporter from "../../internal/tracing/otlpExporter.ts" -import * as Layer from "../../Layer.ts" -import * as Metric from "../../Metric.ts" -import type * as Scope from "../../Scope.ts" +import * as Metric from "../../observability/Metric.ts" +import type * as Scope from "../../resources/Scope.ts" +import * as Layer from "../../services/Layer.ts" +import { Clock } from "../../time/Clock.ts" +import * as Duration from "../../time/Duration.ts" import type * as Headers from "../http/Headers.ts" import type * as HttpClient from "../http/HttpClient.ts" import type { Fixed64, KeyValue } from "./OtlpResource.ts" diff --git a/packages/effect/src/unstable/tracing/OtlpResource.ts b/packages/effect/src/unstable/tracing/OtlpResource.ts index afc4405fa3..a218a59351 100644 --- a/packages/effect/src/unstable/tracing/OtlpResource.ts +++ b/packages/effect/src/unstable/tracing/OtlpResource.ts @@ -3,7 +3,7 @@ */ import * as Config from "../../config/Config.ts" import * as Effect from "../../Effect.ts" -import * as Inspectable from "../../Inspectable.ts" +import * as Inspectable from "../../interfaces/Inspectable.ts" /** * @since 4.0.0 diff --git a/packages/effect/src/unstable/tracing/OtlpTracer.ts b/packages/effect/src/unstable/tracing/OtlpTracer.ts index 5ee639d66e..1e8a175445 100644 --- a/packages/effect/src/unstable/tracing/OtlpTracer.ts +++ b/packages/effect/src/unstable/tracing/OtlpTracer.ts @@ -2,16 +2,16 @@ * @since 4.0.0 */ import * as Cause from "../../Cause.ts" -import * as Duration from "../../Duration.ts" +import * as Option from "../../data/Option.ts" import * as Effect from "../../Effect.ts" import type * as Exit from "../../Exit.ts" import * as Exporter from "../../internal/tracing/otlpExporter.ts" -import * as Layer from "../../Layer.ts" -import * as Option from "../../Option.ts" -import type * as Scope from "../../Scope.ts" -import type * as ServiceMap from "../../ServiceMap.ts" -import * as Tracer from "../../Tracer.ts" -import type { ExtractTag } from "../../Types.ts" +import * as Tracer from "../../observability/Tracer.ts" +import type * as Scope from "../../resources/Scope.ts" +import * as Layer from "../../services/Layer.ts" +import type * as ServiceMap from "../../services/ServiceMap.ts" +import * as Duration from "../../time/Duration.ts" +import type { ExtractTag } from "../../types/Types.ts" import type * as Headers from "../http/Headers.ts" import type * as HttpClient from "../http/HttpClient.ts" import type { KeyValue, Resource } from "./OtlpResource.ts" diff --git a/packages/effect/test/Channel.test.ts b/packages/effect/test/Channel.test.ts index 8fbddc19b8..b30041c4d4 100644 --- a/packages/effect/test/Channel.test.ts +++ b/packages/effect/test/Channel.test.ts @@ -1,9 +1,9 @@ import { assert, describe, it } from "@effect/vitest" -import * as Channel from "effect/Channel" +import { Queue } from "effect/concurrency" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import * as Queue from "effect/Queue" +import { Fiber } from "effect/runtime" +import { Channel } from "effect/stream" describe("Channel", () => { describe("constructors", () => { diff --git a/packages/effect/test/Deferred.test.ts b/packages/effect/test/Deferred.test.ts index 368de11f3b..863e50c16e 100644 --- a/packages/effect/test/Deferred.test.ts +++ b/packages/effect/test/Deferred.test.ts @@ -1,9 +1,9 @@ import { assert, describe, it } from "@effect/vitest" import * as Cause from "effect/Cause" -import * as Deferred from "effect/Deferred" +import { Deferred } from "effect/concurrency" +import { Option } from "effect/data" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as Option from "effect/Option" describe("Deferred", () => { describe("success", () => { diff --git a/packages/effect/test/Duration.test.ts b/packages/effect/test/Duration.test.ts index 93bb5e664c..19540302d3 100644 --- a/packages/effect/test/Duration.test.ts +++ b/packages/effect/test/Duration.test.ts @@ -8,7 +8,9 @@ import { strictEqual, throws } from "@effect/vitest/utils" -import { Duration, Equal, pipe } from "effect" +import { pipe } from "effect" +import { Equal } from "effect/interfaces" +import { Duration } from "effect/time" describe("Duration", () => { it("decode", () => { diff --git a/packages/effect/test/Effect.test.ts b/packages/effect/test/Effect.test.ts index 48804bd0ed..5a0739a51e 100644 --- a/packages/effect/test/Effect.test.ts +++ b/packages/effect/test/Effect.test.ts @@ -1,18 +1,15 @@ import { assert, describe, it } from "@effect/vitest" import * as Cause from "effect/Cause" -import * as Data from "effect/Data" +import { Data, Filter, Option, Result } from "effect/data" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import * as Filter from "effect/Filter" import { constFalse, constTrue, pipe } from "effect/Function" -import * as Option from "effect/Option" -import * as Result from "effect/Result" -import * as Schedule from "effect/Schedule" -import * as Scope from "effect/Scope" -import * as ServiceMap from "effect/ServiceMap" -import * as TestClock from "effect/TestClock" -import * as TxRef from "effect/TxRef" +import { Scope } from "effect/resources" +import { Fiber } from "effect/runtime" +import { Schedule } from "effect/scheduling" +import { ServiceMap } from "effect/services" +import { TestClock } from "effect/testing" +import { TxRef } from "effect/transactions" class ATag extends ServiceMap.Key()("ATag") {} diff --git a/packages/effect/test/EffectEager.test.ts b/packages/effect/test/EffectEager.test.ts index 25d155f5d6..28f53ea50f 100644 --- a/packages/effect/test/EffectEager.test.ts +++ b/packages/effect/test/EffectEager.test.ts @@ -1,8 +1,7 @@ import { assert, describe, it } from "@effect/vitest" -import * as Effect from "effect/Effect" -import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import * as TestClock from "effect/TestClock" +import { Effect, Exit } from "effect" +import { Fiber } from "effect/runtime" +import { TestClock } from "effect/testing" describe("Effect Eager Operations", () => { describe("fnUntracedEager", () => { diff --git a/packages/effect/test/Fiber.test.ts b/packages/effect/test/Fiber.test.ts index c184597781..575aa809b5 100644 --- a/packages/effect/test/Fiber.test.ts +++ b/packages/effect/test/Fiber.test.ts @@ -1,6 +1,6 @@ import { assert, describe, it } from "@effect/vitest" -import * as Effect from "effect/Effect" -import * as Fiber from "effect/Fiber" +import { Effect } from "effect" +import { Fiber } from "effect/runtime" describe("Effect", () => { it("Fiber is a fiber", async () => { diff --git a/packages/effect/test/FiberHandle.test.ts b/packages/effect/test/FiberHandle.test.ts index 515b55f9fc..66e3770501 100644 --- a/packages/effect/test/FiberHandle.test.ts +++ b/packages/effect/test/FiberHandle.test.ts @@ -1,6 +1,9 @@ import { assert, describe, it } from "@effect/vitest" import { assertFalse, assertTrue, strictEqual } from "@effect/vitest/utils" -import { Deferred, Effect, Exit, Fiber, FiberHandle, pipe, Ref, TestClock } from "effect" +import { Effect, Exit, pipe } from "effect" +import { Deferred, FiberHandle, Ref } from "effect/concurrency" +import { Fiber } from "effect/runtime" +import { TestClock } from "effect/testing" describe("FiberHandle", () => { it.effect("interrupts fibers", () => diff --git a/packages/effect/test/FiberMap.test.ts b/packages/effect/test/FiberMap.test.ts index 6f394a59ad..60e1d45a35 100644 --- a/packages/effect/test/FiberMap.test.ts +++ b/packages/effect/test/FiberMap.test.ts @@ -1,6 +1,11 @@ import { assert, describe, it } from "@effect/vitest" import { assertFalse, assertTrue, strictEqual } from "@effect/vitest/utils" -import { Array, Deferred, Effect, Exit, Fiber, FiberMap, pipe, Ref, Scope, TestClock } from "effect" +import { Effect, Exit, pipe } from "effect" +import { Array } from "effect/collections" +import { Deferred, FiberMap, Ref } from "effect/concurrency" +import { Scope } from "effect/resources" +import { Fiber } from "effect/runtime" +import { TestClock } from "effect/testing" describe("FiberMap", () => { it.effect("interrupts fibers", () => diff --git a/packages/effect/test/FiberSet.test.ts b/packages/effect/test/FiberSet.test.ts index 8dc16998d4..7b7279b6c5 100644 --- a/packages/effect/test/FiberSet.test.ts +++ b/packages/effect/test/FiberSet.test.ts @@ -1,6 +1,11 @@ import { assert, describe, it } from "@effect/vitest" import { assertFalse, assertTrue, strictEqual } from "@effect/vitest/utils" -import { Array, Deferred, Effect, Exit, Fiber, FiberSet, pipe, Ref, Scope, TestClock } from "effect" +import { Effect, Exit, pipe } from "effect" +import { Array } from "effect/collections" +import { Deferred, FiberSet, Ref } from "effect/concurrency" +import { Scope } from "effect/resources" +import { Fiber } from "effect/runtime" +import { TestClock } from "effect/testing" describe("FiberSet", () => { it.effect("interrupts fibers", () => diff --git a/packages/effect/test/Graph.test.ts b/packages/effect/test/Graph.test.ts index 0a5a6d9da7..0ab72df8da 100644 --- a/packages/effect/test/Graph.test.ts +++ b/packages/effect/test/Graph.test.ts @@ -1,7 +1,6 @@ -import * as Equal from "effect/Equal" -import * as Graph from "effect/Graph" -import * as Hash from "effect/Hash" -import * as Option from "effect/Option" +import { Graph } from "effect/collections" +import { Option } from "effect/data" +import { Equal, Hash } from "effect/interfaces" import { describe, expect, it } from "vitest" describe("Graph", () => { diff --git a/packages/effect/test/HashMap.test.ts b/packages/effect/test/HashMap.test.ts index fd4adaa49a..8e892b0abb 100644 --- a/packages/effect/test/HashMap.test.ts +++ b/packages/effect/test/HashMap.test.ts @@ -1,7 +1,6 @@ -import * as Equal from "effect/Equal" -import * as Hash from "effect/Hash" -import * as HashMap from "effect/HashMap" -import * as Option from "effect/Option" +import { HashMap } from "effect/collections" +import { Option } from "effect/data" +import { Equal, Hash } from "effect/interfaces" import { describe, expect, it } from "vitest" describe("HashMap", () => { diff --git a/packages/effect/test/HashSet.test.ts b/packages/effect/test/HashSet.test.ts index 3ca6a97855..328c86aa7a 100644 --- a/packages/effect/test/HashSet.test.ts +++ b/packages/effect/test/HashSet.test.ts @@ -1,6 +1,5 @@ -import * as Equal from "effect/Equal" -import * as Hash from "effect/Hash" -import * as HashSet from "effect/HashSet" +import { HashSet } from "effect/collections" +import { Equal, Hash } from "effect/interfaces" import { describe, expect, it } from "vitest" describe("HashSet", () => { diff --git a/packages/effect/test/HttpClient.test.ts b/packages/effect/test/HttpClient.test.ts index cf2d615e03..7edb3465e0 100644 --- a/packages/effect/test/HttpClient.test.ts +++ b/packages/effect/test/HttpClient.test.ts @@ -1,6 +1,10 @@ import { expect, it } from "@effect/vitest" -import { Effect, Layer, ServiceMap, Stream, Struct, TestClock } from "effect" +import { Effect } from "effect" +import { Struct } from "effect/data" import { Schema } from "effect/schema" +import { Layer, ServiceMap } from "effect/services" +import { Stream } from "effect/stream" +import { TestClock } from "effect/testing" import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http" const Todo = Schema.Struct({ diff --git a/packages/effect/test/Layer.test.ts b/packages/effect/test/Layer.test.ts index 90c86bf8cc..a8c727df88 100644 --- a/packages/effect/test/Layer.test.ts +++ b/packages/effect/test/Layer.test.ts @@ -1,10 +1,10 @@ import { assert, describe, it } from "@effect/vitest" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import * as Layer from "effect/Layer" -import * as Scope from "effect/Scope" -import * as ServiceMap from "effect/ServiceMap" +import * as Scope from "effect/resources/Scope" +import { Fiber } from "effect/runtime" +import { ServiceMap } from "effect/services" +import * as Layer from "effect/services/Layer" describe("Layer", () => { it.effect("layers can be acquired in parallel", () => diff --git a/packages/effect/test/Logger.test.ts b/packages/effect/test/Logger.test.ts index 2d59588edc..903deaee20 100644 --- a/packages/effect/test/Logger.test.ts +++ b/packages/effect/test/Logger.test.ts @@ -1,8 +1,8 @@ import { assert, describe, it } from "@effect/vitest" import * as Effect from "effect/Effect" -import * as Layer from "effect/Layer" -import * as Logger from "effect/Logger" -import * as TestConsole from "effect/TestConsole" +import * as Logger from "effect/logging/Logger" +import * as Layer from "effect/services/Layer" +import * as TestConsole from "effect/testing/TestConsole" describe("Logger", () => { it.effect("should output logs", () => diff --git a/packages/effect/test/ManagedRuntime.test.ts b/packages/effect/test/ManagedRuntime.test.ts index dbea6a6726..054be9acfa 100644 --- a/packages/effect/test/ManagedRuntime.test.ts +++ b/packages/effect/test/ManagedRuntime.test.ts @@ -1,6 +1,8 @@ import { describe, it, test } from "@effect/vitest" import { strictEqual } from "@effect/vitest/utils" -import { Effect, Layer, ManagedRuntime, ServiceMap } from "effect" +import { Effect } from "effect" +import { ManagedRuntime } from "effect/runtime" +import { Layer, ServiceMap } from "effect/services" describe("ManagedRuntime", () => { test("memoizes the layer build", async () => { diff --git a/packages/effect/test/Metric.test.ts b/packages/effect/test/Metric.test.ts index ee767acdef..257d7e59f8 100644 --- a/packages/effect/test/Metric.test.ts +++ b/packages/effect/test/Metric.test.ts @@ -1,11 +1,11 @@ import { assert, describe, it } from "@effect/vitest" -import * as Duration from "effect/Duration" +import { Option } from "effect/data" import * as Effect from "effect/Effect" -import * as Fiber from "effect/Fiber" -import * as Metric from "effect/Metric" -import * as Option from "effect/Option" -import * as String from "effect/String" -import * as TestClock from "effect/TestClock" +import { Metric } from "effect/observability" +import { String } from "effect/primitives" +import { Fiber } from "effect/runtime" +import { TestClock } from "effect/testing" +import { Duration } from "effect/time" const attributes = { x: "a", y: "b" } diff --git a/packages/effect/test/PubSub.test.ts b/packages/effect/test/PubSub.test.ts index 6d708da864..48d0c64e42 100644 --- a/packages/effect/test/PubSub.test.ts +++ b/packages/effect/test/PubSub.test.ts @@ -1,6 +1,10 @@ import { assert, describe, it } from "@effect/vitest" -import { Array, Effect, Fiber, Option, PubSub } from "effect" +import { Effect } from "effect" +import { Array } from "effect/collections" +import { PubSub } from "effect/concurrency" +import { Option } from "effect/data" import { pipe } from "effect/Function" +import { Fiber } from "effect/runtime" describe("PubSub", () => { it.effect("publishAll - capacity 2 (BoundedPubSubPow2)", () => { diff --git a/packages/effect/test/Queue.test.ts b/packages/effect/test/Queue.test.ts index 8f379849a7..2430554d4e 100644 --- a/packages/effect/test/Queue.test.ts +++ b/packages/effect/test/Queue.test.ts @@ -1,5 +1,8 @@ import { assert, describe, it } from "@effect/vitest" -import { Effect, Exit, Fiber, Queue, Stream } from "effect" +import { Effect, Exit } from "effect" +import { Queue } from "effect/concurrency" +import { Fiber } from "effect/runtime" +import { Stream } from "effect/stream" describe("Queue", () => { it.effect("offerAll with capacity", () => diff --git a/packages/effect/test/RcMap.test.ts b/packages/effect/test/RcMap.test.ts index a6fb805b52..a7fe1ec01f 100644 --- a/packages/effect/test/RcMap.test.ts +++ b/packages/effect/test/RcMap.test.ts @@ -1,5 +1,8 @@ import { assert, describe, it } from "@effect/vitest" -import { Cause, Data, Effect, Exit, RcMap, Scope, TestClock } from "effect" +import { Cause, Effect, Exit } from "effect" +import { Data } from "effect/data" +import { RcMap, Scope } from "effect/resources" +import { TestClock } from "effect/testing" describe("RcMap", () => { it.effect("deallocation", () => diff --git a/packages/effect/test/RcRef.test.ts b/packages/effect/test/RcRef.test.ts index f55506813f..c3bd4ff8d5 100644 --- a/packages/effect/test/RcRef.test.ts +++ b/packages/effect/test/RcRef.test.ts @@ -1,8 +1,8 @@ import { assert, describe, it } from "@effect/vitest" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as RcRef from "effect/RcRef" -import * as Scope from "effect/Scope" +import * as RcRef from "effect/resources/RcRef" +import * as Scope from "effect/resources/Scope" describe("RcRef", () => { it.effect("deallocation", () => diff --git a/packages/effect/test/Record.test.ts b/packages/effect/test/Record.test.ts index 9a5e433baf..761f4247c1 100644 --- a/packages/effect/test/Record.test.ts +++ b/packages/effect/test/Record.test.ts @@ -1,4 +1,4 @@ -import { Record } from "effect" +import { Record } from "effect/data" import { describe, it } from "vitest" import { deepStrictEqual } from "./utils/assert.ts" diff --git a/packages/effect/test/Redacted.test.ts b/packages/effect/test/Redacted.test.ts index 4037f1b1c6..c97fe3b119 100644 --- a/packages/effect/test/Redacted.test.ts +++ b/packages/effect/test/Redacted.test.ts @@ -1,6 +1,8 @@ import { describe, it } from "@effect/vitest" import { assertFalse, assertTrue, strictEqual, throws } from "@effect/vitest/utils" -import { Chunk, Equal, Hash, Redacted } from "effect" +import { Chunk } from "effect/collections" +import { Redacted } from "effect/data" +import { Equal, Hash } from "effect/interfaces" describe("Redacted", () => { it("chunk constructor", () => { diff --git a/packages/effect/test/Ref.test.ts b/packages/effect/test/Ref.test.ts index 5aeb311265..506a9153b8 100644 --- a/packages/effect/test/Ref.test.ts +++ b/packages/effect/test/Ref.test.ts @@ -1,5 +1,7 @@ import { assert, describe, it } from "@effect/vitest" -import { Effect, Option, Ref } from "effect" +import { Effect } from "effect" +import { Ref } from "effect/concurrency" +import { Option } from "effect/data" const current = "value" const update = "new value" diff --git a/packages/effect/test/Result.test.ts b/packages/effect/test/Result.test.ts index 16d32acc21..258a7d66cc 100644 --- a/packages/effect/test/Result.test.ts +++ b/packages/effect/test/Result.test.ts @@ -1,4 +1,8 @@ -import { Cause, Chunk, Effect, Equal, flow, identity, Number as Num, Option, pipe, Result, String as Str } from "effect" +import { Cause, Effect, flow, identity, pipe } from "effect" +import { Chunk } from "effect/collections" +import { Option, Result } from "effect/data" +import { Equal } from "effect/interfaces" +import { Number as Num, String as Str } from "effect/primitives" import { inspect } from "node:util" import { describe, it } from "vitest" import { diff --git a/packages/effect/test/Schedule.test.ts b/packages/effect/test/Schedule.test.ts index 497924b1a5..abc4d7eae0 100644 --- a/packages/effect/test/Schedule.test.ts +++ b/packages/effect/test/Schedule.test.ts @@ -1,6 +1,12 @@ import { describe, expect, it } from "@effect/vitest" -import { Array, Duration, Effect, Fiber, Pull, Schedule, TestClock } from "effect" +import { Effect } from "effect" +import { Array } from "effect/collections" import { constant, constUndefined } from "effect/Function" +import { Fiber } from "effect/runtime" +import { Schedule } from "effect/scheduling" +import { Pull } from "effect/stream" +import { TestClock } from "effect/testing" +import { Duration } from "effect/time" describe("Schedule", () => { describe("collecting", () => { diff --git a/packages/effect/test/Scope.test.ts b/packages/effect/test/Scope.test.ts index 30919b1a35..455118dfc5 100644 --- a/packages/effect/test/Scope.test.ts +++ b/packages/effect/test/Scope.test.ts @@ -1,5 +1,8 @@ import { describe, expect, it } from "@effect/vitest" -import { Duration, Effect, Exit, Scope, TestClock } from "effect" +import { Effect, Exit } from "effect" +import { Scope } from "effect/resources" +import { TestClock } from "effect/testing" +import { Duration } from "effect/time" describe("Scope", () => { describe("parallel finalization", () => { diff --git a/packages/effect/test/Stream.test.ts b/packages/effect/test/Stream.test.ts index 2e9747776f..a93d047fd2 100644 --- a/packages/effect/test/Stream.test.ts +++ b/packages/effect/test/Stream.test.ts @@ -1,5 +1,9 @@ import { assert, describe, it } from "@effect/vitest" -import { Effect, Exit, Fiber, Option, Queue, Stream } from "effect" +import { Effect, Exit } from "effect" +import { Queue } from "effect/concurrency" +import { Option } from "effect/data" +import { Fiber } from "effect/runtime" +import { Stream } from "effect/stream" describe("Stream", () => { describe("callback", () => { diff --git a/packages/effect/test/Struct.test.ts b/packages/effect/test/Struct.test.ts index ee5feabcb1..a239c95821 100644 --- a/packages/effect/test/Struct.test.ts +++ b/packages/effect/test/Struct.test.ts @@ -1,4 +1,6 @@ -import { Equivalence, pipe, String as Str, Struct } from "effect" +import { pipe } from "effect" +import { Equivalence, Struct } from "effect/data" +import { String as Str } from "effect/primitives" import { Schema } from "effect/schema" import { describe, it } from "vitest" import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "./utils/assert.ts" diff --git a/packages/effect/test/TestClock.test.ts b/packages/effect/test/TestClock.test.ts index f79264b67f..66ba391d74 100644 --- a/packages/effect/test/TestClock.test.ts +++ b/packages/effect/test/TestClock.test.ts @@ -1,8 +1,8 @@ import { assert, describe, it } from "@effect/vitest" -import * as Duration from "effect/Duration" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as TestClock from "effect/TestClock" +import * as TestClock from "effect/testing/TestClock" +import * as Duration from "effect/time/Duration" describe("TestClock", () => { it.effect("sleep - does not require passage of wall time", () => diff --git a/packages/effect/test/Tuple.test.ts b/packages/effect/test/Tuple.test.ts index af2d490bfe..8d09449584 100644 --- a/packages/effect/test/Tuple.test.ts +++ b/packages/effect/test/Tuple.test.ts @@ -1,4 +1,5 @@ -import { pipe, Tuple } from "effect" +import { pipe } from "effect" +import { Tuple } from "effect/data" import { Schema } from "effect/schema" import { describe, it } from "vitest" import { deepStrictEqual, strictEqual } from "./utils/assert.ts" diff --git a/packages/effect/test/TxChunk.test.ts b/packages/effect/test/TxChunk.test.ts index ecebd1dad2..cdc922d192 100644 --- a/packages/effect/test/TxChunk.test.ts +++ b/packages/effect/test/TxChunk.test.ts @@ -1,4 +1,6 @@ -import { Chunk, Effect, TxChunk } from "effect" +import { Effect } from "effect" +import { Chunk } from "effect/collections" +import { TxChunk } from "effect/transactions" import { describe, expect, it } from "vitest" describe("TxChunk", () => { diff --git a/packages/effect/test/TxHashMap.test.ts b/packages/effect/test/TxHashMap.test.ts index 074385d74b..ff94ba7b95 100644 --- a/packages/effect/test/TxHashMap.test.ts +++ b/packages/effect/test/TxHashMap.test.ts @@ -1,9 +1,9 @@ import { assert, describe, it } from "@effect/vitest" +import { HashMap } from "effect/collections" +import { Option } from "effect/data" import * as Effect from "effect/Effect" -import * as Hash from "effect/Hash" -import * as HashMap from "effect/HashMap" -import * as Option from "effect/Option" -import * as TxHashMap from "effect/TxHashMap" +import { Hash } from "effect/interfaces" +import { TxHashMap } from "effect/transactions" describe("TxHashMap", () => { describe("constructors", () => { diff --git a/packages/effect/test/TxHashSet.test.ts b/packages/effect/test/TxHashSet.test.ts index 342242ac0c..9538bc9246 100644 --- a/packages/effect/test/TxHashSet.test.ts +++ b/packages/effect/test/TxHashSet.test.ts @@ -1,9 +1,8 @@ import { assert, describe, it } from "@effect/vitest" +import { HashSet } from "effect/collections" import * as Effect from "effect/Effect" -import * as Equal from "effect/Equal" -import * as Hash from "effect/Hash" -import * as HashSet from "effect/HashSet" -import * as TxHashSet from "effect/TxHashSet" +import { Equal, Hash } from "effect/interfaces" +import { TxHashSet } from "effect/transactions" class TestValue implements Equal.Equal { constructor(readonly value: string) {} diff --git a/packages/effect/test/TxQueue.test.ts b/packages/effect/test/TxQueue.test.ts index b4b88d46c9..c633c12668 100644 --- a/packages/effect/test/TxQueue.test.ts +++ b/packages/effect/test/TxQueue.test.ts @@ -1,10 +1,10 @@ import { assert, describe, it } from "@effect/vitest" import * as Cause from "effect/Cause" -import * as Chunk from "effect/Chunk" +import { Chunk } from "effect/collections" +import { Option } from "effect/data" import * as Effect from "effect/Effect" -import * as Fiber from "effect/Fiber" -import * as Option from "effect/Option" -import * as TxQueue from "effect/TxQueue" +import { Fiber } from "effect/runtime" +import { TxQueue } from "effect/transactions" describe("TxQueue", () => { describe("interfaces", () => { diff --git a/packages/effect/test/TxSemaphore.test.ts b/packages/effect/test/TxSemaphore.test.ts index ec794f2d2f..31833060f4 100644 --- a/packages/effect/test/TxSemaphore.test.ts +++ b/packages/effect/test/TxSemaphore.test.ts @@ -1,8 +1,8 @@ import { assert, describe, it } from "@effect/vitest" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import * as TxSemaphore from "effect/TxSemaphore" +import { Fiber } from "effect/runtime" +import * as TxSemaphore from "effect/transactions/TxSemaphore" describe("TxSemaphore", () => { describe("constructors", () => { diff --git a/packages/effect/test/batching/Request.test.ts b/packages/effect/test/batching/Request.test.ts index 71bf7e6126..ac78d85396 100644 --- a/packages/effect/test/batching/Request.test.ts +++ b/packages/effect/test/batching/Request.test.ts @@ -1,14 +1,14 @@ import { assert, describe, expect, it } from "@effect/vitest" -import * as Array from "effect/Array" import * as Request from "effect/batching/Request" import * as Resolver from "effect/batching/RequestResolver" import * as Cause from "effect/Cause" -import * as Data from "effect/Data" +import { Array } from "effect/collections" +import { Data } from "effect/data" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" import { flow, pipe } from "effect/Function" -import * as ServiceMap from "effect/ServiceMap" +import { Fiber } from "effect/runtime" +import { ServiceMap } from "effect/services" class Counter extends ServiceMap.Key()("Counter") {} class Requests extends ServiceMap.Key()("Requests") {} diff --git a/packages/effect/test/caching/Cache.test.ts b/packages/effect/test/caching/Cache.test.ts index 1a8d28299c..5835a55df7 100644 --- a/packages/effect/test/caching/Cache.test.ts +++ b/packages/effect/test/caching/Cache.test.ts @@ -1,14 +1,13 @@ import { assert, describe, it } from "@effect/vitest" import { Cache } from "effect/caching" -import * as Data from "effect/Data" -import * as Deferred from "effect/Deferred" -import * as Duration from "effect/Duration" +import { Deferred } from "effect/concurrency" +import { Data, Option } from "effect/data" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import * as Option from "effect/Option" -import * as ServiceMap from "effect/ServiceMap" -import * as TestClock from "effect/TestClock" +import { Fiber } from "effect/runtime" +import { ServiceMap } from "effect/services" +import { TestClock } from "effect/testing" +import { Duration } from "effect/time" describe("Cache", () => { describe("constructors", () => { diff --git a/packages/effect/test/config/Config.test.ts b/packages/effect/test/config/Config.test.ts index 743795e346..e55dc7d6cc 100644 --- a/packages/effect/test/config/Config.test.ts +++ b/packages/effect/test/config/Config.test.ts @@ -1,8 +1,10 @@ import { describe, it } from "@effect/vitest" import { assertFailure, assertSuccess, deepStrictEqual, strictEqual } from "@effect/vitest/utils" -import type { LogLevel } from "effect" -import { Brand, Cause, DateTime, Duration, Effect, Filter, Option, pipe, Redacted } from "effect" +import { Cause, Effect, pipe } from "effect" import { Config, ConfigError, ConfigProvider } from "effect/config" +import { Brand, Filter, Option, Redacted } from "effect/data" +import type { LogLevel } from "effect/logging" +import { DateTime, Duration } from "effect/time" type Str = Brand.Branded const Str = Brand.refined( diff --git a/packages/effect/test/config/ConfigProvider.test.ts b/packages/effect/test/config/ConfigProvider.test.ts index 2535c7e7b5..90a9c7009f 100644 --- a/packages/effect/test/config/ConfigProvider.test.ts +++ b/packages/effect/test/config/ConfigProvider.test.ts @@ -1,8 +1,10 @@ import { assert, describe, it } from "@effect/vitest" -import { Effect, Layer, Redacted } from "effect" +import { Effect } from "effect" import { Config, ConfigProvider } from "effect/config" +import { Redacted } from "effect/data" import { FileSystem, Path } from "effect/platform" import { SystemError } from "effect/platform/PlatformError" +import { Layer } from "effect/services" describe("ConfigProvider", () => { describe("fileTree", () => { diff --git a/packages/effect/test/http/Multipart.test.ts b/packages/effect/test/http/Multipart.test.ts index f8c2d8bc7f..86d2f1a9cb 100644 --- a/packages/effect/test/http/Multipart.test.ts +++ b/packages/effect/test/http/Multipart.test.ts @@ -1,6 +1,8 @@ import { describe, it } from "@effect/vitest" import { deepStrictEqual } from "@effect/vitest/utils" -import { Effect, identity, Stream, Unify } from "effect" +import { Effect, identity } from "effect" +import { Stream } from "effect/stream" +import { Unify } from "effect/types" import * as Multipart from "effect/unstable/http/Multipart" describe("Multipart", () => { diff --git a/packages/effect/test/schema/Formatter.test.ts b/packages/effect/test/schema/Formatter.test.ts index 71dddc4100..e39c445d96 100644 --- a/packages/effect/test/schema/Formatter.test.ts +++ b/packages/effect/test/schema/Formatter.test.ts @@ -1,4 +1,5 @@ -import { Effect, Option } from "effect" +import { Effect } from "effect" +import { Option } from "effect/data" import type { AST } from "effect/schema" import { Check, Formatter, Getter, Issue, Schema, ToParser } from "effect/schema" import { describe, it } from "vitest" @@ -22,19 +23,19 @@ const assertStructuredIssue = async ( } describe("makeTree", () => { - it("should use the id annotation if present", async () => { + it("should use the identifier annotation if present", async () => { await assertions.decoding.fail( - Schema.String.annotate({ id: "id" }), + Schema.String.annotate({ identifier: "id" }), null, `Expected id, actual null` ) await assertions.decoding.fail( - Schema.NonEmptyString.annotate({ id: "id" }), + Schema.NonEmptyString.annotate({ identifier: "id" }), null, `Expected id, actual null` ) await assertions.decoding.fail( - Schema.String.check(Check.nonEmpty({ id: "id" })), + Schema.String.check(Check.nonEmpty({ identifier: "id" })), null, `Expected id, actual null` ) @@ -55,7 +56,7 @@ describe("makeTree", () => { name: Schema.String, totalPrice: Schema.Number }).annotate({ - id: "Order", + identifier: "Order", formatter: { Tree: { getTitle: getOrderId diff --git a/packages/effect/test/schema/Schema.test.ts b/packages/effect/test/schema/Schema.test.ts index 754711ec83..3075888f27 100644 --- a/packages/effect/test/schema/Schema.test.ts +++ b/packages/effect/test/schema/Schema.test.ts @@ -1,18 +1,9 @@ -import { - BigInt, - Effect, - Equal, - flow, - Option, - Order, - pipe, - Predicate, - ServiceMap, - String as Str, - Struct, - Tuple -} from "effect" +import { Effect, flow, pipe } from "effect" +import { Option, Order, Predicate, Struct, Tuple } from "effect/data" +import { Equal } from "effect/interfaces" +import { BigInt, String as Str } from "effect/primitives" import { AST, Check, Getter, Issue, Schema, ToParser, Transformation } from "effect/schema" +import { ServiceMap } from "effect/services" import { produce } from "immer" import { describe, it } from "vitest" import { assertFalse, assertInclude, assertTrue, deepStrictEqual, strictEqual, throws } from "../utils/assert.ts" @@ -3869,8 +3860,8 @@ describe("Schema", () => { assertTrue(Schema.isSchema(A)) // should expose the fields deepStrictEqual(A.fields, { a: Schema.String }) - // should expose the id - strictEqual(A.id, "A") + // should expose the identifier + strictEqual(A.identifier, "A") strictEqual(A.name, "A") @@ -3922,8 +3913,8 @@ describe("Schema", () => { assertTrue(Schema.isSchema(A)) // should expose the fields deepStrictEqual(A.fields, { a: Schema.String }) - // should expose the id - strictEqual(A.id, "A") + // should expose the identifier + strictEqual(A.identifier, "A") strictEqual(A.name, "A") @@ -3976,8 +3967,8 @@ describe("Schema", () => { assertTrue(Schema.isSchema(A)) // should expose the fields deepStrictEqual(A.fields, { a: Schema.String }) - // should expose the id - strictEqual(A.id, "A") + // should expose the identifier + strictEqual(A.identifier, "A") assertions.formatter.formatAST(A, `A`) @@ -4029,8 +4020,8 @@ describe("Schema", () => { assertTrue(Schema.isSchema(A)) // should expose the fields deepStrictEqual(A.fields, { a: Schema.String }) - // should expose the id - strictEqual(A.id, "A") + // should expose the identifier + strictEqual(A.identifier, "A") assertions.formatter.formatAST(A, `A & `) diff --git a/packages/effect/test/schema/Serializer.test.ts b/packages/effect/test/schema/Serializer.test.ts index 7ec3eaaa29..5c17f10057 100644 --- a/packages/effect/test/schema/Serializer.test.ts +++ b/packages/effect/test/schema/Serializer.test.ts @@ -1,4 +1,4 @@ -import { Option } from "effect" +import { Option } from "effect/data" import { Schema, Serializer, Transformation } from "effect/schema" import { describe, it } from "vitest" import { strictEqual } from "../utils/assert.ts" diff --git a/packages/effect/test/schema/ToEquivalence.test.ts b/packages/effect/test/schema/ToEquivalence.test.ts index b0c9b9fbd1..b363f29494 100644 --- a/packages/effect/test/schema/ToEquivalence.test.ts +++ b/packages/effect/test/schema/ToEquivalence.test.ts @@ -1,4 +1,4 @@ -import { Equivalence, Option } from "effect" +import { Equivalence, Option } from "effect/data" import { Schema, ToEquivalence } from "effect/schema" import { describe, it } from "vitest" import { assertFalse, assertTrue } from "../utils/assert.ts" diff --git a/packages/effect/test/schema/ToJsonSchema.test.ts b/packages/effect/test/schema/ToJsonSchema.test.ts index 592e5e123e..f48055817d 100644 --- a/packages/effect/test/schema/ToJsonSchema.test.ts +++ b/packages/effect/test/schema/ToJsonSchema.test.ts @@ -956,7 +956,7 @@ describe("ToJsonSchema", () => { } const schema = Schema.Struct({ a: Schema.String, - as: Schema.Array(Schema.suspend((): Schema.Codec => schema.annotate({ id: "A" }))) + as: Schema.Array(Schema.suspend((): Schema.Codec => schema.annotate({ identifier: "A" }))) }) assertDraft7(schema, { "$defs": { @@ -1007,7 +1007,7 @@ describe("ToJsonSchema", () => { } const schema = Schema.Struct({ a: Schema.String, - as: Schema.Array(Schema.suspend((): Schema.Codec => schema).annotate({ id: "A" })) + as: Schema.Array(Schema.suspend((): Schema.Codec => schema).annotate({ identifier: "A" })) }) assertDraft7(schema, { "$defs": { @@ -1059,7 +1059,7 @@ describe("ToJsonSchema", () => { const schema = Schema.Struct({ a: Schema.String, as: Schema.Array(Schema.suspend((): Schema.Codec => schema)) - }).annotate({ id: "A" }) + }).annotate({ identifier: "A" }) assertDraft7(schema, { "$ref": "#/$defs/A", "$defs": { @@ -1094,7 +1094,7 @@ describe("ToJsonSchema", () => { const schema = Schema.Struct({ a: Schema.String, as: Schema.Array(Schema.suspend((): Schema.Codec => schema)) - }).annotate({ id: "A" }) + }).annotate({ identifier: "A" }) assertDraft7(schema, { "type": "object", "properties": { @@ -1157,9 +1157,9 @@ describe("ToJsonSchema", () => { }) }) - describe("id", () => { + describe("identifier", () => { it(`topLevelReferenceStrategy: "skip"`, () => { - const schema = Schema.String.annotate({ id: "A" }) + const schema = Schema.String.annotate({ identifier: "A" }) assertDraft7(schema, { "type": "string" }, { @@ -1169,7 +1169,7 @@ describe("ToJsonSchema", () => { describe(`topLevelReferenceStrategy: "keep" (default)`, () => { it(`String & annotation`, () => { - const schema = Schema.String.annotate({ id: "A" }) + const schema = Schema.String.annotate({ identifier: "A" }) assertDraft7(schema, { "$ref": "#/$defs/A", "$defs": { @@ -1181,7 +1181,7 @@ describe("ToJsonSchema", () => { }) it(`String & annotation & check`, () => { - const schema = Schema.String.annotate({ id: "A" }).check(Check.nonEmpty()) + const schema = Schema.String.annotate({ identifier: "A" }).check(Check.nonEmpty()) assertDraft7(schema, { "type": "string", "description": "a value with a length of at least 1", @@ -1191,7 +1191,7 @@ describe("ToJsonSchema", () => { }) it(`String & annotation & check & annotation`, () => { - const schema = Schema.String.annotate({ id: "A" }).check(Check.nonEmpty({ id: "B" })) + const schema = Schema.String.annotate({ identifier: "A" }).check(Check.nonEmpty({ identifier: "B" })) assertDraft7(schema, { "$ref": "#/$defs/B", "$defs": { @@ -1206,8 +1206,8 @@ describe("ToJsonSchema", () => { }) it(`String & annotation & check & annotation & check`, () => { - const schema = Schema.String.annotate({ id: "A" }).check( - Check.nonEmpty({ id: "B" }), + const schema = Schema.String.annotate({ identifier: "A" }).check( + Check.nonEmpty({ identifier: "B" }), Check.maxLength(2) ) assertDraft7(schema, { diff --git a/packages/effect/test/schema/ToPretty.test.ts b/packages/effect/test/schema/ToPretty.test.ts index e4156c68ea..3364bb31ac 100644 --- a/packages/effect/test/schema/ToPretty.test.ts +++ b/packages/effect/test/schema/ToPretty.test.ts @@ -1,4 +1,4 @@ -import { Option } from "effect" +import { Option } from "effect/data" import { Schema, ToPretty } from "effect/schema" import { describe, it } from "vitest" import { strictEqual } from "../utils/assert.ts" diff --git a/packages/effect/test/schema/standardSchemaV1.test.ts b/packages/effect/test/schema/standardSchemaV1.test.ts index 5fa2b01cfc..758b6cbd5e 100644 --- a/packages/effect/test/schema/standardSchemaV1.test.ts +++ b/packages/effect/test/schema/standardSchemaV1.test.ts @@ -1,6 +1,8 @@ import { assertTrue, deepStrictEqual, strictEqual } from "@effect/vitest/utils" -import { Effect, Option, ServiceMap } from "effect" +import { Effect } from "effect" +import { Option } from "effect/data" import { Check, Getter, Schema } from "effect/schema" +import { ServiceMap } from "effect/services" import { describe, it } from "vitest" import { standard } from "../utils/schema.ts" diff --git a/packages/effect/test/utils/assert.ts b/packages/effect/test/utils/assert.ts index dd11ceb628..350df6cbbb 100644 --- a/packages/effect/test/utils/assert.ts +++ b/packages/effect/test/utils/assert.ts @@ -1,5 +1,7 @@ import type { Cause } from "effect" -import { Equal, Exit, Option, Predicate, Result } from "effect" +import { Option, Predicate, Result } from "effect/data" +import * as Exit from "effect/Exit" +import { Equal } from "effect/interfaces" import * as assert from "node:assert" import { assert as vassert } from "vitest" diff --git a/packages/effect/test/utils/schema.ts b/packages/effect/test/utils/schema.ts index 7fe429b58a..9e3e86ff06 100644 --- a/packages/effect/test/utils/schema.ts +++ b/packages/effect/test/utils/schema.ts @@ -1,7 +1,9 @@ import type { StandardSchemaV1 } from "@standard-schema/spec" -import type { ServiceMap } from "effect" -import { Effect, FastCheck, Predicate, Record, Result } from "effect" +import { Effect } from "effect" +import { Predicate, Record, Result } from "effect/data" import { AST, Formatter, Issue, Schema, Serializer, ToArbitrary, ToParser } from "effect/schema" +import type { ServiceMap } from "effect/services" +import { FastCheck } from "effect/testing" import { deepStrictEqual, fail, strictEqual, throws } from "./assert.ts" export const assertions = make({ diff --git a/packages/platform-bun/src/BunFileSystem.ts b/packages/platform-bun/src/BunFileSystem.ts index 660aaceb55..0312d494c2 100644 --- a/packages/platform-bun/src/BunFileSystem.ts +++ b/packages/platform-bun/src/BunFileSystem.ts @@ -2,11 +2,11 @@ * @since 1.0.0 */ import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem" -import type { Layer } from "effect/Layer" import type { FileSystem } from "effect/platform/FileSystem" +import type * as Layer from "effect/services/Layer" /** * @since 1.0.0 * @category layer */ -export const layer: Layer = NodeFileSystem.layer +export const layer: Layer.Layer = NodeFileSystem.layer diff --git a/packages/platform-bun/src/BunHttpPlatform.ts b/packages/platform-bun/src/BunHttpPlatform.ts index 34a303850e..8c4a4b8469 100644 --- a/packages/platform-bun/src/BunHttpPlatform.ts +++ b/packages/platform-bun/src/BunHttpPlatform.ts @@ -2,8 +2,8 @@ * @since 1.0.0 */ import type { Effect } from "effect" -import * as Layer from "effect/Layer" import type { FileSystem } from "effect/platform/FileSystem" +import * as Layer from "effect/services/Layer" import * as Etag from "effect/unstable/http/Etag" import * as Platform from "effect/unstable/http/HttpPlatform" import * as Response from "effect/unstable/http/HttpServerResponse" diff --git a/packages/platform-bun/src/BunHttpServer.ts b/packages/platform-bun/src/BunHttpServer.ts index 62008ccc5c..fd5199d5e9 100644 --- a/packages/platform-bun/src/BunHttpServer.ts +++ b/packages/platform-bun/src/BunHttpServer.ts @@ -2,22 +2,22 @@ * @since 1.0.0 */ import type { Server as BunServer, ServerWebSocket } from "bun" +import * as Deferred from "effect/concurrency/Deferred" +import * as FiberSet from "effect/concurrency/FiberSet" import * as Config from "effect/config/Config" import type { ConfigError } from "effect/config/ConfigError" -import * as Deferred from "effect/Deferred" +import * as Option from "effect/data/Option" +import type * as Record from "effect/data/Record" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" -import * as FiberSet from "effect/FiberSet" -import * as Inspectable from "effect/Inspectable" -import * as Layer from "effect/Layer" -import * as Option from "effect/Option" +import * as Inspectable from "effect/interfaces/Inspectable" import type * as FileSystem from "effect/platform/FileSystem" import type * as Path from "effect/platform/Path" -import type { ReadonlyRecord } from "effect/Record" -import type * as Scope from "effect/Scope" -import * as ServiceMap from "effect/ServiceMap" -import * as Stream from "effect/Stream" +import type * as Scope from "effect/resources/Scope" +import * as Fiber from "effect/runtime/Fiber" +import * as Layer from "effect/services/Layer" +import * as ServiceMap from "effect/services/ServiceMap" +import * as Stream from "effect/stream/Stream" import * as Cookies from "effect/unstable/http/Cookies" import * as Etag from "effect/unstable/http/Etag" import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient" @@ -337,7 +337,7 @@ class BunServerRequest extends Inspectable.Class implements ServerRequest.HttpSe return this.headersOverride } - private cachedCookies: ReadonlyRecord | undefined + private cachedCookies: Record.ReadonlyRecord | undefined get cookies() { if (this.cachedCookies) { return this.cachedCookies diff --git a/packages/platform-bun/src/BunMultipart.ts b/packages/platform-bun/src/BunMultipart.ts index e13e9e5ea9..38ae549682 100644 --- a/packages/platform-bun/src/BunMultipart.ts +++ b/packages/platform-bun/src/BunMultipart.ts @@ -4,8 +4,8 @@ import type * as Effect from "effect/Effect" import type { FileSystem } from "effect/platform/FileSystem" import type { Path } from "effect/platform/Path" -import type * as Scope from "effect/Scope" -import * as Stream from "effect/Stream" +import type * as Scope from "effect/resources/Scope" +import * as Stream from "effect/stream/Stream" import * as Multipart from "effect/unstable/http/Multipart" import * as BunStream from "./BunStream.ts" diff --git a/packages/platform-bun/src/BunPath.ts b/packages/platform-bun/src/BunPath.ts index 21668400f5..da71d3e9f4 100644 --- a/packages/platform-bun/src/BunPath.ts +++ b/packages/platform-bun/src/BunPath.ts @@ -2,23 +2,23 @@ * @since 1.0.0 */ import * as NodePath from "@effect/platform-node-shared/NodePath" -import type { Layer } from "effect/Layer" import type { Path } from "effect/platform/Path" +import type * as Layer from "effect/services/Layer" /** * @since 1.0.0 * @category layer */ -export const layer: Layer = NodePath.layer +export const layer: Layer.Layer = NodePath.layer /** * @since 1.0.0 * @category layer */ -export const layerPosix: Layer = NodePath.layerPosix +export const layerPosix: Layer.Layer = NodePath.layerPosix /** * @since 1.0.0 * @category layer */ -export const layerWin32: Layer = NodePath.layerWin32 +export const layerWin32: Layer.Layer = NodePath.layerWin32 diff --git a/packages/platform-bun/src/BunRuntime.ts b/packages/platform-bun/src/BunRuntime.ts index c1156ee6ab..14212f1684 100644 --- a/packages/platform-bun/src/BunRuntime.ts +++ b/packages/platform-bun/src/BunRuntime.ts @@ -3,7 +3,7 @@ */ import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime" import type { Effect } from "effect/Effect" -import type { Teardown } from "effect/Runtime" +import type { Teardown } from "effect/runtime/Runtime" /** * Helps you run a main effect with built-in error handling, logging, and signal management. diff --git a/packages/platform-bun/src/BunServices.ts b/packages/platform-bun/src/BunServices.ts index ae32c97dd4..aed9c9581f 100644 --- a/packages/platform-bun/src/BunServices.ts +++ b/packages/platform-bun/src/BunServices.ts @@ -1,9 +1,9 @@ /** * @since 1.0.0 */ -import * as Layer from "effect/Layer" import type { FileSystem } from "effect/platform/FileSystem" import type { Path } from "effect/platform/Path" +import * as Layer from "effect/services/Layer" import * as NodeFileSystem from "./BunFileSystem.ts" import * as NodePath from "./BunPath.ts" diff --git a/packages/platform-bun/src/BunSocket.ts b/packages/platform-bun/src/BunSocket.ts index 2598f5791a..8f90474bde 100644 --- a/packages/platform-bun/src/BunSocket.ts +++ b/packages/platform-bun/src/BunSocket.ts @@ -1,7 +1,7 @@ /** * @since 1.0.0 */ -import * as Layer from "effect/Layer" +import * as Layer from "effect/services/Layer" import * as Socket from "effect/unstable/socket/Socket" /** diff --git a/packages/platform-bun/src/BunStream.ts b/packages/platform-bun/src/BunStream.ts index 5e613ac5e1..30f1272b8c 100644 --- a/packages/platform-bun/src/BunStream.ts +++ b/packages/platform-bun/src/BunStream.ts @@ -2,13 +2,13 @@ * @since 1.0.0 */ -import * as Arr from "effect/Array" -import * as Channel from "effect/Channel" +import * as Arr from "effect/collections/Array" import * as Effect from "effect/Effect" import type { LazyArg } from "effect/Function" -import * as Pull from "effect/Pull" -import * as Scope from "effect/Scope" -import * as Stream from "effect/Stream" +import * as Scope from "effect/resources/Scope" +import * as Channel from "effect/stream/Channel" +import * as Pull from "effect/stream/Pull" +import * as Stream from "effect/stream/Stream" /** * @since 1.0.0 diff --git a/packages/platform-node-shared/src/NodeFileSystem.ts b/packages/platform-node-shared/src/NodeFileSystem.ts index a30b2b2c86..de93f2a6a2 100644 --- a/packages/platform-node-shared/src/NodeFileSystem.ts +++ b/packages/platform-node-shared/src/NodeFileSystem.ts @@ -1,16 +1,16 @@ /** * @since 1.0.0 */ +import * as Queue from "effect/concurrency/Queue" +import * as Option from "effect/data/Option" import * as Effect from "effect/Effect" import { effectify } from "effect/Effect" import * as Exit from "effect/Exit" import { pipe } from "effect/Function" -import * as Layer from "effect/Layer" -import * as Option from "effect/Option" import * as FileSystem from "effect/platform/FileSystem" import * as Error from "effect/platform/PlatformError" -import * as Queue from "effect/Queue" -import * as Stream from "effect/Stream" +import * as Layer from "effect/services/Layer" +import * as Stream from "effect/stream/Stream" import * as Crypto from "node:crypto" import * as NFS from "node:fs" import * as OS from "node:os" diff --git a/packages/platform-node-shared/src/NodePath.ts b/packages/platform-node-shared/src/NodePath.ts index a567a016c8..25f78501b2 100644 --- a/packages/platform-node-shared/src/NodePath.ts +++ b/packages/platform-node-shared/src/NodePath.ts @@ -2,9 +2,9 @@ * @since 1.0.0 */ import * as Effect from "effect/Effect" -import * as Layer from "effect/Layer" import { Path, TypeId } from "effect/platform/Path" import { BadArgument } from "effect/platform/PlatformError" +import * as Layer from "effect/services/Layer" import * as NodePath from "node:path" import * as NodeUrl from "node:url" diff --git a/packages/platform-node-shared/src/NodeRuntime.ts b/packages/platform-node-shared/src/NodeRuntime.ts index 5a66e30be4..59eaa8c6bb 100644 --- a/packages/platform-node-shared/src/NodeRuntime.ts +++ b/packages/platform-node-shared/src/NodeRuntime.ts @@ -2,8 +2,7 @@ * @since 1.0.0 */ import type { Effect } from "effect/Effect" -import type { Teardown } from "effect/Runtime" -import { makeRunMain } from "effect/Runtime" +import * as Runtime from "effect/runtime/Runtime" /** * @since 1.0.0 @@ -11,13 +10,19 @@ import { makeRunMain } from "effect/Runtime" */ export const runMain: { ( - options?: { readonly disableErrorReporting?: boolean | undefined; readonly teardown?: Teardown | undefined } + options?: { + readonly disableErrorReporting?: boolean | undefined + readonly teardown?: Runtime.Teardown | undefined + } ): (effect: Effect) => void ( effect: Effect, - options?: { readonly disableErrorReporting?: boolean | undefined; readonly teardown?: Teardown | undefined } + options?: { + readonly disableErrorReporting?: boolean | undefined + readonly teardown?: Runtime.Teardown | undefined + } ): void -} = makeRunMain(({ +} = Runtime.makeRunMain(({ fiber, teardown }) => { diff --git a/packages/platform-node-shared/src/NodeSink.ts b/packages/platform-node-shared/src/NodeSink.ts index d27787b3d8..5728d6880b 100644 --- a/packages/platform-node-shared/src/NodeSink.ts +++ b/packages/platform-node-shared/src/NodeSink.ts @@ -1,14 +1,14 @@ /** * @since 1.0.0 */ -import type { NonEmptyReadonlyArray } from "effect/Array" -import * as Channel from "effect/Channel" +import type { NonEmptyReadonlyArray } from "effect/collections/Array" import * as Effect from "effect/Effect" import { identity, type LazyArg } from "effect/Function" import type { PlatformError } from "effect/platform/PlatformError" import { SystemError } from "effect/platform/PlatformError" -import * as Pull from "effect/Pull" -import * as Sink from "effect/Sink" +import * as Channel from "effect/stream/Channel" +import * as Pull from "effect/stream/Pull" +import * as Sink from "effect/stream/Sink" import type { Writable } from "node:stream" /** diff --git a/packages/platform-node-shared/src/NodeSocket.ts b/packages/platform-node-shared/src/NodeSocket.ts index 41a68afe6c..0f342424eb 100644 --- a/packages/platform-node-shared/src/NodeSocket.ts +++ b/packages/platform-node-shared/src/NodeSocket.ts @@ -1,14 +1,14 @@ /** * @since 1.0.0 */ -import type { NonEmptyReadonlyArray } from "effect/Array" -import * as Channel from "effect/Channel" -import * as Deferred from "effect/Deferred" +import type { Array } from "effect/collections" +import * as Deferred from "effect/concurrency/Deferred" +import * as FiberSet from "effect/concurrency/FiberSet" import * as Effect from "effect/Effect" -import * as FiberSet from "effect/FiberSet" -import * as Layer from "effect/Layer" -import * as Scope from "effect/Scope" -import * as ServiceMap from "effect/ServiceMap" +import * as Scope from "effect/resources/Scope" +import * as Layer from "effect/services/Layer" +import * as ServiceMap from "effect/services/ServiceMap" +import * as Channel from "effect/stream/Channel" import * as Socket from "effect/unstable/socket/Socket" import * as Net from "node:net" import type { Duplex } from "node:stream" @@ -168,10 +168,10 @@ export const fromDuplex = ( export const makeNetChannel = ( options: Net.NetConnectOpts ): Channel.Channel< - NonEmptyReadonlyArray, + Array.NonEmptyReadonlyArray, Socket.SocketError | IE, void, - NonEmptyReadonlyArray, + Array.NonEmptyReadonlyArray, IE > => Channel.unwrap( diff --git a/packages/platform-node-shared/src/NodeSocketServer.ts b/packages/platform-node-shared/src/NodeSocketServer.ts index 7882d3f146..30a8f5cd0f 100644 --- a/packages/platform-node-shared/src/NodeSocketServer.ts +++ b/packages/platform-node-shared/src/NodeSocketServer.ts @@ -2,14 +2,14 @@ * @since 1.0.0 */ import type { Cause } from "effect/Cause" +import * as FiberSet from "effect/concurrency/FiberSet" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as FiberSet from "effect/FiberSet" import { pipe } from "effect/Function" -import * as Layer from "effect/Layer" -import { UnhandledLogLevel } from "effect/References" -import * as Scope from "effect/Scope" -import * as ServiceMap from "effect/ServiceMap" +import * as Scope from "effect/resources/Scope" +import * as Layer from "effect/services/Layer" +import * as References from "effect/services/References" +import * as ServiceMap from "effect/services/ServiceMap" import * as Socket from "effect/unstable/socket/Socket" import * as SocketServer from "effect/unstable/socket/SocketServer" import type * as Http from "node:http" @@ -217,7 +217,7 @@ export const layerWebSocket = ( const reportUnhandledError = (cause: Cause) => Effect.withFiber((fiber) => { - const unhandledLogLevel = fiber.getRef(UnhandledLogLevel) + const unhandledLogLevel = fiber.getRef(References.UnhandledLogLevel) if (unhandledLogLevel._tag === "Some") { return Effect.logWithLevel(unhandledLogLevel.value)(cause, "Unhandled error in SocketServer") } diff --git a/packages/platform-node-shared/src/NodeStream.ts b/packages/platform-node-shared/src/NodeStream.ts index ee38e39f9a..19b0f319ca 100644 --- a/packages/platform-node-shared/src/NodeStream.ts +++ b/packages/platform-node-shared/src/NodeStream.ts @@ -1,20 +1,19 @@ /** * @since 1.0.0 */ -import type { NonEmptyReadonlyArray } from "effect/Array" -import * as Arr from "effect/Array" import * as Cause from "effect/Cause" -import * as Channel from "effect/Channel" +import * as Arr from "effect/collections/Array" +import * as MutableRef from "effect/concurrency/MutableRef" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as Fiber from "effect/Fiber" import { dual, type LazyArg } from "effect/Function" -import * as MutableRef from "effect/MutableRef" import type { SizeInput } from "effect/platform/FileSystem" -import * as Pull from "effect/Pull" -import * as Scope from "effect/Scope" -import * as ServiceMap from "effect/ServiceMap" -import * as Stream from "effect/Stream" +import * as Scope from "effect/resources/Scope" +import * as Fiber from "effect/runtime/Fiber" +import * as ServiceMap from "effect/services/ServiceMap" +import * as Channel from "effect/stream/Channel" +import * as Pull from "effect/stream/Pull" +import * as Stream from "effect/stream/Stream" import type { Duplex } from "node:stream" import { Readable } from "node:stream" import { pullIntoWritable } from "./NodeSink.ts" @@ -40,7 +39,7 @@ export const fromReadableChannel = (opti readonly onError?: (error: unknown) => E readonly chunkSize?: number | undefined readonly closeOnDone?: boolean | undefined -}): Channel.Channel, E> => +}): Channel.Channel, E> => Channel.fromTransform((_, scope) => unsafeReadableToPull({ scope, @@ -64,7 +63,7 @@ export const fromDuplex = , IE | E, void, NonEmptyReadonlyArray, IE> => +): Channel.Channel, IE | E, void, Arr.NonEmptyReadonlyArray, IE> => Channel.fromTransform((upstream, scope) => { const duplex = options.evaluate() const exit = MutableRef.make> | undefined>(undefined) diff --git a/packages/platform-node-shared/test/NodeFileSystem.test.ts b/packages/platform-node-shared/test/NodeFileSystem.test.ts index 2d03843ceb..31fd066fa4 100644 --- a/packages/platform-node-shared/test/NodeFileSystem.test.ts +++ b/packages/platform-node-shared/test/NodeFileSystem.test.ts @@ -1,9 +1,9 @@ import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem" import { assert, describe, expect, it } from "@effect/vitest" -import { Array } from "effect" +import { Array } from "effect/collections" import * as Effect from "effect/Effect" import * as Fs from "effect/platform/FileSystem" -import * as Stream from "effect/Stream" +import * as Stream from "effect/stream/Stream" const runPromise = (self: Effect.Effect) => Effect.runPromise( diff --git a/packages/platform-node-shared/test/NodeSink.test.ts b/packages/platform-node-shared/test/NodeSink.test.ts index 0fba5f7288..839bff67e5 100644 --- a/packages/platform-node-shared/test/NodeSink.test.ts +++ b/packages/platform-node-shared/test/NodeSink.test.ts @@ -1,10 +1,10 @@ import * as NodeSink from "@effect/platform-node-shared/NodeSink" import * as NodeStream from "@effect/platform-node-shared/NodeStream" import { assert, describe, it } from "@effect/vitest" -import { Queue } from "effect" -import * as Data from "effect/Data" -import * as Effect from "effect/Effect" -import * as Stream from "effect/Stream" +import { Effect } from "effect" +import * as Queue from "effect/concurrency/Queue" +import * as Data from "effect/data/Data" +import * as Stream from "effect/stream/Stream" import { createReadStream } from "fs" import { join } from "path" import { Writable } from "stream" diff --git a/packages/platform-node-shared/test/NodeStream.test.ts b/packages/platform-node-shared/test/NodeStream.test.ts index be6dcca6b0..8492db5344 100644 --- a/packages/platform-node-shared/test/NodeStream.test.ts +++ b/packages/platform-node-shared/test/NodeStream.test.ts @@ -1,7 +1,10 @@ import * as NodeStream from "@effect/platform-node-shared/NodeStream" import { assert, describe, it } from "@effect/vitest" -import { Array, Channel, Console, Stream } from "effect" -import * as Effect from "effect/Effect" +import { Effect } from "effect" +import * as Array from "effect/collections/Array" +import * as Console from "effect/logging/Console" +import * as Channel from "effect/stream/Channel" +import * as Stream from "effect/stream/Stream" import { Duplex, Readable, Transform } from "node:stream" import * as Zlib from "node:zlib" diff --git a/packages/platform-node/src/NodeFileSystem.ts b/packages/platform-node/src/NodeFileSystem.ts index 660aaceb55..a973e51a95 100644 --- a/packages/platform-node/src/NodeFileSystem.ts +++ b/packages/platform-node/src/NodeFileSystem.ts @@ -2,11 +2,11 @@ * @since 1.0.0 */ import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem" -import type { Layer } from "effect/Layer" import type { FileSystem } from "effect/platform/FileSystem" +import type * as Layer from "effect/services/Layer" /** * @since 1.0.0 * @category layer */ -export const layer: Layer = NodeFileSystem.layer +export const layer: Layer.Layer = NodeFileSystem.layer diff --git a/packages/platform-node/src/NodeHttpClient.ts b/packages/platform-node/src/NodeHttpClient.ts index ed2c598f3e..f25ac7c204 100644 --- a/packages/platform-node/src/NodeHttpClient.ts +++ b/packages/platform-node/src/NodeHttpClient.ts @@ -1,13 +1,13 @@ /** * @since 1.0.0 */ +import * as Option from "effect/data/Option" import * as Effect from "effect/Effect" -import * as Inspectable from "effect/Inspectable" -import * as Layer from "effect/Layer" -import * as Option from "effect/Option" -import type * as Scope from "effect/Scope" -import * as ServiceMap from "effect/ServiceMap" -import * as Stream from "effect/Stream" +import * as Inspectable from "effect/interfaces/Inspectable" +import type * as Scope from "effect/resources/Scope" +import * as Layer from "effect/services/Layer" +import * as ServiceMap from "effect/services/ServiceMap" +import * as Stream from "effect/stream/Stream" import * as Cookies from "effect/unstable/http/Cookies" import * as Headers from "effect/unstable/http/Headers" import type * as Body from "effect/unstable/http/HttpBody" diff --git a/packages/platform-node/src/NodeHttpIncomingMessage.ts b/packages/platform-node/src/NodeHttpIncomingMessage.ts index 1cd8f320c6..b859dc1700 100644 --- a/packages/platform-node/src/NodeHttpIncomingMessage.ts +++ b/packages/platform-node/src/NodeHttpIncomingMessage.ts @@ -1,10 +1,10 @@ /** * @since 1.0.0 */ +import * as Option from "effect/data/Option" import * as Effect from "effect/Effect" -import * as Inspectable from "effect/Inspectable" -import * as Option from "effect/Option" -import type * as Stream from "effect/Stream" +import * as Inspectable from "effect/interfaces/Inspectable" +import type * as Stream from "effect/stream/Stream" import * as Headers from "effect/unstable/http/Headers" import * as IncomingMessage from "effect/unstable/http/HttpIncomingMessage" import * as UrlParams from "effect/unstable/http/UrlParams" diff --git a/packages/platform-node/src/NodeHttpPlatform.ts b/packages/platform-node/src/NodeHttpPlatform.ts index 110969bb49..e459bf7498 100644 --- a/packages/platform-node/src/NodeHttpPlatform.ts +++ b/packages/platform-node/src/NodeHttpPlatform.ts @@ -2,7 +2,7 @@ * @since 1.0.0 */ import { pipe } from "effect/Function" -import * as Layer from "effect/Layer" +import * as Layer from "effect/services/Layer" import * as EtagImpl from "effect/unstable/http/Etag" import * as Headers from "effect/unstable/http/Headers" import * as Platform from "effect/unstable/http/HttpPlatform" diff --git a/packages/platform-node/src/NodeHttpServer.ts b/packages/platform-node/src/NodeHttpServer.ts index a183b0a7d8..2fd6dc4166 100644 --- a/packages/platform-node/src/NodeHttpServer.ts +++ b/packages/platform-node/src/NodeHttpServer.ts @@ -1,19 +1,19 @@ /** * @since 1.0.0 */ -import { ServiceMap } from "effect" import type * as Cause from "effect/Cause" import * as Config from "effect/config/Config" import type * as ConfigError from "effect/config/ConfigError" +import type * as Record from "effect/data/Record" import * as Effect from "effect/Effect" -import * as Fiber from "effect/Fiber" import type { LazyArg } from "effect/Function" -import * as Layer from "effect/Layer" import type * as FileSystem from "effect/platform/FileSystem" import type * as Path from "effect/platform/Path" -import type { ReadonlyRecord } from "effect/Record" -import * as Scope from "effect/Scope" -import * as Stream from "effect/Stream" +import * as Scope from "effect/resources/Scope" +import * as Fiber from "effect/runtime/Fiber" +import * as Layer from "effect/services/Layer" +import * as ServiceMap from "effect/services/ServiceMap" +import * as Stream from "effect/stream/Stream" import * as Cookies from "effect/unstable/http/Cookies" import * as Etag from "effect/unstable/http/Etag" import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient" @@ -258,7 +258,7 @@ class ServerRequestImpl extends NodeHttpIncomingMessage impleme this.headersOverride = headersOverride } - private cachedCookies: ReadonlyRecord | undefined + private cachedCookies: Record.ReadonlyRecord | undefined get cookies() { if (this.cachedCookies) { return this.cachedCookies diff --git a/packages/platform-node/src/NodeMultipart.ts b/packages/platform-node/src/NodeMultipart.ts index 793ff12a7f..af71f0f00c 100644 --- a/packages/platform-node/src/NodeMultipart.ts +++ b/packages/platform-node/src/NodeMultipart.ts @@ -2,11 +2,11 @@ * @since 1.0.0 */ import * as Effect from "effect/Effect" -import * as Inspectable from "effect/Inspectable" +import * as Inspectable from "effect/interfaces/Inspectable" import type * as FileSystem from "effect/platform/FileSystem" import type * as Path from "effect/platform/Path" -import type * as Scope from "effect/Scope" -import * as Stream from "effect/Stream" +import type * as Scope from "effect/resources/Scope" +import * as Stream from "effect/stream/Stream" import * as Multipart from "effect/unstable/http/Multipart" import * as MP from "effect/unstable/http/Multipasta/Node" import * as NFS from "node:fs" diff --git a/packages/platform-node/src/NodePath.ts b/packages/platform-node/src/NodePath.ts index 21668400f5..da71d3e9f4 100644 --- a/packages/platform-node/src/NodePath.ts +++ b/packages/platform-node/src/NodePath.ts @@ -2,23 +2,23 @@ * @since 1.0.0 */ import * as NodePath from "@effect/platform-node-shared/NodePath" -import type { Layer } from "effect/Layer" import type { Path } from "effect/platform/Path" +import type * as Layer from "effect/services/Layer" /** * @since 1.0.0 * @category layer */ -export const layer: Layer = NodePath.layer +export const layer: Layer.Layer = NodePath.layer /** * @since 1.0.0 * @category layer */ -export const layerPosix: Layer = NodePath.layerPosix +export const layerPosix: Layer.Layer = NodePath.layerPosix /** * @since 1.0.0 * @category layer */ -export const layerWin32: Layer = NodePath.layerWin32 +export const layerWin32: Layer.Layer = NodePath.layerWin32 diff --git a/packages/platform-node/src/NodeRuntime.ts b/packages/platform-node/src/NodeRuntime.ts index c1156ee6ab..264d8fee28 100644 --- a/packages/platform-node/src/NodeRuntime.ts +++ b/packages/platform-node/src/NodeRuntime.ts @@ -3,7 +3,7 @@ */ import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime" import type { Effect } from "effect/Effect" -import type { Teardown } from "effect/Runtime" +import type * as Runtime from "effect/runtime/Runtime" /** * Helps you run a main effect with built-in error handling, logging, and signal management. @@ -36,14 +36,14 @@ export const runMain: { ( options?: { readonly disableErrorReporting?: boolean | undefined - readonly teardown?: Teardown | undefined + readonly teardown?: Runtime.Teardown | undefined } ): (effect: Effect) => void ( effect: Effect, options?: { readonly disableErrorReporting?: boolean | undefined - readonly teardown?: Teardown | undefined + readonly teardown?: Runtime.Teardown | undefined } ): void } = NodeRuntime.runMain diff --git a/packages/platform-node/src/NodeServices.ts b/packages/platform-node/src/NodeServices.ts index 3e2bb4d4a5..324bc6b280 100644 --- a/packages/platform-node/src/NodeServices.ts +++ b/packages/platform-node/src/NodeServices.ts @@ -1,9 +1,9 @@ /** * @since 1.0.0 */ -import * as Layer from "effect/Layer" import type { FileSystem } from "effect/platform/FileSystem" import type { Path } from "effect/platform/Path" +import * as Layer from "effect/services/Layer" import * as NodeFileSystem from "./NodeFileSystem.ts" import * as NodePath from "./NodePath.ts" diff --git a/packages/platform-node/src/NodeSocket.ts b/packages/platform-node/src/NodeSocket.ts index 3d54b6e54a..bc65a788ce 100644 --- a/packages/platform-node/src/NodeSocket.ts +++ b/packages/platform-node/src/NodeSocket.ts @@ -2,7 +2,7 @@ * @since 1.0.0 */ import { NodeWS as WS } from "@effect/platform-node-shared/NodeSocket" -import * as Layer from "effect/Layer" +import * as Layer from "effect/services/Layer" import * as Socket from "effect/unstable/socket/Socket" /** diff --git a/packages/platform-node/test/NodeHttpClient.test.ts b/packages/platform-node/test/NodeHttpClient.test.ts index 5280981c0e..2dd9f5556e 100644 --- a/packages/platform-node/test/NodeHttpClient.test.ts +++ b/packages/platform-node/test/NodeHttpClient.test.ts @@ -1,11 +1,11 @@ import * as NodeClient from "@effect/platform-node/NodeHttpClient" import { describe, expect, it } from "@effect/vitest" -import { Struct } from "effect" +import { Struct } from "effect/data" import * as Effect from "effect/Effect" -import * as Layer from "effect/Layer" import * as Schema from "effect/schema/Schema" -import * as ServiceMap from "effect/ServiceMap" -import * as Stream from "effect/Stream" +import * as Layer from "effect/services/Layer" +import * as ServiceMap from "effect/services/ServiceMap" +import * as Stream from "effect/stream/Stream" import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http" const Todo = Schema.Struct({ diff --git a/packages/platform-node/test/NodeHttpServer.test.ts b/packages/platform-node/test/NodeHttpServer.test.ts index 52a1695b11..8333bfccda 100644 --- a/packages/platform-node/test/NodeHttpServer.test.ts +++ b/packages/platform-node/test/NodeHttpServer.test.ts @@ -1,7 +1,13 @@ import { NodeHttpServer } from "@effect/platform-node" import { assert, describe, expect, it } from "@effect/vitest" -import { Duration, Effect, Fiber, Layer, Option, Stream, Tracer } from "effect" -import { Schema } from "effect/schema" +import { Effect } from "effect" +import * as Option from "effect/data/Option" +import * as Tracer from "effect/observability/Tracer" +import * as Fiber from "effect/runtime/Fiber" +import * as Schema from "effect/schema/Schema" +import * as Layer from "effect/services/Layer" +import * as Stream from "effect/stream/Stream" +import * as Duration from "effect/time/Duration" import { Cookies, HttpBody, diff --git a/packages/platform-node/test/NodeSocket.test.ts b/packages/platform-node/test/NodeSocket.test.ts index 3865b9e032..720a4cef0e 100644 --- a/packages/platform-node/test/NodeSocket.test.ts +++ b/packages/platform-node/test/NodeSocket.test.ts @@ -1,6 +1,9 @@ import { NodeSocket, NodeSocketServer } from "@effect/platform-node" import { assert, describe, expect, it } from "@effect/vitest" -import { Effect, Fiber, Queue, Stream } from "effect" +import { Effect } from "effect" +import { Queue } from "effect/concurrency" +import * as Fiber from "effect/runtime/Fiber" +import * as Stream from "effect/stream/Stream" import { Socket, type SocketServer } from "effect/unstable/socket" import { WS } from "vitest-websocket-mock" diff --git a/packages/vitest/src/index.ts b/packages/vitest/src/index.ts index 5262dfa5cb..e6eb227884 100644 --- a/packages/vitest/src/index.ts +++ b/packages/vitest/src/index.ts @@ -1,12 +1,12 @@ /** * @since 1.0.0 */ -import type * as Duration from "effect/Duration" import type * as Effect from "effect/Effect" -import type * as FC from "effect/FastCheck" -import type * as Layer from "effect/Layer" +import type * as Scope from "effect/resources/Scope" import type * as Schema from "effect/schema/Schema" -import type * as Scope from "effect/Scope" +import type * as Layer from "effect/services/Layer" +import type * as FC from "effect/testing/FastCheck" +import type * as Duration from "effect/time/Duration" import * as V from "vitest" import * as internal from "./internal/internal.ts" @@ -170,7 +170,8 @@ export const live: Vitest.Tester = internal.live * * ```ts * import { expect, layer } from "@effect/vitest" - * import { ServiceMap, Effect, Layer } from "effect" + * import { Effect, Layer } from "effect" + * import { ServiceMap } from "effect/services" * * class Foo extends ServiceMap.Key("Foo")() { * static Live = Layer.succeed(Foo, "foo") diff --git a/packages/vitest/src/internal/internal.ts b/packages/vitest/src/internal/internal.ts index 38b82b3f47..55e0e2c3f4 100644 --- a/packages/vitest/src/internal/internal.ts +++ b/packages/vitest/src/internal/internal.ts @@ -3,19 +3,19 @@ */ import * as Cause from "effect/Cause" -import * as Duration from "effect/Duration" +import { isObject } from "effect/data/Predicate" import * as Effect from "effect/Effect" import * as Exit from "effect/Exit" -import * as fc from "effect/FastCheck" -import * as Fiber from "effect/Fiber" import { flow, pipe } from "effect/Function" -import * as Layer from "effect/Layer" -import { isObject } from "effect/Predicate" -import * as Schedule from "effect/Schedule" +import * as Scope from "effect/resources/Scope" +import * as Fiber from "effect/runtime/Fiber" +import * as Schedule from "effect/scheduling/Schedule" import * as Schema from "effect/schema/Schema" -import * as Scope from "effect/Scope" -import * as TestClock from "effect/TestClock" -import * as TestConsole from "effect/TestConsole" +import * as Layer from "effect/services/Layer" +import * as fc from "effect/testing/FastCheck" +import * as TestClock from "effect/testing/TestClock" +import * as TestConsole from "effect/testing/TestConsole" +import * as Duration from "effect/time/Duration" import * as V from "vitest" import type * as Vitest from "../index.ts" diff --git a/packages/vitest/src/utils.ts b/packages/vitest/src/utils.ts index 5058f72b39..b526cd2f52 100644 --- a/packages/vitest/src/utils.ts +++ b/packages/vitest/src/utils.ts @@ -2,11 +2,11 @@ * @since 0.21.0 */ import type * as Cause from "effect/Cause" -import * as Equal from "effect/Equal" +import * as Option from "effect/data/Option" +import * as Predicate from "effect/data/Predicate" +import * as Result from "effect/data/Result" import * as Exit from "effect/Exit" -import * as Option from "effect/Option" -import * as Predicate from "effect/Predicate" -import * as Result from "effect/Result" +import * as Equal from "effect/interfaces/Equal" import * as assert from "node:assert" import { assert as vassert } from "vitest" diff --git a/packages/vitest/test/index.test.ts b/packages/vitest/test/index.test.ts index 79846e1b17..056124e636 100644 --- a/packages/vitest/test/index.test.ts +++ b/packages/vitest/test/index.test.ts @@ -1,5 +1,9 @@ import { afterAll, describe, expect, it, layer } from "@effect/vitest" -import { Clock, Duration, Effect, FastCheck, Fiber, Layer, ServiceMap, TestClock } from "effect" +import { Effect } from "effect" +import { Fiber } from "effect/runtime" +import { Layer, ServiceMap } from "effect/services" +import { FastCheck, TestClock } from "effect/testing" +import { Clock, Duration } from "effect/time" it.effect( "effect", diff --git a/scripts/codemods/ts-fence.test.ts b/scripts/codemods/ts-fence.test.ts index 904a6e119e..42b2a04fc0 100644 --- a/scripts/codemods/ts-fence.test.ts +++ b/scripts/codemods/ts-fence.test.ts @@ -2,7 +2,7 @@ // npx vitest scripts/codemods/ts-fence.test.ts --config scripts/codemods/vitest.config.ts import type * as cs from "jscodeshift" import * as TestUtils from "jscodeshift/src/testUtils" -import transformer from "./ts-fence.js" +import transformer from "./ts-fence.ts" const expectTransformation_ = (transformer: cs.Transform) => (