Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
refactor Scope elimination in signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Sep 4, 2023
1 parent 7395eb5 commit 0743a57
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-planets-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/stream": patch
---

refactor Scope elimination in signatures
4 changes: 2 additions & 2 deletions docs/modules/Channel.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ Use a scoped effect to emit an output element.
```ts
export declare const scoped: <R, E, A>(
effect: Effect.Effect<Scope.Scope | R, E, A>
effect: Effect.Effect<R, E, A>
) => Channel<Exclude<R, Scope.Scope>, unknown, unknown, unknown, E, A, unknown>
```
Expand Down Expand Up @@ -594,7 +594,7 @@ Makes a channel from a managed that returns a channel in case of success.
```ts
export declare const unwrapScoped: <R, E, Env, InErr, InElem, InDone, OutErr, OutElem, OutDone>(
self: Effect.Effect<Scope.Scope | R, E, Channel<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>
```
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/Sink.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,11 @@ Creates a sink from a chunk processing function.
```ts
export declare const fromPush: <R, E, In, L, Z>(
push: Effect.Effect<
Scope.Scope | R,
R,
never,
(_: Option.Option<Chunk.Chunk<In>>) => Effect.Effect<R, readonly [Either.Either<E, Z>, Chunk.Chunk<L>], void>
>
) => Sink<R, E, In, L, Z>
) => Sink<Exclude<R, Scope.Scope>, E, In, L, Z>
```
Added in v1.0.0
Expand Down Expand Up @@ -1095,8 +1095,8 @@ Creates a sink produced from a scoped effect.
```ts
export declare const unwrapScoped: <R, E, In, L, Z>(
effect: Effect.Effect<Scope.Scope | R, E, Sink<R, E, In, L, Z>>
) => Sink<R, E, In, L, Z>
effect: Effect.Effect<R, E, Sink<R, E, In, L, Z>>
) => Sink<Exclude<R, Scope.Scope>, E, In, L, Z>
```
Added in v1.0.0
Expand Down
10 changes: 4 additions & 6 deletions docs/modules/Stream.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,9 @@ end of the stream, by setting it to `None`.
```ts
export declare const asyncScoped: <R, E, A>(
register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<R | Scope.Scope, E, unknown>,
register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<R, E, unknown>,
outputBuffer?: number
) => Stream<R, E, A>
) => Stream<Exclude<R, Scope.Scope>, E, A>
```
Added in v1.0.0
Expand Down Expand Up @@ -1066,9 +1066,7 @@ Creates a single-valued stream from a scoped resource.
**Signature**
```ts
export declare const scoped: <R, E, A>(
effect: Effect.Effect<Scope.Scope | R, E, A>
) => Stream<Exclude<R, Scope.Scope>, E, A>
export declare const scoped: <R, E, A>(effect: Effect.Effect<R, E, A>) => Stream<Exclude<R, Scope.Scope>, E, A>
```
Added in v1.0.0
Expand Down Expand Up @@ -1228,7 +1226,7 @@ Creates a stream produced from a scoped `Effect`.
```ts
export declare const unwrapScoped: <R, E, R2, E2, A>(
effect: Effect.Effect<Scope.Scope | R, E, Stream<R2, E2, A>>
effect: Effect.Effect<R, E, Stream<R2, E2, A>>
) => Stream<R2 | Exclude<R, Scope.Scope>, E | E2, A>
```
Expand Down
4 changes: 2 additions & 2 deletions src/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ export const runDrain: <Env, InErr, InDone, OutElem, OutErr, OutDone>(
* @category constructors
*/
export const scoped: <R, E, A>(
effect: Effect.Effect<R | Scope.Scope, E, A>
effect: Effect.Effect<R, E, A>
) => Channel<Exclude<R, Scope.Scope>, unknown, unknown, unknown, E, A, unknown> = channel.scoped

/**
Expand Down Expand Up @@ -2022,7 +2022,7 @@ export const unwrap: <R, E, R2, InErr, InElem, InDone, OutErr, OutElem, OutDone>
* @category constructors
*/
export const unwrapScoped: <R, E, Env, InErr, InElem, InDone, OutErr, OutElem, OutDone>(
self: Effect.Effect<Scope.Scope | R, E, Channel<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

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Sink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1002,11 +1002,11 @@ export const fromHub: <In>(
*/
export const fromPush: <R, E, In, L, Z>(
push: Effect.Effect<
Scope.Scope | R,
R,
never,
(_: Option.Option<Chunk.Chunk<In>>) => Effect.Effect<R, readonly [Either.Either<E, Z>, Chunk.Chunk<L>], void>
>
) => Sink<R, E, In, L, Z> = internal.fromPush
) => Sink<Exclude<R, Scope.Scope>, E, In, L, Z> = internal.fromPush

/**
* Create a sink which enqueues each element into the specified queue.
Expand Down Expand Up @@ -1332,8 +1332,8 @@ export const unwrap: <R, E, R2, E2, In, L, Z>(
* @category constructors
*/
export const unwrapScoped: <R, E, In, L, Z>(
effect: Effect.Effect<R | Scope.Scope, E, Sink<R, E, In, L, Z>>
) => Sink<R, E, In, L, Z> = internal.unwrapScoped
effect: Effect.Effect<R, E, Sink<R, E, In, L, Z>>
) => Sink<Exclude<R, Scope.Scope>, E, In, L, Z> = internal.unwrapScoped

/**
* Returns the sink that executes this one and times its execution.
Expand Down
10 changes: 5 additions & 5 deletions src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ export const asyncOption: <R, E, A>(
* @category constructors
*/
export const asyncScoped: <R, E, A>(
register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<R | Scope.Scope, E, unknown>,
register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<R, E, unknown>,
outputBuffer?: number
) => Stream<R, E, A> = internal.asyncScoped
) => Stream<Exclude<R, Scope.Scope>, E, A> = internal.asyncScoped

/**
* Returns a `Stream` that first collects `n` elements from the input `Stream`,
Expand Down Expand Up @@ -3329,7 +3329,7 @@ export const scheduleWith: {
* @since 1.0.0
* @category constructors
*/
export const scoped: <R, E, A>(effect: Effect.Effect<Scope.Scope | R, E, A>) => Stream<Exclude<R, Scope.Scope>, E, A> =
export const scoped: <R, E, A>(effect: Effect.Effect<R, E, A>) => Stream<Exclude<R, Scope.Scope>, E, A> =
internal.scoped

/**
Expand Down Expand Up @@ -3915,8 +3915,8 @@ export const unwrap: <R, E, R2, E2, A>(effect: Effect.Effect<R, E, Stream<R2, E2
* @category constructors
*/
export const unwrapScoped: <R, E, R2, E2, A>(
effect: Effect.Effect<Scope.Scope | R, E, Stream<R2, E2, A>>
) => Stream<Exclude<R | Scope.Scope, Scope.Scope> | R2, E | E2, A> = internal.unwrapScoped
effect: Effect.Effect<R, E, Stream<R2, E2, A>>
) => Stream<R2 | Exclude<R, Scope.Scope>, E | E2, A> = internal.unwrapScoped

/**
* Updates the specified service within the context of the `Stream`.
Expand Down
12 changes: 4 additions & 8 deletions src/internal/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2127,8 +2127,8 @@ export const runDrain = <Env, InErr, InDone, OutElem, OutErr, OutDone>(

/** @internal */
export const scoped = <R, E, A>(
effect: Effect.Effect<R | Scope.Scope, E, A>
): Channel.Channel<Exclude<R | Scope.Scope, Scope.Scope>, unknown, unknown, unknown, E, A, unknown> =>
effect: Effect.Effect<R, E, A>
): Channel.Channel<Exclude<R, Scope.Scope>, unknown, unknown, unknown, E, A, unknown> =>
unwrap(
Effect.uninterruptibleMask((restore) =>
Effect.map(Scope.make(), (scope) =>
Expand Down Expand Up @@ -2259,13 +2259,9 @@ export const unwrapScoped = <
OutElem,
OutDone
>(
self: Effect.Effect<
R | Scope.Scope,
E,
Channel.Channel<Env, InErr, InElem, InDone, OutErr, OutElem, OutDone>
>
self: Effect.Effect<R, E, Channel.Channel<Env, InErr, InElem, InDone, OutErr, OutElem, OutDone>>
): Channel.Channel<
Exclude<R | Scope.Scope, Scope.Scope> | Env,
Exclude<R, Scope.Scope> | Env,
InErr,
InElem,
InDone,
Expand Down
9 changes: 5 additions & 4 deletions src/internal/sink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1462,11 +1462,12 @@ export const fromHub = <In>(
/** @internal */
export const fromPush = <R, E, In, L, Z>(
push: Effect.Effect<
R | Scope.Scope,
R,
never,
(_: Option.Option<Chunk.Chunk<In>>) => Effect.Effect<R, readonly [Either.Either<E, Z>, Chunk.Chunk<L>], void>
>
): Sink.Sink<R, E, In, L, Z> => new SinkImpl(channel.unwrapScoped(pipe(push, Effect.map(fromPushPull))))
): Sink.Sink<Exclude<R, Scope.Scope>, E, In, L, Z> =>
new SinkImpl(channel.unwrapScoped(pipe(push, Effect.map(fromPushPull))))

const fromPushPull = <R, E, In, L, Z>(
push: (
Expand Down Expand Up @@ -1969,8 +1970,8 @@ export const unwrap = <R, E, R2, E2, In, L, Z>(

/** @internal */
export const unwrapScoped = <R, E, In, L, Z>(
effect: Effect.Effect<R | Scope.Scope, E, Sink.Sink<R, E, In, L, Z>>
): Sink.Sink<R, E, In, L, Z> => {
effect: Effect.Effect<R, E, Sink.Sink<R, E, In, L, Z>>
): Sink.Sink<Exclude<R, Scope.Scope>, E, In, L, Z> => {
return new SinkImpl(channel.unwrapScoped(pipe(effect, Effect.map((sink) => toChannel(sink)))))
}

Expand Down
12 changes: 6 additions & 6 deletions src/internal/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ export const asyncOption = <R, E, A>(

/** @internal */
export const asyncScoped = <R, E, A>(
register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<R | Scope.Scope, E, unknown>,
register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<R, E, unknown>,
outputBuffer = 16
): Stream.Stream<R, E, A> =>
): Stream.Stream<Exclude<R, Scope.Scope>, E, A> =>
pipe(
Effect.acquireRelease(
Queue.bounded<Take.Take<E, A>>(outputBuffer),
Expand Down Expand Up @@ -5622,8 +5622,8 @@ export const scanEffect = dual<

/** @internal */
export const scoped = <R, E, A>(
effect: Effect.Effect<R | Scope.Scope, E, A>
): Stream.Stream<Exclude<R | Scope.Scope, Scope.Scope>, E, A> =>
effect: Effect.Effect<R, E, A>
): Stream.Stream<Exclude<R, Scope.Scope>, E, A> =>
new StreamImpl(channel.ensuring(channel.scoped(pipe(effect, Effect.map(Chunk.of))), Effect.unit))

/** @internal */
Expand Down Expand Up @@ -6754,8 +6754,8 @@ export const unwrap = <R, E, R2, E2, A>(

/** @internal */
export const unwrapScoped = <R, E, R2, E2, A>(
effect: Effect.Effect<R | Scope.Scope, E, Stream.Stream<R2, E2, A>>
): Stream.Stream<Exclude<R | Scope.Scope, Scope.Scope> | R2, E | E2, A> => flatten(scoped(effect))
effect: Effect.Effect<R, E, Stream.Stream<R2, E2, A>>
): Stream.Stream<Exclude<R, Scope.Scope> | R2, E | E2, A> => flatten(scoped(effect))

/** @internal */
export const updateService = dual<
Expand Down

0 comments on commit 0743a57

Please sign in to comment.