Skip to content

Commit

Permalink
change Take type parameters order from Take<E, A> to `Take<A, E =… (
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored and tim-smart committed Feb 7, 2024
1 parent 4dbc5cd commit 5b880cb
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 185 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-peas-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

change `Take` type parameters order from `Take<E, A>` to `Take<A, E = never>`
2 changes: 1 addition & 1 deletion packages/effect/mod.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
dirs=(../effect/src)
dirs=(../effect/test)
for dir in ${dirs[@]};
do
echo Refactoring $dir
Expand Down
31 changes: 16 additions & 15 deletions packages/effect/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ const enabled = {
swapSTMGenParams: false,
swapDeferredParams: false,
swapTDeferredParams: false,
swapTakeParams: false,
cleanupSTM: false,
cleanupEffect: false,
cleanupStream: false,
cleanupExit: false
cleanupExit: false,
cleanupTake: true
}

const cleanup = (name: string) => (ast: cs.ASTPath<cs.TSTypeReference>) => {
Expand All @@ -31,6 +33,7 @@ const cleanupEffect = cleanup("Effect")
const cleanupStream = cleanup("Stream")
const cleanupExit = cleanup("Exit")
const cleanupSTM = cleanup("STM")
const cleanupTake = cleanup("Take")

const filter = (ast: cs.ASTPath<cs.TSTypeReference>, nodeName: string) => {
const name = ast.value.typeName
Expand Down Expand Up @@ -71,31 +74,23 @@ const swapParamsREA = (nodeName: string) => (ast: cs.ASTPath<cs.TSTypeReference>
}
}

const swapDeferredParams = (ast: cs.ASTPath<cs.TSTypeReference>) => {
const is = filter(ast, "Deferred")
const swapParamsEA = (nodeName: string) => (ast: cs.ASTPath<cs.TSTypeReference>) => {
const is = filter(ast, nodeName)
if (
is(ast.value.typeName) &&
ast.value.typeParameters &&
ast.value.typeParameters.params.length === 2
) {
const params = ast.value.typeParameters.params
const newParams = [params[1], params[0]]
popNever(newParams)
ast.value.typeParameters.params = newParams
}
}

const swapTDeferredParams = (ast: cs.ASTPath<cs.TSTypeReference>) => {
const is = filter(ast, "TDeferred")
if (
is(ast.value.typeName) &&
ast.value.typeParameters &&
ast.value.typeParameters.params.length === 2
) {
const params = ast.value.typeParameters.params
const newParams = [params[1], params[0]]
ast.value.typeParameters.params = newParams
}
}
const swapDeferredParams = swapParamsEA("Deferred")
const swapTDeferredParams = swapParamsEA("TDeferred")
const swapTakeParams = swapParamsEA("Take")

const swapSTMParams = swapParamsREA("STM")
const swapSTMGenParams = swapParamsREA("STMGen")
Expand Down Expand Up @@ -141,6 +136,9 @@ export default function transformer(file: cs.FileInfo, api: cs.API) {
if (enabled.swapTDeferredParams) {
swapTDeferredParams(ast)
}
if (enabled.swapTakeParams) {
swapTakeParams(ast)
}
if (enabled.cleanupEffect) {
cleanupEffect(ast)
}
Expand All @@ -153,6 +151,9 @@ export default function transformer(file: cs.FileInfo, api: cs.API) {
if (enabled.cleanupSTM) {
cleanupSTM(ast)
}
if (enabled.cleanupTake) {
cleanupTake(ast)
}
})

return root.toSource()
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/GroupBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type GroupByTypeId = typeof GroupByTypeId
* @category models
*/
export interface GroupBy<out R, out E, out K, out V> extends GroupBy.Variance<R, E, K, V>, Pipeable {
readonly grouped: Stream.Stream<readonly [K, Queue.Dequeue<Take.Take<E, V>>], E, R>
readonly grouped: Stream.Stream<readonly [K, Queue.Dequeue<Take.Take<V, E>>], E, R>
}

/**
Expand Down Expand Up @@ -99,5 +99,5 @@ export const first: {
* @category constructors
*/
export const make: <R, E, K, V>(
grouped: Stream.Stream<readonly [K, Queue.Dequeue<Take.Take<E, V>>], E, R>
grouped: Stream.Stream<readonly [K, Queue.Dequeue<Take.Take<V, E>>], E, R>
) => GroupBy<R, E, K, V> = internal.make
34 changes: 17 additions & 17 deletions packages/effect/src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,12 @@ export const broadcastedQueues: {
maximumLag: number
): <A, E, R>(
self: Stream<A, E, R>
) => Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Take.Take<E, A>>, N>, never, R | Scope.Scope>
) => Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Take.Take<A, E>>, N>, never, R | Scope.Scope>
<A, E, R, N extends number>(
self: Stream<A, E, R>,
n: N,
maximumLag: number
): Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Take.Take<E, A>>, N>, never, Scope.Scope | R>
): Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Take.Take<A, E>>, N>, never, Scope.Scope | R>
} = internal.broadcastedQueues

/**
Expand All @@ -422,11 +422,11 @@ export const broadcastedQueuesDynamic: {
maximumLag: number
): <A, E, R>(
self: Stream<A, E, R>
) => Effect.Effect<Effect.Effect<Queue.Dequeue<Take.Take<E, A>>, never, Scope.Scope>, never, R | Scope.Scope>
) => Effect.Effect<Effect.Effect<Queue.Dequeue<Take.Take<A, E>>, never, Scope.Scope>, never, R | Scope.Scope>
<A, E, R>(
self: Stream<A, E, R>,
maximumLag: number
): Effect.Effect<Effect.Effect<Queue.Dequeue<Take.Take<E, A>>, never, Scope.Scope>, never, Scope.Scope | R>
): Effect.Effect<Effect.Effect<Queue.Dequeue<Take.Take<A, E>>, never, Scope.Scope>, never, Scope.Scope | R>
} = internal.broadcastedQueuesDynamic

/**
Expand Down Expand Up @@ -1397,7 +1397,7 @@ export const flattenIterables: <A, E, R>(self: Stream<Iterable<A>, E, R>) => Str
* @since 2.0.0
* @category sequencing
*/
export const flattenTake: <R, E, E2, A>(self: Stream<Take.Take<E2, A>, E, R>) => Stream<A, E | E2, R> =
export const flattenTake: <R, E, E2, A>(self: Stream<Take.Take<A, E2>, E, R>) => Stream<A, E | E2, R> =
internal.flattenTake

/**
Expand Down Expand Up @@ -3180,8 +3180,8 @@ export const runHead: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Option.O
* @category destructors
*/
export const runIntoPubSub: {
<E, A>(pubsub: PubSub.PubSub<Take.Take<E, A>>): <R>(self: Stream<A, E, R>) => Effect.Effect<void, never, R>
<A, E, R>(self: Stream<A, E, R>, pubsub: PubSub.PubSub<Take.Take<E, A>>): Effect.Effect<void, never, R>
<E, A>(pubsub: PubSub.PubSub<Take.Take<A, E>>): <R>(self: Stream<A, E, R>) => Effect.Effect<void, never, R>
<A, E, R>(self: Stream<A, E, R>, pubsub: PubSub.PubSub<Take.Take<A, E>>): Effect.Effect<void, never, R>
} = internal.runIntoPubSub

/**
Expand All @@ -3193,9 +3193,9 @@ export const runIntoPubSub: {
*/
export const runIntoPubSubScoped: {
<E, A>(
pubsub: PubSub.PubSub<Take.Take<E, A>>
pubsub: PubSub.PubSub<Take.Take<A, E>>
): <R>(self: Stream<A, E, R>) => Effect.Effect<void, never, Scope.Scope | R>
<A, E, R>(self: Stream<A, E, R>, pubsub: PubSub.PubSub<Take.Take<E, A>>): Effect.Effect<void, never, Scope.Scope | R>
<A, E, R>(self: Stream<A, E, R>, pubsub: PubSub.PubSub<Take.Take<A, E>>): Effect.Effect<void, never, Scope.Scope | R>
} = internal.runIntoPubSubScoped

/**
Expand All @@ -3206,8 +3206,8 @@ export const runIntoPubSubScoped: {
* @category destructors
*/
export const runIntoQueue: {
<E, A>(queue: Queue.Enqueue<Take.Take<E, A>>): <R>(self: Stream<A, E, R>) => Effect.Effect<void, never, R>
<A, E, R>(self: Stream<A, E, R>, queue: Queue.Enqueue<Take.Take<E, A>>): Effect.Effect<void, never, R>
<E, A>(queue: Queue.Enqueue<Take.Take<A, E>>): <R>(self: Stream<A, E, R>) => Effect.Effect<void, never, R>
<A, E, R>(self: Stream<A, E, R>, queue: Queue.Enqueue<Take.Take<A, E>>): Effect.Effect<void, never, R>
} = internal.runIntoQueue

/**
Expand Down Expand Up @@ -3236,9 +3236,9 @@ export const runIntoQueueElementsScoped: {
*/
export const runIntoQueueScoped: {
<E, A>(
queue: Queue.Enqueue<Take.Take<E, A>>
queue: Queue.Enqueue<Take.Take<A, E>>
): <R>(self: Stream<A, E, R>) => Effect.Effect<void, never, Scope.Scope | R>
<A, E, R>(self: Stream<A, E, R>, queue: Queue.Enqueue<Take.Take<E, A>>): Effect.Effect<void, never, Scope.Scope | R>
<A, E, R>(self: Stream<A, E, R>, queue: Queue.Enqueue<Take.Take<A, E>>): Effect.Effect<void, never, Scope.Scope | R>
} = internal.runIntoQueueScoped

/**
Expand Down Expand Up @@ -3799,11 +3799,11 @@ export const timeoutTo: {
export const toPubSub: {
(
capacity: number
): <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<PubSub.PubSub<Take.Take<E, A>>, never, Scope.Scope | R>
): <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<PubSub.PubSub<Take.Take<A, E>>, never, Scope.Scope | R>
<A, E, R>(
self: Stream<A, E, R>,
capacity: number
): Effect.Effect<PubSub.PubSub<Take.Take<E, A>>, never, Scope.Scope | R>
): Effect.Effect<PubSub.PubSub<Take.Take<A, E>>, never, Scope.Scope | R>
} = internal.toPubSub

/**
Expand Down Expand Up @@ -3834,14 +3834,14 @@ export const toQueue: {
| { readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; readonly capacity?: number | undefined }
| { readonly strategy: "unbounded" }
| undefined
): <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Queue.Dequeue<Take.Take<E, A>>, never, Scope.Scope | R>
): <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Queue.Dequeue<Take.Take<A, E>>, never, Scope.Scope | R>
<A, E, R>(
self: Stream<A, E, R>,
options?:
| { readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; readonly capacity?: number | undefined }
| { readonly strategy: "unbounded" }
| undefined
): Effect.Effect<Queue.Dequeue<Take.Take<E, A>>, never, Scope.Scope | R>
): Effect.Effect<Queue.Dequeue<Take.Take<A, E>>, never, Scope.Scope | R>
} = internal.toQueue

/**
Expand Down
Loading

0 comments on commit 5b880cb

Please sign in to comment.