-
-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Stream): switchMap #2974
base: next-minor
Are you sure you want to change the base?
feat(Stream): switchMap #2974
Conversation
🦋 Changeset detectedLatest commit: d86a416 The changes in this PR will be included in the next version bump. This PR includes changesets to release 31 packages
Not sure what this means? Click here to learn what changesets are. Click here if you"re a maintainer who wants to add another changeset to this PR |
b6ce3f9
to
3572b58
Compare
3dbb34c
to
e843763
Compare
What is the benefit over |
3572b58
to
b9ea946
Compare
168da4f
to
22c9547
Compare
I guess just verbosity, not sure if this is common enough to justify it |
RxJS also do have a switchMap operator, and it"s one of the most important and widely used operator. I decided to make it as a separate operator not just because of verbosity, but because of clarity and visualization. This is a real code from my project export const BinanceWsUnitSingleLayer = Layer.effect(
BinanceWsUnitTag,
Effect.gen(function* () {
// ....................................................................
return {
createStream(
stream: string,
): Stream.Stream<
unknown,
| BinanceWsConnectionError
| BinanceWsResponseError
| BinanceWsConnectionCloseError
> {
return Stream.suspend(() => {
debug(`📤Requesting stream "${stream}"`);
let stream$ = streams.get(stream);
if (stream$) {
return stream$;
}
stream$ = connection.pipe(
Stream.flatMap(
(ws) =>
Effect.request(
BinanceWsSubscribeRequest({ stream, ws }),
RequestResolver.contextFromEffect(subscribe),
).pipe(
Stream.unwrap,
Stream.ensuring(
Effect.gen(function* () {
debug(`🔻 Unsubscribing ${stream}`);
streams.delete(stream);
yield* Effect.request(
BinanceWsUnsubscribeRequest({ stream, ws }),
RequestResolver.contextFromEffect(unsubscribe),
);
}),
),
),
{ switch: true, concurrency: 1 },
),
);
streams.set(stream, stream$);
return stream$;
});
},
} satisfies BinanceWsUnit;
}),
) When you fluently read this code, it is not really easy to notice the
And it doesn"t describes this concept. Actually, i thinks that the |
f51ab48
to
31a5555
Compare
22c9547
to
e355abe
Compare
31a5555
to
5ec3fa4
Compare
e355abe
to
9be706e
Compare
5ec3fa4
to
a48c616
Compare
3ef9f71
to
ec3e6ba
Compare
fe1d97d
to
a247c84
Compare
ec3e6ba
to
883f4a3
Compare
a247c84
to
7db7767
Compare
883f4a3
to
d39cc11
Compare
7db7767
to
83632b3
Compare
d39cc11
to
e4e460a
Compare
83632b3
to
5fbc6fd
Compare
e4e460a
to
4bf8364
Compare
5fbc6fd
to
ac70b32
Compare
4bf8364
to
a3c5770
Compare
ac70b32
to
db63b92
Compare
a3c5770
to
aad62bd
Compare
bbe556f
to
df7f007
Compare
df7f007
to
d425963
Compare
ee1f1cd
to
1576be0
Compare
Type
Description
Related