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

Commit

Permalink
fix filterMap tacit usage (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Sep 27, 2023
1 parent f9ebdf4 commit 0e4c6d1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-yaks-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/stream": patch
---

fix filterMap tacit usage
30 changes: 16 additions & 14 deletions docs/modules/Stream.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4050,8 +4050,8 @@ Performs a filter and map in a single step.
```ts
export declare const filterMap: {
<A, X extends A, B>(pf: (a: X) => Option.Option<B>): <R, E>(self: Stream<R, E, A>) => Stream<R, E, B>
<R, E, A, X extends A, B>(self: Stream<R, E, A>, pf: (a: X) => Option.Option<B>): Stream<R, E, B>
<A, B>(pf: (a: A) => Option.Option<B>): <R, E>(self: Stream<R, E, A>) => Stream<R, E, B>
<R, E, A, B>(self: Stream<R, E, A>, pf: (a: A) => Option.Option<B>): Stream<R, E, B>
}
```
Expand All @@ -4065,13 +4065,14 @@ Performs an effectful filter and map in a single step.
```ts
export declare const filterMapEffect: {
<A, X extends A, R2, E2, A2>(pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>): <R, E>(
<A, R2, E2, A2>(pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>): <R, E>(
self: Stream<R, E, A>
) => Stream<R2 | R, E2 | E, A2>
<R, E, A, X extends A, R2, E2, A2>(
self: Stream<R, E, A>,
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
): Stream<R | R2, E | E2, A2>
<R, E, A, R2, E2, A2>(self: Stream<R, E, A>, pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>): Stream<
R | R2,
E | E2,
A2
>
}
```
Expand All @@ -4086,8 +4087,8 @@ function is defined.
```ts
export declare const filterMapWhile: {
<A, X extends A, A2>(pf: (a: X) => Option.Option<A2>): <R, E>(self: Stream<R, E, A>) => Stream<R, E, A2>
<R, E, A, X extends A, A2>(self: Stream<R, E, A>, pf: (a: X) => Option.Option<A2>): Stream<R, E, A2>
<A, A2>(pf: (a: A) => Option.Option<A2>): <R, E>(self: Stream<R, E, A>) => Stream<R, E, A2>
<R, E, A, A2>(self: Stream<R, E, A>, pf: (a: A) => Option.Option<A2>): Stream<R, E, A2>
}
```
Expand All @@ -4102,13 +4103,14 @@ specified partial function is defined.
```ts
export declare const filterMapWhileEffect: {
<A, X extends A, R2, E2, A2>(pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>): <R, E>(
<A, R2, E2, A2>(pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>): <R, E>(
self: Stream<R, E, A>
) => Stream<R2 | R, E2 | E, A2>
<R, E, A, X extends A, R2, E2, A2>(
self: Stream<R, E, A>,
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
): Stream<R | R2, E | E2, A2>
<R, E, A, R2, E2, A2>(self: Stream<R, E, A>, pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>): Stream<
R | R2,
E | E2,
A2
>
}
```
Expand Down
24 changes: 12 additions & 12 deletions src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,8 @@ export const filterEffect: {
* @category utils
*/
export const filterMap: {
<A, X extends A, B>(pf: (a: X) => Option.Option<B>): <R, E>(self: Stream<R, E, A>) => Stream<R, E, B>
<R, E, A, X extends A, B>(self: Stream<R, E, A>, pf: (a: X) => Option.Option<B>): Stream<R, E, B>
<A, B>(pf: (a: A) => Option.Option<B>): <R, E>(self: Stream<R, E, A>) => Stream<R, E, B>
<R, E, A, B>(self: Stream<R, E, A>, pf: (a: A) => Option.Option<B>): Stream<R, E, B>
} = internal.filterMap

/**
Expand All @@ -1197,12 +1197,12 @@ export const filterMap: {
* @category utils
*/
export const filterMapEffect: {
<A, X extends A, R2, E2, A2>(
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
<A, R2, E2, A2>(
pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>
): <R, E>(self: Stream<R, E, A>) => Stream<R2 | R, E2 | E, A2>
<R, E, A, X extends A, R2, E2, A2>(
<R, E, A, R2, E2, A2>(
self: Stream<R, E, A>,
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>
): Stream<R | R2, E | E2, A2>
} = internal.filterMapEffect

Expand All @@ -1214,8 +1214,8 @@ export const filterMapEffect: {
* @category utils
*/
export const filterMapWhile: {
<A, X extends A, A2>(pf: (a: X) => Option.Option<A2>): <R, E>(self: Stream<R, E, A>) => Stream<R, E, A2>
<R, E, A, X extends A, A2>(self: Stream<R, E, A>, pf: (a: X) => Option.Option<A2>): Stream<R, E, A2>
<A, A2>(pf: (a: A) => Option.Option<A2>): <R, E>(self: Stream<R, E, A>) => Stream<R, E, A2>
<R, E, A, A2>(self: Stream<R, E, A>, pf: (a: A) => Option.Option<A2>): Stream<R, E, A2>
} = internal.filterMapWhile

/**
Expand All @@ -1226,12 +1226,12 @@ export const filterMapWhile: {
* @category utils
*/
export const filterMapWhileEffect: {
<A, X extends A, R2, E2, A2>(
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
<A, R2, E2, A2>(
pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>
): <R, E>(self: Stream<R, E, A>) => Stream<R2 | R, E2 | E, A2>
<R, E, A, X extends A, R2, E2, A2>(
<R, E, A, R2, E2, A2>(
self: Stream<R, E, A>,
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>
): Stream<R | R2, E | E2, A2>
} = internal.filterMapWhileEffect

Expand Down
46 changes: 23 additions & 23 deletions src/internal/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2383,28 +2383,28 @@ export const filterEffect = dual<

/** @internal */
export const filterMap = dual<
<A, X extends A, B>(pf: (a: X) => Option.Option<B>) => <R, E>(self: Stream.Stream<R, E, A>) => Stream.Stream<R, E, B>,
<R, E, A, X extends A, B>(self: Stream.Stream<R, E, A>, pf: (a: X) => Option.Option<B>) => Stream.Stream<R, E, B>
<A, B>(pf: (a: A) => Option.Option<B>) => <R, E>(self: Stream.Stream<R, E, A>) => Stream.Stream<R, E, B>,
<R, E, A, B>(self: Stream.Stream<R, E, A>, pf: (a: A) => Option.Option<B>) => Stream.Stream<R, E, B>
>(
2,
<R, E, A, X extends A, B>(self: Stream.Stream<R, E, A>, pf: (a: X) => Option.Option<B>): Stream.Stream<R, E, B> =>
mapChunks(self, Chunk.filterMap(pf as (a: A) => Option.Option<B>))
<R, E, A, B>(self: Stream.Stream<R, E, A>, pf: (a: A) => Option.Option<B>): Stream.Stream<R, E, B> =>
mapChunks(self, Chunk.filterMap(pf))
)

/** @internal */
export const filterMapEffect = dual<
<A, X extends A, R2, E2, A2>(
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
<A, R2, E2, A2>(
pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>
) => <R, E>(self: Stream.Stream<R, E, A>) => Stream.Stream<R2 | R, E2 | E, A2>,
<R, E, A, X extends A, R2, E2, A2>(
<R, E, A, R2, E2, A2>(
self: Stream.Stream<R, E, A>,
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>
) => Stream.Stream<R2 | R, E2 | E, A2>
>(
2,
<R, E, A, X extends A, R2, E2, A2>(
<R, E, A, R2, E2, A2>(
self: Stream.Stream<R, E, A>,
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>
): Stream.Stream<R | R2, E | E2, A2> =>
suspend(() => {
const loop = (
Expand All @@ -2419,7 +2419,7 @@ export const filterMapEffect = dual<
})
} else {
return pipe(
pf(next.value as X),
pf(next.value),
Option.match({
onNone: () => Effect.sync(() => loop(iterator)),
onSome: Effect.map((a2) => core.flatMap(core.write(Chunk.of(a2)), () => loop(iterator)))
Expand All @@ -2434,16 +2434,16 @@ export const filterMapEffect = dual<

/** @internal */
export const filterMapWhile = dual<
<A, X extends A, A2>(
pf: (a: X) => Option.Option<A2>
<A, A2>(
pf: (a: A) => Option.Option<A2>
) => <R, E>(self: Stream.Stream<R, E, A>) => Stream.Stream<R, E, A2>,
<R, E, A, X extends A, A2>(self: Stream.Stream<R, E, A>, pf: (a: X) => Option.Option<A2>) => Stream.Stream<R, E, A2>
<R, E, A, A2>(self: Stream.Stream<R, E, A>, pf: (a: A) => Option.Option<A2>) => Stream.Stream<R, E, A2>
>(
2,
<R, E, A, X extends A, A2>(self: Stream.Stream<R, E, A>, pf: (a: X) => Option.Option<A2>) => {
<R, E, A, A2>(self: Stream.Stream<R, E, A>, pf: (a: A) => Option.Option<A2>) => {
const loop: Channel.Channel<never, E, Chunk.Chunk<A>, unknown, E, Chunk.Chunk<A2>, unknown> = core.readWith({
onInput: (input: Chunk.Chunk<A>) => {
const mapped = Chunk.filterMapWhile(input, pf as (a: A) => Option.Option<A2>)
const mapped = Chunk.filterMapWhile(input, pf)
if (mapped.length === input.length) {
return pipe(core.write(mapped), core.flatMap(() => loop))
}
Expand All @@ -2458,18 +2458,18 @@ export const filterMapWhile = dual<

/** @internal */
export const filterMapWhileEffect = dual<
<A, X extends A, R2, E2, A2>(
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
<A, R2, E2, A2>(
pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>
) => <R, E>(self: Stream.Stream<R, E, A>) => Stream.Stream<R2 | R, E2 | E, A2>,
<R, E, A, X extends A, R2, E2, A2>(
<R, E, A, R2, E2, A2>(
self: Stream.Stream<R, E, A>,
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>
) => Stream.Stream<R2 | R, E2 | E, A2>
>(
2,
<R, E, A, X extends A, R2, E2, A2>(
<R, E, A, R2, E2, A2>(
self: Stream.Stream<R, E, A>,
pf: (a: X) => Option.Option<Effect.Effect<R2, E2, A2>>
pf: (a: A) => Option.Option<Effect.Effect<R2, E2, A2>>
): Stream.Stream<R | R2, E | E2, A2> =>
suspend(() => {
const loop = (
Expand All @@ -2484,7 +2484,7 @@ export const filterMapWhileEffect = dual<
})
} else {
return channel.unwrap(
Option.match(pf(next.value as X), {
Option.match(pf(next.value), {
onNone: () => Effect.succeed(core.unit),
onSome: Effect.map(
(a2) => core.flatMap(core.write(Chunk.of(a2)), () => loop(iterator))
Expand Down

0 comments on commit 0e4c6d1

Please sign in to comment.