Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use literal strings for service tags #1955

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-elephants-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

make data-last FiberSet.run accept an Effect
5 changes: 5 additions & 0 deletions .changeset/selfish-elephants-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

add Fiber{Map,Set}.makeRuntime
5 changes: 5 additions & 0 deletions .changeset/serious-news-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

add Fiber{Set,Map}.runtime api
5 changes: 5 additions & 0 deletions .changeset/seven-parents-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

make data-last FiberMap.run accept an Effect
5 changes: 5 additions & 0 deletions .changeset/wise-singers-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Refactor effect to use literal tags for services
10 changes: 4 additions & 6 deletions packages/effect/src/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type { Predicate } from "./Predicate.js"
import type * as PubSub from "./PubSub.js"
import type * as Queue from "./Queue.js"
import type * as Ref from "./Ref.js"
import type * as Scope from "./Scope.js"
import type * as SingleProducerAsyncInput from "./SingleProducerAsyncInput.js"
import type * as Sink from "./Sink.js"
import type * as Stream from "./Stream.js"
Expand Down Expand Up @@ -1090,7 +1089,7 @@ export const fromPubSub: <Err, Done, Elem>(
*/
export const fromPubSubScoped: <Err, Done, Elem>(
pubsub: PubSub.PubSub<Either.Either<Exit.Exit<Err, Done>, Elem>>
) => Effect.Effect<Scope.Scope, never, Channel<never, unknown, unknown, unknown, Err, Elem, Done>> =
) => Effect.Effect<"Scope", never, Channel<never, unknown, unknown, unknown, Err, Elem, Done>> =
channel.fromPubSubScoped

/**
Expand Down Expand Up @@ -1932,7 +1931,7 @@ export const runDrain: <Env, InErr, InDone, OutElem, OutErr, OutDone>(
*/
export const scoped: <R, E, A>(
effect: Effect.Effect<R, E, A>
) => Channel<Exclude<R, Scope.Scope>, unknown, unknown, unknown, E, A, unknown> = channel.scoped
) => Channel<Exclude<R, "Scope">, unknown, unknown, unknown, E, A, unknown> = channel.scoped

/**
* Constructs a channel that succeeds immediately with the specified value.
Expand Down Expand Up @@ -1983,8 +1982,7 @@ export const toPubSub: <Err, Done, Elem>(
*/
export const toPull: <Env, InErr, InElem, InDone, OutErr, OutElem, OutDone>(
self: Channel<Env, InErr, InElem, InDone, OutErr, OutElem, OutDone>
) => Effect.Effect<Scope.Scope | Env, never, Effect.Effect<Env, OutErr, Either.Either<OutDone, OutElem>>> =
channel.toPull
) => Effect.Effect<"Scope" | Env, never, Effect.Effect<Env, OutErr, Either.Either<OutDone, OutElem>>> = channel.toPull

/**
* Converts a `Channel` to a `Queue`.
Expand Down Expand Up @@ -2039,7 +2037,7 @@ export const unwrap: <R, E, R2, InErr, InElem, InDone, OutErr, OutElem, OutDone>
*/
export const unwrapScoped: <R, E, Env, InErr, InElem, InDone, OutErr, OutElem, OutDone>(
self: Effect.Effect<R, E, Channel<Env, InErr, InElem, InDone, OutErr, OutElem, OutDone>>
) => Channel<Env | Exclude<R, Scope.Scope>, InErr, InElem, InDone, E | OutErr, OutElem, OutDone> = channel.unwrapScoped
) => Channel<Env | Exclude<R, "Scope">, InErr, InElem, InDone, E | OutErr, OutElem, OutDone> = channel.unwrapScoped

/**
* Updates a service in the context of this channel.
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/src/Clock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ export const clockWith: <R, E, A>(f: (clock: Clock) => Effect.Effect<R, E, A>) =
* @since 2.0.0
* @category context
*/
export const Clock: Context.Tag<Clock, Clock> = internal.clockTag
export const Clock: Context.Tag<"Clock", Clock> = internal.clockTag
2 changes: 1 addition & 1 deletion packages/effect/src/ConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export declare namespace ConfigProvider {
* @since 2.0.0
* @category context
*/
export const ConfigProvider: Context.Tag<ConfigProvider, ConfigProvider> = internal.configProviderTag
export const ConfigProvider: Context.Tag<"ConfigProvider", ConfigProvider> = internal.configProviderTag

/**
* Creates a new config provider.
Expand Down
12 changes: 4 additions & 8 deletions packages/effect/src/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { Effect } from "./Effect.js"
import * as internal from "./internal/console.js"
import * as defaultConsole from "./internal/defaultServices/console.js"
import type * as Layer from "./Layer.js"
import type { Scope } from "./Scope.js"

/**
* @since 2.0.0
Expand Down Expand Up @@ -82,7 +81,7 @@ export interface UnsafeConsole {
* @since 2.0.0
* @category context
*/
export const Console: Context.Tag<Console, Console> = defaultConsole.consoleTag
export const Console: Context.Tag<"Console", Console> = defaultConsole.consoleTag

/**
* @since 2.0.0
Expand Down Expand Up @@ -158,11 +157,8 @@ export const error: (...args: ReadonlyArray<any>) => Effect<never, never, void>
* @category accessor
*/
export const group: (
options?: {
label?: string | undefined
collapsed?: boolean | undefined
}
) => Effect<Scope, never, void> = internal.group
options?: { label?: string | undefined; collapsed?: boolean | undefined } | undefined
) => Effect<"Scope", never, void> = internal.group

/**
* @since 2.0.0
Expand All @@ -187,7 +183,7 @@ export const table: (tabularData: any, properties?: ReadonlyArray<string>) => Ef
* @since 2.0.0
* @category accessor
*/
export const time: (label?: string) => Effect<Scope, never, void> = internal.time
export const time: (label?: string | undefined) => Effect<"Scope", never, void> = internal.time

/**
* @since 2.0.0
Expand Down
16 changes: 8 additions & 8 deletions packages/effect/src/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type TagTypeId = typeof TagTypeId
* @since 2.0.0
* @category models
*/
export interface Tag<in out Identifier, in out Service> extends Pipeable, Inspectable {
export interface Tag<in out Identifier extends string, in out Service> extends Pipeable, Inspectable {
readonly _tag: "Tag"
readonly _op: "Tag"
readonly [TagTypeId]: {
Expand All @@ -37,7 +37,7 @@ export interface Tag<in out Identifier, in out Service> extends Pipeable, Inspec
of(self: Service): Service
context(self: Service): Context<Identifier>
readonly stack?: string | undefined
readonly identifier?: unknown
readonly identifier: Identifier
[Unify.typeSymbol]?: unknown
[Unify.unifySymbol]?: TagUnify<this>
[Unify.ignoreSymbol]?: TagUnifyIgnore
Expand Down Expand Up @@ -91,7 +91,7 @@ export declare namespace Tag {
* @since 2.0.0
* @category constructors
*/
export const Tag: <Identifier, Service = Identifier>(identifier?: unknown) => Tag<Identifier, Service> =
export const Tag: <Identifier extends string>(identifier: Identifier) => <Service>() => Tag<Identifier, Service> =
internal.makeTag

const TypeId: unique symbol = internal.TypeId as TypeId
Expand All @@ -106,7 +106,7 @@ export type TypeId = typeof TypeId
* @since 2.0.0
* @category models
*/
export type ValidTagsById<R> = R extends infer S ? Tag<S, any> : never
export type ValidTagsById<R> = R extends infer S extends string ? Tag<S, any> : never

/**
* @since 2.0.0
Expand Down Expand Up @@ -272,8 +272,8 @@ export const get: {
* @category unsafe
*/
export const unsafeGet: {
<S, I>(tag: Tag<I, S>): <Services>(self: Context<Services>) => S
<Services, S, I>(self: Context<Services>, tag: Tag<I, S>): S
<S, I extends string>(tag: Tag<I, S>): <Services>(self: Context<Services>) => S
<Services, S, I extends string>(self: Context<Services>, tag: Tag<I, S>): S
} = internal.unsafeGet

/**
Expand All @@ -299,8 +299,8 @@ export const unsafeGet: {
* @category getters
*/
export const getOption: {
<S, I>(tag: Tag<I, S>): <Services>(self: Context<Services>) => Option<S>
<Services, S, I>(self: Context<Services>, tag: Tag<I, S>): Option<S>
<S, I extends string>(tag: Tag<I, S>): <Services>(self: Context<Services>) => Option<S>
<Services, S, I extends string>(self: Context<Services>, tag: Tag<I, S>): Option<S>
} = internal.getOption

/**
Expand Down
15 changes: 5 additions & 10 deletions packages/effect/src/DefaultServices.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
/**
* @since 2.0.0
*/
import type * as Clock from "./Clock.js"
import type * as ConfigProvider from "./ConfigProvider.js"
import type * as Console from "./Console.js"
import type * as Context from "./Context.js"
import type * as FiberRef from "./FiberRef.js"
import * as internal from "./internal/defaultServices.js"
import type * as Random from "./Random.js"
import type * as Tracer from "./Tracer.js"

/**
* @since 2.0.0
* @category models
*/
export type DefaultServices =
| Clock.Clock
| Console.Console
| Random.Random
| ConfigProvider.ConfigProvider
| Tracer.Tracer
| "Clock"
| "Console"
| "Random"
| "ConfigProvider"
| "Tracer"

/**
* @since 2.0.0
Expand Down
Loading
Loading