From 21b324917a65d27b316b59f6281baea781158e11 Mon Sep 17 00:00:00 2001 From: gcanti Date: Fri, 22 Sep 2023 14:42:27 +0200 Subject: [PATCH] rename contramap* functions to mapInput* functions, closes #180 - Channel - contramap - contramapEffect - contramapError - contramapErrorEffect - contramapIn - contramapInEffect - contramapContext - Sink - contramap - contramapEffect - contramapChunks - contramapChunksEffect - Stream - contramapContext --- .changeset/nasty-experts-provide.md | 21 ++ docs/modules/Channel.ts.md | 306 ++++++++++++++-------------- docs/modules/Sink.ts.md | 162 +++++++-------- docs/modules/Stream.ts.md | 6 +- src/Channel.ts | 28 +-- src/Sink.ts | 12 +- src/Stream.ts | 4 +- src/internal/channel.ts | 16 +- src/internal/sink.ts | 24 +-- src/internal/stream.ts | 4 +- test/Sink/error-handling.ts | 2 +- test/Sink/mapping.ts | 40 ++-- 12 files changed, 323 insertions(+), 302 deletions(-) create mode 100644 .changeset/nasty-experts-provide.md diff --git a/.changeset/nasty-experts-provide.md b/.changeset/nasty-experts-provide.md new file mode 100644 index 0000000..2f52ed0 --- /dev/null +++ b/.changeset/nasty-experts-provide.md @@ -0,0 +1,21 @@ +--- +"@effect/stream": minor +--- + +rename contramap* functions to mapInput* functions: + +- Channel + - contramap + - contramapEffect + - contramapError + - contramapErrorEffect + - contramapIn + - contramapInEffect + - contramapContext +- Sink + - contramap + - contramapEffect + - contramapChunks + - contramapChunksEffect +- Stream + - contramapContext diff --git a/docs/modules/Channel.ts.md b/docs/modules/Channel.ts.md index bbe4e54..b6ae665 100644 --- a/docs/modules/Channel.ts.md +++ b/docs/modules/Channel.ts.md @@ -50,7 +50,7 @@ Added in v1.0.0 - [contextWith](#contextwith) - [contextWithChannel](#contextwithchannel) - [contextWithEffect](#contextwitheffect) - - [contramapContext](#contramapcontext) + - [mapInputContext](#mapinputcontext) - [provideContext](#providecontext) - [provideLayer](#providelayer) - [provideService](#provideservice) @@ -109,12 +109,6 @@ Added in v1.0.0 - [concatMapWith](#concatmapwith) - [concatMapWithCustom](#concatmapwithcustom) - [concatOut](#concatout) - - [contramap](#contramap) - - [contramapEffect](#contramapeffect) - - [contramapError](#contramaperror) - - [contramapErrorEffect](#contramaperroreffect) - - [contramapIn](#contramapin) - - [contramapInEffect](#contramapineffect) - [doneCollect](#donecollect) - [drain](#drain) - [embedInput](#embedinput) @@ -125,6 +119,12 @@ Added in v1.0.0 - [foldChannel](#foldchannel) - [interruptWhen](#interruptwhen) - [interruptWhenDeferred](#interruptwhendeferred) + - [mapInput](#mapinput) + - [mapInputEffect](#mapinputeffect) + - [mapInputError](#mapinputerror) + - [mapInputErrorEffect](#mapinputerroreffect) + - [mapInputIn](#mapinputin) + - [mapInputInEffect](#mapinputineffect) - [mergeAll](#mergeall) - [mergeAllUnbounded](#mergeallunbounded) - [mergeAllUnboundedWith](#mergeallunboundedwith) @@ -696,7 +696,7 @@ export declare const contextWithEffect: ( Added in v1.0.0 -## contramapContext +## mapInputContext Transforms the context being provided to the channel with the specified function. @@ -704,7 +704,7 @@ function. **Signature** ```ts -export declare const contramapContext: { +export declare const mapInputContext: { (f: (env: Context.Context) => Context.Context): < InErr, InElem, @@ -1863,150 +1863,6 @@ export declare const concatOut: (f: (a: InDone0) => InDone): ( - self: Channel - ) => Channel - ( - self: Channel, - f: (a: InDone0) => InDone - ): Channel -} -``` - -Added in v1.0.0 - -## contramapEffect - -Returns a new channel which is the same as this one but applies the given -effectual function to the input channel's done value. - -**Signature** - -```ts -export declare const contramapEffect: { - (f: (i: InDone0) => Effect.Effect): < - Env, - InElem, - OutErr, - OutElem, - OutDone - >( - self: Channel - ) => Channel - ( - self: Channel, - f: (i: InDone0) => Effect.Effect - ): Channel -} -``` - -Added in v1.0.0 - -## contramapError - -Returns a new channel which is the same as this one but applies the given -function to the input channel's error value. - -**Signature** - -```ts -export declare const contramapError: { - (f: (a: InErr0) => InErr): ( - self: Channel - ) => Channel - ( - self: Channel, - f: (a: InErr0) => InErr - ): Channel -} -``` - -Added in v1.0.0 - -## contramapErrorEffect - -Returns a new channel which is the same as this one but applies the given -effectual function to the input channel's error value. - -**Signature** - -```ts -export declare const contramapErrorEffect: { - (f: (error: InErr0) => Effect.Effect): < - Env, - InElem, - OutErr, - OutElem, - OutDone - >( - self: Channel - ) => Channel - ( - self: Channel, - f: (error: InErr0) => Effect.Effect - ): Channel -} -``` - -Added in v1.0.0 - -## contramapIn - -Returns a new channel which is the same as this one but applies the given -function to the input channel's output elements. - -**Signature** - -```ts -export declare const contramapIn: { - (f: (a: InElem0) => InElem): ( - self: Channel - ) => Channel - ( - self: Channel, - f: (a: InElem0) => InElem - ): Channel -} -``` - -Added in v1.0.0 - -## contramapInEffect - -Returns a new channel which is the same as this one but applies the given -effectual function to the input channel's output elements. - -**Signature** - -```ts -export declare const contramapInEffect: { - (f: (a: InElem0) => Effect.Effect): < - Env, - InDone, - OutErr, - OutElem, - OutDone - >( - self: Channel - ) => Channel - ( - self: Channel, - f: (a: InElem0) => Effect.Effect - ): Channel -} -``` - -Added in v1.0.0 - ## doneCollect Returns a new channel, which is the same as this one, except that all the @@ -2364,6 +2220,150 @@ export declare const interruptWhenDeferred: { Added in v1.0.0 +## mapInput + +Returns a new channel which is the same as this one but applies the given +function to the input channel's done value. + +**Signature** + +```ts +export declare const mapInput: { + (f: (a: InDone0) => InDone): ( + self: Channel + ) => Channel + ( + self: Channel, + f: (a: InDone0) => InDone + ): Channel +} +``` + +Added in v1.0.0 + +## mapInputEffect + +Returns a new channel which is the same as this one but applies the given +effectual function to the input channel's done value. + +**Signature** + +```ts +export declare const mapInputEffect: { + (f: (i: InDone0) => Effect.Effect): < + Env, + InElem, + OutErr, + OutElem, + OutDone + >( + self: Channel + ) => Channel + ( + self: Channel, + f: (i: InDone0) => Effect.Effect + ): Channel +} +``` + +Added in v1.0.0 + +## mapInputError + +Returns a new channel which is the same as this one but applies the given +function to the input channel's error value. + +**Signature** + +```ts +export declare const mapInputError: { + (f: (a: InErr0) => InErr): ( + self: Channel + ) => Channel + ( + self: Channel, + f: (a: InErr0) => InErr + ): Channel +} +``` + +Added in v1.0.0 + +## mapInputErrorEffect + +Returns a new channel which is the same as this one but applies the given +effectual function to the input channel's error value. + +**Signature** + +```ts +export declare const mapInputErrorEffect: { + (f: (error: InErr0) => Effect.Effect): < + Env, + InElem, + OutErr, + OutElem, + OutDone + >( + self: Channel + ) => Channel + ( + self: Channel, + f: (error: InErr0) => Effect.Effect + ): Channel +} +``` + +Added in v1.0.0 + +## mapInputIn + +Returns a new channel which is the same as this one but applies the given +function to the input channel's output elements. + +**Signature** + +```ts +export declare const mapInputIn: { + (f: (a: InElem0) => InElem): ( + self: Channel + ) => Channel + ( + self: Channel, + f: (a: InElem0) => InElem + ): Channel +} +``` + +Added in v1.0.0 + +## mapInputInEffect + +Returns a new channel which is the same as this one but applies the given +effectual function to the input channel's output elements. + +**Signature** + +```ts +export declare const mapInputInEffect: { + (f: (a: InElem0) => Effect.Effect): < + Env, + InDone, + OutErr, + OutElem, + OutDone + >( + self: Channel + ) => Channel + ( + self: Channel, + f: (a: InElem0) => Effect.Effect + ): Channel +} +``` + +Added in v1.0.0 + ## mergeAll **Signature** diff --git a/docs/modules/Sink.ts.md b/docs/modules/Sink.ts.md index 7405daa..53e67a3 100644 --- a/docs/modules/Sink.ts.md +++ b/docs/modules/Sink.ts.md @@ -98,10 +98,6 @@ Added in v1.0.0 - [foldSink](#foldsink) - [mapping](#mapping) - [as](#as) - - [contramap](#contramap) - - [contramapChunks](#contramapchunks) - - [contramapChunksEffect](#contramapchunkseffect) - - [contramapEffect](#contramapeffect) - [dimap](#dimap) - [dimapChunks](#dimapchunks) - [dimapChunksEffect](#dimapchunkseffect) @@ -109,6 +105,10 @@ Added in v1.0.0 - [map](#map) - [mapEffect](#mapeffect) - [mapError](#maperror) + - [mapInput](#mapinput) + - [mapInputChunks](#mapinputchunks) + - [mapInputChunksEffect](#mapinputchunkseffect) + - [mapInputEffect](#mapinputeffect) - [mapLeftover](#mapleftover) - [models](#models) - [Sink (interface)](#sink-interface) @@ -1337,83 +1337,6 @@ export declare const as: { Added in v1.0.0 -## contramap - -Transforms this sink's input elements. - -**Signature** - -```ts -export declare const contramap: (( - f: (input: In0) => In -) => (self: Sink) => Sink) & - ((self: Sink, f: (input: In0) => In) => Sink) -``` - -Added in v1.0.0 - -## contramapChunks - -Transforms this sink's input chunks. `f` must preserve chunking-invariance. - -**Signature** - -```ts -export declare const contramapChunks: { - (f: (chunk: Chunk.Chunk) => Chunk.Chunk): ( - self: Sink - ) => Sink - (self: Sink, f: (chunk: Chunk.Chunk) => Chunk.Chunk): Sink< - R, - E, - In0, - L, - Z - > -} -``` - -Added in v1.0.0 - -## contramapChunksEffect - -Effectfully transforms this sink's input chunks. `f` must preserve -chunking-invariance. - -**Signature** - -```ts -export declare const contramapChunksEffect: { - (f: (chunk: Chunk.Chunk) => Effect.Effect>): ( - self: Sink - ) => Sink - ( - self: Sink, - f: (chunk: Chunk.Chunk) => Effect.Effect> - ): Sink -} -``` - -Added in v1.0.0 - -## contramapEffect - -Effectfully transforms this sink's input elements. - -**Signature** - -```ts -export declare const contramapEffect: (( - f: (input: In0) => Effect.Effect -) => (self: Sink) => Sink) & - (( - self: Sink, - f: (input: In0) => Effect.Effect - ) => Sink) -``` - -Added in v1.0.0 - ## dimap Transforms both inputs and result of this sink using the provided @@ -1560,6 +1483,83 @@ export declare const mapError: { Added in v1.0.0 +## mapInput + +Transforms this sink's input elements. + +**Signature** + +```ts +export declare const mapInput: (( + f: (input: In0) => In +) => (self: Sink) => Sink) & + ((self: Sink, f: (input: In0) => In) => Sink) +``` + +Added in v1.0.0 + +## mapInputChunks + +Transforms this sink's input chunks. `f` must preserve chunking-invariance. + +**Signature** + +```ts +export declare const mapInputChunks: { + (f: (chunk: Chunk.Chunk) => Chunk.Chunk): ( + self: Sink + ) => Sink + (self: Sink, f: (chunk: Chunk.Chunk) => Chunk.Chunk): Sink< + R, + E, + In0, + L, + Z + > +} +``` + +Added in v1.0.0 + +## mapInputChunksEffect + +Effectfully transforms this sink's input chunks. `f` must preserve +chunking-invariance. + +**Signature** + +```ts +export declare const mapInputChunksEffect: { + (f: (chunk: Chunk.Chunk) => Effect.Effect>): ( + self: Sink + ) => Sink + ( + self: Sink, + f: (chunk: Chunk.Chunk) => Effect.Effect> + ): Sink +} +``` + +Added in v1.0.0 + +## mapInputEffect + +Effectfully transforms this sink's input elements. + +**Signature** + +```ts +export declare const mapInputEffect: (( + f: (input: In0) => Effect.Effect +) => (self: Sink) => Sink) & + (( + self: Sink, + f: (input: In0) => Effect.Effect + ) => Sink) +``` + +Added in v1.0.0 + ## mapLeftover Transforms the leftovers emitted by this sink using `f`. diff --git a/docs/modules/Stream.ts.md b/docs/modules/Stream.ts.md index 72bed9f..787fde5 100644 --- a/docs/modules/Stream.ts.md +++ b/docs/modules/Stream.ts.md @@ -84,7 +84,7 @@ Added in v1.0.0 - [contextWith](#contextwith) - [contextWithEffect](#contextwitheffect) - [contextWithStream](#contextwithstream) - - [contramapContext](#contramapcontext) + - [mapInputContext](#mapinputcontext) - [provideContext](#providecontext) - [provideLayer](#providelayer) - [provideService](#provideservice) @@ -1301,7 +1301,7 @@ export declare const contextWithStream: ( Added in v1.0.0 -## contramapContext +## mapInputContext Transforms the context being provided to the stream with the specified function. @@ -1309,7 +1309,7 @@ function. **Signature** ```ts -export declare const contramapContext: { +export declare const mapInputContext: { (f: (env: Context.Context) => Context.Context): (self: Stream) => Stream (self: Stream, f: (env: Context.Context) => Context.Context): Stream } diff --git a/src/Channel.ts b/src/Channel.ts index 266a98d..65211da 100644 --- a/src/Channel.ts +++ b/src/Channel.ts @@ -514,7 +514,7 @@ export const concatOut: ( * @since 1.0.0 * @category utils */ -export const contramap: { +export const mapInput: { ( f: (a: InDone0) => InDone ): ( @@ -524,7 +524,7 @@ export const contramap: { self: Channel, f: (a: InDone0) => InDone ): Channel -} = channel.contramap +} = channel.mapInput /** * Returns a new channel which is the same as this one but applies the given @@ -533,7 +533,7 @@ export const contramap: { * @since 1.0.0 * @category utils */ -export const contramapEffect: { +export const mapInputEffect: { ( f: (i: InDone0) => Effect.Effect ): ( @@ -543,7 +543,7 @@ export const contramapEffect: { self: Channel, f: (i: InDone0) => Effect.Effect ): Channel -} = channel.contramapEffect +} = channel.mapInputEffect /** * Returns a new channel which is the same as this one but applies the given @@ -552,7 +552,7 @@ export const contramapEffect: { * @since 1.0.0 * @category utils */ -export const contramapError: { +export const mapInputError: { ( f: (a: InErr0) => InErr ): ( @@ -562,7 +562,7 @@ export const contramapError: { self: Channel, f: (a: InErr0) => InErr ): Channel -} = channel.contramapError +} = channel.mapInputError /** * Returns a new channel which is the same as this one but applies the given @@ -571,7 +571,7 @@ export const contramapError: { * @since 1.0.0 * @category utils */ -export const contramapErrorEffect: { +export const mapInputErrorEffect: { ( f: (error: InErr0) => Effect.Effect ): ( @@ -581,7 +581,7 @@ export const contramapErrorEffect: { self: Channel, f: (error: InErr0) => Effect.Effect ): Channel -} = channel.contramapErrorEffect +} = channel.mapInputErrorEffect /** * Returns a new channel which is the same as this one but applies the given @@ -590,7 +590,7 @@ export const contramapErrorEffect: { * @since 1.0.0 * @category utils */ -export const contramapIn: { +export const mapInputIn: { ( f: (a: InElem0) => InElem ): ( @@ -600,7 +600,7 @@ export const contramapIn: { self: Channel, f: (a: InElem0) => InElem ): Channel -} = channel.contramapIn +} = channel.mapInputIn /** * Returns a new channel which is the same as this one but applies the given @@ -609,7 +609,7 @@ export const contramapIn: { * @since 1.0.0 * @category utils */ -export const contramapInEffect: { +export const mapInputInEffect: { ( f: (a: InElem0) => Effect.Effect ): ( @@ -619,7 +619,7 @@ export const contramapInEffect: { self: Channel, f: (a: InElem0) => Effect.Effect ): Channel -} = channel.contramapInEffect +} = channel.mapInputInEffect /** * Returns a new channel, which is the same as this one, except that all the @@ -1739,7 +1739,7 @@ export const provideLayer: { * @since 1.0.0 * @category context */ -export const contramapContext: { +export const mapInputContext: { ( f: (env: Context.Context) => Context.Context ): ( @@ -1749,7 +1749,7 @@ export const contramapContext: { self: Channel, f: (env: Context.Context) => Context.Context ): Channel -} = channel.contramapContext +} = channel.mapInputContext /** * Splits the context into two parts, providing one part using the diff --git a/src/Sink.ts b/src/Sink.ts index 0d86537..ef9708a 100644 --- a/src/Sink.ts +++ b/src/Sink.ts @@ -266,7 +266,7 @@ export const collectLeftover: ( * @since 1.0.0 * @category mapping */ -export const contramap = internal.contramap +export const mapInput = internal.mapInput /** * Effectfully transforms this sink's input elements. @@ -274,7 +274,7 @@ export const contramap = internal.contramap * @since 1.0.0 * @category mapping */ -export const contramapEffect = internal.contramapEffect +export const mapInputEffect = internal.mapInputEffect /** * Transforms this sink's input chunks. `f` must preserve chunking-invariance. @@ -282,7 +282,7 @@ export const contramapEffect = internal.contramapEffect * @since 1.0.0 * @category mapping */ -export const contramapChunks: { +export const mapInputChunks: { ( f: (chunk: Chunk.Chunk) => Chunk.Chunk ): (self: Sink) => Sink @@ -290,7 +290,7 @@ export const contramapChunks: { self: Sink, f: (chunk: Chunk.Chunk) => Chunk.Chunk ): Sink -} = internal.contramapChunks +} = internal.mapInputChunks /** * Effectfully transforms this sink's input chunks. `f` must preserve @@ -299,7 +299,7 @@ export const contramapChunks: { * @since 1.0.0 * @category mapping */ -export const contramapChunksEffect: { +export const mapInputChunksEffect: { ( f: (chunk: Chunk.Chunk) => Effect.Effect> ): (self: Sink) => Sink @@ -307,7 +307,7 @@ export const contramapChunksEffect: { self: Sink, f: (chunk: Chunk.Chunk) => Effect.Effect> ): Sink -} = internal.contramapChunksEffect +} = internal.mapInputChunksEffect /** * A sink that counts the number of elements fed to it. diff --git a/src/Stream.ts b/src/Stream.ts index 897b760..51c2911 100644 --- a/src/Stream.ts +++ b/src/Stream.ts @@ -2613,10 +2613,10 @@ export const provideServiceStream: { * @since 1.0.0 * @category context */ -export const contramapContext: { +export const mapInputContext: { (f: (env: Context.Context) => Context.Context): (self: Stream) => Stream (self: Stream, f: (env: Context.Context) => Context.Context): Stream -} = internal.contramapContext +} = internal.mapInputContext /** * Splits the context into two parts, providing one part using the diff --git a/src/internal/channel.ts b/src/internal/channel.ts index bbf541d..23e2422 100644 --- a/src/internal/channel.ts +++ b/src/internal/channel.ts @@ -261,7 +261,7 @@ export const concatOut = ( ): Channel.Channel => core.concatAll(self) /** @internal */ -export const contramap = dual< +export const mapInput = dual< ( f: (a: InDone0) => InDone ) => ( @@ -284,7 +284,7 @@ export const contramap = dual< }) /** @internal */ -export const contramapEffect = dual< +export const mapInputEffect = dual< ( f: (i: InDone0) => Effect.Effect ) => ( @@ -307,7 +307,7 @@ export const contramapEffect = dual< }) /** @internal */ -export const contramapError = dual< +export const mapInputError = dual< ( f: (a: InErr0) => InErr ) => ( @@ -330,7 +330,7 @@ export const contramapError = dual< }) /** @internal */ -export const contramapErrorEffect = dual< +export const mapInputErrorEffect = dual< ( f: (error: InErr0) => Effect.Effect ) => ( @@ -353,7 +353,7 @@ export const contramapErrorEffect = dual< }) /** @internal */ -export const contramapIn = dual< +export const mapInputIn = dual< ( f: (a: InElem0) => InElem ) => ( @@ -375,7 +375,7 @@ export const contramapIn = dual< return core.pipeTo(reader, self) }) -export const contramapInEffect = dual< +export const mapInputInEffect = dual< ( f: (a: InElem0) => Effect.Effect ) => ( @@ -2060,7 +2060,7 @@ export const provideLayer = dual< unwrapScoped(Effect.map(Layer.build(layer), (env) => core.provideContext(self, env)))) /** @internal */ -export const contramapContext = dual< +export const mapInputContext = dual< ( f: (env: Context.Context) => Context.Context ) => ( @@ -2293,7 +2293,7 @@ export const updateService = dual< tag: T, f: (resource: Context.Tag.Service) => Context.Tag.Service ): Channel.Channel => - contramapContext(self, (context: Context.Context) => + mapInputContext(self, (context: Context.Context) => Context.merge( context, Context.make(tag, f(Context.unsafeGet(context, tag))) diff --git a/src/internal/sink.ts b/src/internal/sink.ts index e5ce3c8..5e4c631 100644 --- a/src/internal/sink.ts +++ b/src/internal/sink.ts @@ -349,17 +349,17 @@ export const collectLeftover = ( new SinkImpl(pipe(core.collectElements(toChannel(self)), channel.map(([chunks, z]) => [z, Chunk.flatten(chunks)]))) /** @internal */ -export const contramap = dual< +export const mapInput = dual< (f: (input: In0) => In) => (self: Sink.Sink) => Sink.Sink, (self: Sink.Sink, f: (input: In0) => In) => Sink.Sink >( 2, (self: Sink.Sink, f: (input: In0) => In): Sink.Sink => - pipe(self, contramapChunks(Chunk.map(f))) + pipe(self, mapInputChunks(Chunk.map(f))) ) /** @internal */ -export const contramapEffect = dual< +export const mapInputEffect = dual< ( f: (input: In0) => Effect.Effect ) => (self: Sink.Sink) => Sink.Sink, @@ -373,7 +373,7 @@ export const contramapEffect = dual< self: Sink.Sink, f: (input: In0) => Effect.Effect ): Sink.Sink => - contramapChunksEffect( + mapInputChunksEffect( self, (chunk) => Effect.map( @@ -384,7 +384,7 @@ export const contramapEffect = dual< ) /** @internal */ -export const contramapChunks = dual< +export const mapInputChunks = dual< ( f: (chunk: Chunk.Chunk) => Chunk.Chunk ) => (self: Sink.Sink) => Sink.Sink, @@ -408,7 +408,7 @@ export const contramapChunks = dual< ) /** @internal */ -export const contramapChunksEffect = dual< +export const mapInputChunksEffect = dual< ( f: (chunk: Chunk.Chunk) => Effect.Effect> ) => (self: Sink.Sink) => Sink.Sink, @@ -466,7 +466,7 @@ export const dimap = dual< readonly onInput: (input: In0) => In readonly onDone: (z: Z) => Z2 } - ): Sink.Sink => map(contramap(self, options.onInput), options.onDone) + ): Sink.Sink => map(mapInput(self, options.onInput), options.onDone) ) /** @internal */ @@ -494,7 +494,7 @@ export const dimapEffect = dual< } ): Sink.Sink => mapEffect( - contramapEffect(self, options.onInput), + mapInputEffect(self, options.onInput), options.onDone ) ) @@ -524,7 +524,7 @@ export const dimapChunks = dual< } ): Sink.Sink => map( - contramapChunks(self, options.onInput), + mapInputChunks(self, options.onInput), options.onDone ) ) @@ -553,7 +553,7 @@ export const dimapChunksEffect = dual< readonly onDone: (z: Z) => Effect.Effect } ): Sink.Sink => - mapEffect(contramapChunksEffect(self, options.onInput), options.onDone) + mapEffect(mapInputChunksEffect(self, options.onInput), options.onDone) ) /** @internal */ @@ -750,7 +750,7 @@ export const filterInput: { (f: Predicate): (self: Sink.Sink) => Sink.Sink } = (f: Predicate) => { return (self: Sink.Sink): Sink.Sink => - pipe(self, contramapChunks(Chunk.filter(f))) + pipe(self, mapInputChunks(Chunk.filter(f))) } /** @internal */ @@ -768,7 +768,7 @@ export const filterInputEffect = dual< self: Sink.Sink, f: (input: In1) => Effect.Effect ): Sink.Sink => - contramapChunksEffect( + mapInputChunksEffect( self, (chunk) => Effect.map(Effect.filter(chunk, f), Chunk.unsafeFromArray) ) diff --git a/src/internal/stream.ts b/src/internal/stream.ts index 3eedf2d..7381a18 100644 --- a/src/internal/stream.ts +++ b/src/internal/stream.ts @@ -4603,7 +4603,7 @@ export const provideServiceStream = dual< ) /** @internal */ -export const contramapContext = dual< +export const mapInputContext = dual< ( f: (env: Context.Context) => Context.Context ) => (self: Stream.Stream) => Stream.Stream, @@ -6772,7 +6772,7 @@ export const updateService = dual< ): Stream.Stream => pipe( self, - contramapContext((context) => + mapInputContext((context) => pipe( context, Context.add(tag, f(pipe(context, Context.unsafeGet(tag)))) diff --git a/test/Sink/error-handling.ts b/test/Sink/error-handling.ts index d2838e6..f6811d6 100644 --- a/test/Sink/error-handling.ts +++ b/test/Sink/error-handling.ts @@ -18,7 +18,7 @@ describe.concurrent("Sink", () => { Stream.run( pipe( Sink.drain, - Sink.contramapEffect((input: number) => Effect.try(() => input)), + Sink.mapInputEffect((input: number) => Effect.try(() => input)), Sink.mapError(() => ErrorSink) ) ), diff --git a/test/Sink/mapping.ts b/test/Sink/mapping.ts index e32073d..4a666d1 100644 --- a/test/Sink/mapping.ts +++ b/test/Sink/mapping.ts @@ -18,71 +18,71 @@ describe.concurrent("Sink", () => { assert.strictEqual(result, "as") })) - it.effect("contramap - happy path", () => + it.effect("mapInput - happy path", () => Effect.gen(function*($) { const sink = pipe( Sink.collectAll(), - Sink.contramap((input: string) => Number.parseInt(input)) + Sink.mapInput((input: string) => Number.parseInt(input)) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink)) assert.deepStrictEqual(Array.from(result), [1, 2, 3]) })) - it.effect("contramap - error", () => + it.effect("mapInput - error", () => Effect.gen(function*($) { const sink = pipe( Sink.fail("Ouch"), - Sink.contramap((input: string) => Number.parseInt(input)) + Sink.mapInput((input: string) => Number.parseInt(input)) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink), Effect.either) assert.deepStrictEqual(result, Either.left("Ouch")) })) - it.effect("contramapChunks - happy path", () => + it.effect("mapInputChunks - happy path", () => Effect.gen(function*($) { const sink = pipe( Sink.collectAll(), - Sink.contramapChunks(Chunk.map((_) => Number.parseInt(_))) + Sink.mapInputChunks(Chunk.map((_) => Number.parseInt(_))) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink)) assert.deepStrictEqual(Array.from(result), [1, 2, 3]) })) - it.effect("contramapChunks - error", () => + it.effect("mapInputChunks - error", () => Effect.gen(function*($) { const sink = pipe( Sink.fail("Ouch"), - Sink.contramapChunks(Chunk.map(Number.parseInt)) + Sink.mapInputChunks(Chunk.map(Number.parseInt)) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink), Effect.either) assert.deepStrictEqual(result, Either.left("Ouch")) })) - it.effect("contramapEffect - happy path", () => + it.effect("mapInputEffect - happy path", () => Effect.gen(function*($) { const sink = pipe( Sink.collectAll(), - Sink.contramapEffect((s: string) => Effect.try(() => Number.parseInt(s))) + Sink.mapInputEffect((s: string) => Effect.try(() => Number.parseInt(s))) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink)) assert.deepStrictEqual(Array.from(result), [1, 2, 3]) })) - it.effect("contramapEffect - error", () => + it.effect("mapInputEffect - error", () => Effect.gen(function*($) { const sink = pipe( Sink.fail("Ouch"), - Sink.contramapEffect((s: string) => Effect.try(() => Number.parseInt(s))) + Sink.mapInputEffect((s: string) => Effect.try(() => Number.parseInt(s))) ) const result = yield* $(Stream.make("1", "2", "3"), Stream.run(sink), Effect.either) assert.deepStrictEqual(result, Either.left("Ouch")) })) - it.effect("contramapEffect - error in transformation", () => + it.effect("mapInputEffect - error in transformation", () => Effect.gen(function*($) { const sink = pipe( Sink.collectAll(), - Sink.contramapEffect((s: string) => + Sink.mapInputEffect((s: string) => Effect.try(() => { const result = Number.parseInt(s) if (Number.isNaN(result)) { @@ -96,11 +96,11 @@ describe.concurrent("Sink", () => { assert.deepStrictEqual(result, Either.left(Cause.RuntimeException("Cannot parse \"a\" to an integer"))) })) - it.effect("contramapChunksEffect - happy path", () => + it.effect("mapInputChunksEffect - happy path", () => Effect.gen(function*($) { const sink = pipe( Sink.collectAll(), - Sink.contramapChunksEffect((chunk: Chunk.Chunk) => + Sink.mapInputChunksEffect((chunk: Chunk.Chunk) => pipe( chunk, Effect.forEach((s) => Effect.try(() => Number.parseInt(s))), @@ -112,11 +112,11 @@ describe.concurrent("Sink", () => { assert.deepStrictEqual(Array.from(result), [1, 2, 3]) })) - it.effect("contramapChunksEffect - error", () => + it.effect("mapInputChunksEffect - error", () => Effect.gen(function*($) { const sink = pipe( Sink.fail("Ouch"), - Sink.contramapChunksEffect((chunk: Chunk.Chunk) => + Sink.mapInputChunksEffect((chunk: Chunk.Chunk) => pipe( chunk, Effect.forEach((s) => Effect.try(() => Number.parseInt(s))), @@ -128,11 +128,11 @@ describe.concurrent("Sink", () => { assert.deepStrictEqual(result, Either.left("Ouch")) })) - it.effect("contramapChunksEffect - error in transformation", () => + it.effect("mapInputChunksEffect - error in transformation", () => Effect.gen(function*($) { const sink = pipe( Sink.collectAll(), - Sink.contramapChunksEffect((chunk: Chunk.Chunk) => + Sink.mapInputChunksEffect((chunk: Chunk.Chunk) => pipe( chunk, Effect.forEach((s) =>