Skip to content

Commit

Permalink
Support unification for Micro module (#3078)
Browse files Browse the repository at this point in the history
Co-authored-by: maksim.khramtsov <[email protected]>
Co-authored-by: Tim <[email protected]>
  • Loading branch information
3 people authored Jun 25, 2024
1 parent ff78636 commit c86bd4e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-cameras-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Support unification for Micro module
15 changes: 13 additions & 2 deletions packages/effect/dtslint/Unify.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -23,7 +25,16 @@ Unify.unify(<N>(n: N) => Math.random() > 0 ? Either.right(n) : Either.left("ok")
// $ExpectType Either<number, string>
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">
>
21 changes: 20 additions & 1 deletion packages/effect/src/Micro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

/**
Expand Down Expand Up @@ -64,9 +65,27 @@ export type runSymbol = typeof runSymbol
export interface Micro<out A, out E = never, out R = never> extends Effect<A, E, R> {
readonly [TypeId]: Micro.Variance<A, E, R>
readonly [runSymbol]: (env: Env<any>, onResult: (result: Result<A, E>) => void) => void
[Unify.typeSymbol]?: unknown
[Unify.unifySymbol]?: MicroUnify<this>
[Unify.ignoreSymbol]?: MicroUnifyIgnore
[Symbol.iterator](): MicroIterator<Micro<A, E, R>>
}

/**
* @category models
* @since 3.4.3
*/
export interface MicroUnify<A extends { [Unify.typeSymbol]?: any }> extends EffectUnify<A> {
Micro?: () => A[Unify.typeSymbol] extends Micro<infer A0, infer E0, infer R0> | infer _ ? Micro<A0, E0, R0> : never
}

/**
* @category models
* @since 3.4.3
*/
export interface MicroUnifyIgnore extends EffectUnifyIgnore {
Effect?: true
}
/**
* @category type lambdas
* @since 3.4.1
Expand Down

0 comments on commit c86bd4e

Please sign in to comment.