# Need help understanding map with bool value (Ch. 13.)

**URL:** <https://forums.kodeco.com/t/need-help-understanding-map-with-bool-value-ch-13/168477>\
**Category:** RxSwift\
**Created:** [April 7, 2022, 3:49pm UTC](https://forums.kodeco.com/t/need-help-understanding-map-with-bool-value-ch-13/168477 "2022-04-07T15:49:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lxirsh](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/lxirsh/32/110937_2.png) [@lxirsh](https://forums.kodeco.com/u/lxirsh)\
**Post date:** [April 7, 2022, 3:49pm UTC](https://forums.kodeco.com/t/need-help-understanding-map-with-bool-value-ch-13/168477/1 "2022-04-07T15:49:58Z")

</div>

In chapter 13 there is this bit of code:

```auto
let running = Observable.merge(
    searchInput.map { _ in true },
    search.map { _ in false }.asObservable()
  )
  .startWith(true)
  .asDriver(onErrorJustReturn: false)

```

And the explanation for it is as follows:  
" The two observables `searchInput` and `search` can be merged into a single observable having the value of either `true` or `false` depending on whether or not they are receiving events. The result is an observable describing whether the application is currently requesting data from the server or not."

What I’m not completely getting is why searchInput is mapped to “\_ in true”, while search is mapped to “\_ in false”. Since the activity indicator should only be shown when the user is not entering text and the data is being retrieved from the api, I’m assuming that when the user is inputting text, searchInput is mapped to false and while data is being retrieved from the api, is search mapped to true. Is this correct?

---

<div class="post-metadata">

**Author:** ![icanzilb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/icanzilb/32/109333_2.png) [@icanzilb](https://forums.kodeco.com/u/icanzilb)\
**Post date:** [April 19, 2022, 9:01am UTC](https://forums.kodeco.com/t/need-help-understanding-map-with-bool-value-ch-13/168477/2 "2022-04-19T09:01:55Z")

</div>

> [@lxirsh](#):
>
> What I’m not completely getting is why searchInput is mapped to “\_ in true”, while search is mapped to “\_ in false”.

That’s a great point, you are completely right that the name is somewhat confusing.

If you look few paragraphs further in the chapter you will see that `running` is bound to the `isHidden` property on the views. In other words when `running` is true - the activity is hidden… In this case the issue is somewhat poor naming of the variable. If it was called `isNotSearching` would’ve been more semantic and easier to understand.

---

<div class="post-metadata">

**Author:** ![lxirsh](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/lxirsh/32/110937_2.png) [@lxirsh](https://forums.kodeco.com/u/lxirsh)\
**Post date:** [August 4, 2022, 4:10pm UTC](https://forums.kodeco.com/t/need-help-understanding-map-with-bool-value-ch-13/168477/3 "2022-08-04T16:10:50Z")

</div>

Ah that makes more sense. I was so hung-up on that code fragment that I missed that. I think the syntax of “\_ in true”, “\_ in false” was also throwing me off. Does this mean that if the searchInput is active that “true in true”. i.e. “true” is returned, and when the search is active “true in false”, i.e “false” is returned?

---

<div class="post-metadata">

**Author:** ![icanzilb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/icanzilb/32/109333_2.png) [@icanzilb](https://forums.kodeco.com/u/icanzilb)\
**Post date:** [August 4, 2022, 7:42pm UTC](https://forums.kodeco.com/t/need-help-understanding-map-with-bool-value-ch-13/168477/4 "2022-08-04T19:42:23Z")

</div>

yeah, `_ in X` is basically a constant, the closure returns X whatever the input is. This is a common pattern, especially if you combine streams of values.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [September 21, 2022, 7:50am UTC](https://forums.kodeco.com/t/need-help-understanding-map-with-bool-value-ch-13/168477/5 "2022-09-21T07:50:39Z")

</div>

Closed on September 21, 2022, 7:50am UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
