From c86bd4e134c23146c216f9ff97e03781d55991b6 Mon Sep 17 00:00:00 2001 From: Maxim Khramtsov Date: Wed, 26 Jun 2024 00:26:44 +0200 Subject: [PATCH] Support unification for `Micro` module (#3078) Co-authored-by: maksim.khramtsov Co-authored-by: Tim --- .changeset/rare-cameras-explain.md | 5 +++++ packages/effect/dtslint/Unify.ts | 15 +++++++++++++-- packages/effect/src/Micro.ts | 21 ++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 .changeset/rare-cameras-explain.md diff --git a/.changeset/rare-cameras-explain.md b/.changeset/rare-cameras-explain.md new file mode 100644 index 0000000000..e6b3bdae01 --- /dev/null +++ b/.changeset/rare-cameras-explain.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +Support unification for Micro module diff --git a/packages/effect/dtslint/Unify.ts b/packages/effect/dtslint/Unify.ts index 9d5889d12b..4aabe4784d 100644 --- a/packages/effect/dtslint/Unify.ts +++ b/packages/effect/dtslint/Unify.ts @@ -1,4 +1,6 @@ +import type * as Effect from "effect/Effect" import * as Either from "effect/Either" +import type * as Micro from "effect/Micro" import type * as Option from "effect/Option" import type * as Stream from "effect/Stream" import * as Unify from "effect/Unify" @@ -23,7 +25,16 @@ Unify.unify((n: N) => Math.random() > 0 ? Either.right(n) : Either.left("ok") // $ExpectType Either Unify.unify(Math.random() > 0 ? Either.right(10) : Either.left("ok")) -// $ExpectType Stream<0 | 1, never, never> +// $ExpectType Stream<0 | "a", "b" | 1, "c" | 2> export type SU = Unify.Unify< - Stream.Stream<0> | Stream.Stream<1> + Stream.Stream<0, 1, 2> | Stream.Stream<"a", "b", "c"> +> + +// $ExpectType Micro<0 | "a", "b" | 1, "c" | 2> +export type MU = Unify.Unify< + Micro.Micro<0, 1, 2> | Micro.Micro<"a", "b", "c"> +> +// $ExpectType Effect<0 | "a", "b" | 1, "c" | 2> +export type EU = Unify.Unify< + Effect.Effect<0, 1, 2> | Effect.Effect<"a", "b", "c"> > diff --git a/packages/effect/src/Micro.ts b/packages/effect/src/Micro.ts index 25a73c5157..d118588c61 100644 --- a/packages/effect/src/Micro.ts +++ b/packages/effect/src/Micro.ts @@ -6,7 +6,7 @@ */ import type { Channel, ChannelTypeId } from "./Channel.js" import * as Context from "./Context.js" -import type { Effect, EffectTypeId } from "./Effect.js" +import type { Effect, EffectTypeId, EffectUnify, EffectUnifyIgnore } from "./Effect.js" import * as Effectable from "./Effectable.js" import * as Either from "./Either.js" import { constTrue, constVoid, dual, identity, type LazyArg } from "./Function.js" @@ -24,6 +24,7 @@ import type { ReadonlyRecord } from "./Record.js" import type { Sink, SinkTypeId } from "./Sink.js" import type { Stream, StreamTypeId } from "./Stream.js" import type { Concurrency, Covariant, Equals, NoInfer, NotFunction, Simplify } from "./Types.js" +import type * as Unify from "./Unify.js" import { YieldWrap, yieldWrapGet } from "./Utils.js" /** @@ -64,9 +65,27 @@ export type runSymbol = typeof runSymbol export interface Micro extends Effect { readonly [TypeId]: Micro.Variance readonly [runSymbol]: (env: Env, onResult: (result: Result) => void) => void + [Unify.typeSymbol]?: unknown + [Unify.unifySymbol]?: MicroUnify + [Unify.ignoreSymbol]?: MicroUnifyIgnore [Symbol.iterator](): MicroIterator> } +/** + * @category models + * @since 3.4.3 + */ +export interface MicroUnify extends EffectUnify { + Micro?: () => A[Unify.typeSymbol] extends Micro | infer _ ? Micro : never +} + +/** + * @category models + * @since 3.4.3 + */ +export interface MicroUnifyIgnore extends EffectUnifyIgnore { + Effect?: true +} /** * @category type lambdas * @since 3.4.1