Skip to content

Commit

Permalink
change Channel type parameters order from `Channel<out Env, in InEr… (
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored and mikearnaldi committed Feb 6, 2024
1 parent 8284573 commit c6d5930
Show file tree
Hide file tree
Showing 25 changed files with 2,299 additions and 2,418 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-rice-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

change `Channel` type parameters order from `Channel<out Env, in InErr, in InElem, in InDone, out OutErr, out OutElem, out OutDone>` to `Channel<OutElem, InElem = unknown, OutErr = never, InErr = unknown, OutDone = void, InDone = unknown, Env = never>`
23 changes: 22 additions & 1 deletion packages/effect/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const enabled = {
swapFiberSetParams: false,
swapRequestParams: false,
swapResourceParams: false,
swapTExitParams: true,
swapTExitParams: false,
swapChannelParams: false,
cleanupSTM: false,
cleanupEffect: false,
cleanupStream: false,
Expand Down Expand Up @@ -104,6 +105,23 @@ const swapRequestParams = swapParamsEA("Request")
const swapResourceParams = swapParamsEA("Resource")
const swapTExitParams = swapParamsEA("TExit")

// from: Channel<out Env, in InErr, in InElem, in InDone, out OutErr, out OutElem, out OutDone>
// <in out Env, in InErr, in InElem, in InDone, out OutErr, out OutElem, out OutDone>
// to: Channel<OutElem, InElem = unknown, OutErr = never, InErr = unknown, OutDone = void, InDone = unknown, Env = never>
const swapChannelParams = (ast: cs.ASTPath<cs.TSTypeReference>) => {
const is = filter(ast, "VarianceStruct")
if (
is(ast.value.typeName) &&
ast.value.typeParameters &&
ast.value.typeParameters.params.length === 7
) {
const params = ast.value.typeParameters.params
const newParams = [params[5], params[2], params[4], params[1], params[6], params[3], params[0]]
popNever(newParams)
ast.value.typeParameters.params = newParams
}
}

const swapSTMParams = swapParamsREA("STM")
const swapSTMGenParams = swapParamsREA("STMGen")
const swapLayerParams = swapParamsREA("Layer")
Expand Down Expand Up @@ -169,6 +187,9 @@ export default function transformer(file: cs.FileInfo, api: cs.API) {
if (enabled.swapTExitParams) {
swapTExitParams(ast)
}
if (enabled.swapChannelParams) {
swapChannelParams(ast)
}
if (enabled.cleanupEffect) {
cleanupEffect(ast)
}
Expand Down
10 changes: 1 addition & 9 deletions packages/effect/src/Cause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,7 @@ export interface YieldableError extends Pipeable, Inspectable, Readonly<Error> {
readonly [Effect.EffectTypeId]: Effect.Effect.VarianceStruct<never, this, never>
readonly [Stream.StreamTypeId]: Effect.Effect.VarianceStruct<never, this, never>
readonly [Sink.SinkTypeId]: Sink.Sink.VarianceStruct<never, this, unknown, never, never>
readonly [Channel.ChannelTypeId]: Channel.Channel.VarianceStruct<
never,
unknown,
unknown,
unknown,
this,
never,
never
>
readonly [Channel.ChannelTypeId]: Channel.Channel.VarianceStruct<never, unknown, this, unknown, never, unknown, never>
}

/**
Expand Down
Loading

0 comments on commit c6d5930

Please sign in to comment.