-
-
Notifications
You must be signed in to change notification settings - Fork 199
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: b667ac0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 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
1179383
to
89f105c
Compare
e0712ac
to
ee7daf1
Compare
89f105c
to
b304c5c
Compare
ee7daf1
to
aea249f
Compare
b304c5c
to
dd4c6fe
Compare
aea249f
to
64c4d89
Compare
dd4c6fe
to
d6c4889
Compare
64c4d89
to
58e69ae
Compare
d6c4889
to
af13d8c
Compare
58e69ae
to
e8abb46
Compare
af13d8c
to
c730f99
Compare
ea413ed
to
5d5b65e
Compare
9a9d999
to
a8302d7
Compare
5d5b65e
to
ccc2462
Compare
a8302d7
to
6c77633
Compare
18add16
to
0f5e3bd
Compare
2b4fb20
to
338128e
Compare
0f5e3bd
to
22454df
Compare
338128e
to
e88f4a6
Compare
22454df
to
5b45da6
Compare
e88f4a6
to
b1213de
Compare
5b45da6
to
26fddcf
Compare
b1213de
to
8ab2b2c
Compare
26fddcf
to
b667ac0
Compare
Type
Description
Related