<commit_before># mergeMap
#### signature: `mergeMap(project: function: Observable, resultSelector: function: any, concurrent: number): Observable`

### Description

###### TL;DR: Map values from source to inner observable, merge output

The **mergeMap** operator takes a project function, subscribing to the returned observable and emitting the output.

__*For instance...*__

Suppose you are initiating an HTTP request, for the sake of example we can imagine a `makeRequest` method which <sup>1</sup>returns an observable.
The `mergeMap` operator will subscribe to this <sup>2</sup>observable, emitting the result to the outer subscriber. 


```js
Observable.of(url)
 /*
    The observable returned from the makeRequest method will be subscribed to, 
    creating an inner subscription.
    Values emitted from this inner observable will be emitted to the outer subscriber, 
    ie the next operator or subscribe function.
 */
  .mergeMap(makeRequest);
```

If a promise is returned from the provided function, `.then` will be called with the result emitted to the outer subscriber.

```js
Observable.of(url)
  /*
    Promises are also fine, the result will be emitted.
  */
  .mergeMap(makePromiseRequest)
```

Lastly, if an array or iterable is returned each item will be emitted in sequence. For instance:

```js
Observable.of([1,2,3])
  .mergeMap(arr => arr)
```

Will emit:

```bash
1
2
3
```

<sup>1</sup> *This is an example of an Observable of Observables.*

<sup>2</sup> *You will see this referred to as the inner observable.*


---
:bulb:  flatMap is an alias for mergeMap!

:bulb: If the order of emission and subscription of inner observables is important, try [`concatMap`](concatmap.md)!

---

### Examples

##### Example 1: mergeMap with observable

( [jsBin](http://jsbin.com/mojurubana/1/edit?js,console) | [jsFiddle](https://jsfiddle.net/btroncone/41awjgda/) )

```js
//emit 'Hello'
const source = Rx.Observable.of('Hello');
//map to inner observable and flatten
const example = source.mergeMap(val => Rx.Observable.of(`${val} World!`));
//output: 'Hello World!'
const subscribe = example.subscribe(val => console.log(val));
```

##### Example 2: mergeMap with promise
<commit_msg>Update wording<commit_after># mergeMap
#### signature: `mergeMap(project: function: Observable, resultSelector: function: any, concurrent: number): Observable`

### Description

###### TL;DR: Map values from source to inner observable, merge output

The **mergeMap** operator takes a project function, subscribing to the returned observable and emitting the output.

__*For instance...*__

Suppose you are initiating an HTTP request, for the sake of example we can imagine a `makeRequest` method which <sup>1</sup>returns an observable.
The `mergeMap` operator will subscribe to this <sup>2</sup>observable, emitting the result to the outer subscriber. 


```js
Observable.of(url)
 /*
    The observable returned from the makeRequest method will be subscribed to, 
    creating an inner subscription.
    Values emitted from this inner observable will be emitted to the outer subscriber, 
    ie the next operator or subscribe function.
 */
  .mergeMap(makeRequest);
```

If a promise is returned from the provided function, `.then` will be called with the result emitted to the outer subscriber.

```js
Observable.of(url)
  /*
    Promises are also fine, the result will be emitted.
  */
  .mergeMap(makePromiseRequest)
```

Lastly, if an array or iterable is returned each item will be emitted in sequence. For instance:

```js
Observable.of([1,2,3])
  .mergeMap(arr => arr)
```

Will emit:

```bash
1
2
3
```

<sup>1</sup> *This is an example of an Observable of Observables.*

<sup>2</sup> *This is eferred to as the inner observable.*


---
:bulb:  flatMap is an alias for mergeMap!

:bulb: If the order of emission and subscription of inner observables is important, try [`concatMap`](concatmap.md)!

---

### Examples

##### Example 1: mergeMap with observable

( [jsBin](http://jsbin.com/mojurubana/1/edit?js,console) | [jsFiddle](https://jsfiddle.net/btroncone/41awjgda/) )

```js
//emit 'Hello'
const source = Rx.Observable.of('Hello');
//map to inner observable and flatten
const example = source.mergeMap(val => Rx.Observable.of(`${val} World!`));
//output: 'Hello World!'
const subscribe = example.subscribe(val => console.log(val));
```

##### Example 2: mergeMap with promise

{'fraction_non_alphanumeric': 0.12067395264116576, 'fraction_numerical': 0.006830601092896175, 'mean_word_length': 4.463930348258707, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5778541', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1251, 'n_words': 511}