Currently, my code is set up to transform an Observable<string[]> into an Observable<string>, emitting the values one second apart from each other. It's like a message ticker on a website.
Here's how it works at the moment:
const arrayOfStrings$ = of([
'Warming things up',
'Getting things ready',
'Welcome'
]);
this.messages$ = arrayOfStrings$.pipe(
switchMap((messages) => from(messages).pipe(
concatMap((innerMessage) => of(innerMessage).pipe(delay(1000))),
)),
tap((message) => {
console.log(`Message: ${message}`);
})
);
I'm wondering if there's a more concise way to achieve the same outcome with less code. The nesting of switchMap()
and concatMap()
is a bit cumbersome for me.
Any suggestions or advice would be greatly appreciated.
Edit: The example provided here is a simplified version of what I'm currently working on in my project. I'm looking for a simpler method to transition from an Observable<string[]> to an Observable while adding a one-second delay between emissions.