RxJS - combine transformed items onto a data flow

Is there an operator that allows me to iterate over elements of a stream and concatenate them instead of transforming them?

Consider the following stream:

A => B => C

If I use items$.concatMap(x => f(x)), the result will be:

"f(A)" => "f(B)" => "f(C)"

Using the concat operator won't work as it doesn't receive individual elements as parameters.

What I want to achieve is:

"A" => "B" => "C" => "f(A)" => "f(B)" => "f(C)"

One way to do this is by breaking up the stream and storing it as follows:

item$ = Observable.of("A","B","C");

item$.concat(item$.map(x => f(x)));

Answer №1

After much searching, I finally stumbled upon the perfect operator for this task (at the time of writing, it was nowhere to be found in the RxJS 5 documentation). It goes by the name of let and graciously provides the entire current observable as an argument.

item$.let(obs$ => obs$.concat(obs$.map(f));

Although it may not seem overly impressive when used as the initial operation, it becomes incredibly handy when you have other operations preceding it and wish to avoid pausing to store the stream in a local variable:

item$.debounce(1000)
     .map(z => f(z.id))
     .moreOperators(...)
     .let(obs$ => obs$.concat(obs$.map(f));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for managing child records while the parent record is still being created

When dealing with creating or editing an Excursion record, there is a form that includes nested excursion_images, which are created through a remote call using JavaScript (Fine Uploader). While this solution works perfectly for editing an Excursion, it en ...

Utilizing JSON data to generate an HTML webpage showcasing a collection of community districts through the power of JavaScript

As a beginner in javascript, I am working with a JSON file that contains an array of objects. Each object includes two properties: a borough and mappings. Mappings have two sub-properties called macro and neighborhoods. The macro represents a larger neighb ...

Is the concept of client fanout truly beneficial?

I'm in the process of constructing a community platform on firebase that features timelines and posts similar to those found on Facebook. When a user creates a post, it should automatically appear on the timelines of their followers. Google proposes ...

Finding the common dates between two date arrays in Node.js

Looking for help with correctly intersecting matrices while working in nodejs? Trying to compare two arrays to find common elements, also known as an "array intersection." This seems to be a common question, and despite trying various solutions mentioned o ...

Style selector for dynamic drop-down menus

import React, { Component } from "react"; export default class FontChanger extends Component{ constructor(props){ super(props); this.state ={ selectedFont: "", currentFont: "", }; this.handleFon ...

Effortless 'rotational' script

I am currently developing a HTML5 Canvas game with the help of JavaScript. My aim is to create an object that smoothly transitions to a specific direction. The direction is being stored as a variable and calculated in radians. Here's how the code op ...

What is the best way to dynamically insert an email value into a JSON file?

Here is the structure of my JSON file: test.json: { "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3b8a1baa093beb2babfbabdb2a7bca1fdb0bcbe">[email protected]</a>", "password": "Sanju@143", ...

Unusual behavior exhibited by dynamic code in iframe

When trying to retrieve a dynamic height iframe, I implement the code below. In the <head> area <script language="javascript" type="text/javascript"> function adjustIframe(obj) { obj.style.height = obj.contentWindow.document.body.scrollHeight ...

Showcase -solely one property object- from numerous property objects enclosed within an array

Hello, I am seeking assistance as I have recently begun learning about angularJS. I am working with objects that have keys such as: scope.eventList=[]; for(){ var event = { id : hash, ...

Save the information fetched using the 'fetch' method into a different .js document when working with React

Here is the code I am working on: const fetchData = () => fetch("https://api.myjson.com/bins/mp441") .then(response => response.json()) .then(obj => data = obj); const RECORD_NOS = Object.keys(data).length - 1; export { fetchData, ...

Using JavaScript to display a line using `document.write`

I'm having trouble displaying a line using the Document.Write function in JavaScript. When I submit the form, the line briefly appears and then disappears Any ideas on why this might be happening? <!DOCTYPE html> <html> <head& ...

Utilizing CSS transitions to smoothly adjust the width of an element until it completely fills the container div in ReactJS

import React from 'react'; import PropTypes from 'prop-types'; import SearchIcon from '@material-ui/icons/Search'; import InputBase from '@material-ui/core/InputBase'; import { AccountCircle } from '@material-ui ...

problem with passing the identification number into the function

I am facing an issue with passing the id into a javascript onClick method. I am using the Spring framework and in the controller class, I send the related id to the JSP file like this: model.addAttribute("uploadid", uploadid); Afterwards, I need to p ...

Having trouble with submitting a Vue.js form when toggling the visibility of a bootstrap panel?

There are three bootstrap panels that are displayed depending on the selection made in the select element: <div class="panel panel-default"> <Select/> </div> <div class="panel panel-default" v-if="fileMode == 0"></div> <d ...

Scheduling tasks for jQuery/Javascript like a Cronjob

I'm currently working on a web application that predominantly uses PHP, however, I am incorporating jQuery/Javascript to retrieve Tweets from users' URLs at http://twitter.com/status/user_timeline/joebloggs.json?count=1&callback=. My aim is ...

Using Angular, implementing conditional statements within a for loop

I am currently working on a project where I have an array being looped inside a tag, using the target="_blank" attribute. The issue is that one of the elements in the array should not have this target="_blank" attribute. What would be the best course of ...

Guide on leveraging event delegation to trigger a function depending on the id of the clicked element

Although I have experience with event delegation, I am currently facing a challenge in setting up a single event listener that can execute one of three functions based on the ID of the element clicked. Here is the existing code without event delegation: ...

Is there a way to have one element automatically expand when another is selected?

I'm currently utilizing the date and time picker from . However, I need some assistance with the current setup. Currently, the date and time pickers are in separate input fields. In order to select a date, I have to click on the Date input field, and ...

Utilizing webpack, gulp, and typescript to efficiently incorporate jQuery plugins

I'm having trouble figuring out the correct way to load third-party libraries that have dependencies on each other. I am using TypeScript and Gulp with either Webpack or SystemJS for my module loader, both of which are throwing similar errors in this ...

Managing multiple Socket.io connections upon page reload

I am currently developing a real-time application and utilizing Socket.io for its functionality. At the moment, my setup involves receiving user-posted messages through the socket server, saving this data to a MySQL database via the controller, and then b ...