3 ms·
Can you expand on this, maybe show some examples? I’m familiar with RxJS and have always thought it would be nice to have some syntax sugar for common operatio
by __ryan__ 5y ago
Can you expand on this, maybe show some examples?
I’m familiar with RxJS and have always thought it would be nice to have some syntax sugar for common operations. But I’m not sure how the concept would apply to monads in general.
- manx 5y agoInside an async block, the await keyword stands for then/flatMap/bind. Using multiple awaits is the same as a chain of then/flatMap/bind, or the do-notation in Haskell. async { const a = await getA(); const b = await getB(a); return await getC(b); } Is the same as: getA().then((a) => getB(a)).then((b) => getC(b)); Observable is interesting, because it has multiple flatMap variations, like concatMap, switchMap etc. There could be different await keywords that represent these operators. Example: asyncObservable { const request = await myRequestStream(); const response = switchMap sendRequest(request); return response; } This should be equivalent to: myRequestStream().switchMap((request) => sendRequest(request)) In general, the advantage of this syntax is, that you can work on die values directly, instead of needing to work with the Observable.
- manx 5y agoReact hooks with useState are very similar.