title: How to make functions work together in a single flow?
body: <p>I recently started to learn FP by using JavaScript.</p>
  <p>As you probably know JavaScript is a multi-paradigm language that can support FP and OO-style writing code. To write good code in a functional way usually, we need a library that can extend our possibilities to the next level.</p>
  <p>There are planty liabraires like <a href="https://github.com/gcanti/fp-ts" rel="nofollow noreferrer">fp-ts</a>, <a href="https://github.com/gigobyte/purify" rel="nofollow noreferrer">purify</a>, <a href="https://github.com/Effect-TS/core" rel="nofollow noreferrer">effect-ts</a>, <a href="https://github.com/evilsoft/crocks" rel="nofollow noreferrer">crocks</a> which provide us with such functionality. Most of these libraries (or all) are based on terminology and rules of <a href="https://en.wikipedia.org/wiki/Category_theory" rel="nofollow noreferrer">category theory</a>.</p>
  <p>Most of these libraries (or all) have a function like a <code>pipe</code> which allows us to create powerful functionality from the smaller functions.</p>
  <p>Normally, libraries show examples like</p>
  <pre><code>const sum = a =&gt; b =&gt; a + b
  const double = a =&gt; a * 2
  
  const doubledSum = pipe(1, sum(2), double) // 1 + 2 = 3, 3 * 2 = 6, result 6
  </code></pre>
  <p>There is nothing wrong with such examples, but they rarely have anything in common with the code of real projects.</p>
  <p>But, usually, the production code contains Promises, Nullable data, Exceptions, and even more that should play well all together.</p>
  <p>For all of the above, there is a special term in the FP libraries</p>
  <ul>
  <li>Promises = Task / Future</li>
  <li>Nullable = Option / Maybe</li>
  <li>Exceptions = Either / Result</li>
  </ul>
  <p>When these terms exist without each other (in code and in mind) everything seems to be clear. But. When you start joining them, problems arise.</p>
  <p>I'm going to list questions that block me from writing the code and hope that people who passed this step can share their experience with me (and anyone else who has the same problems)</p>
  <ol>
  <li>Is it possible to write code only using pipe? Or sometimes it makes sense to use a regular function body to put <code>if/else</code> blocks inside (for example)</li>
  <li>How to write <code>if/else</code> statements in a pipe?</li>
  <li>When to use a <code>Do</code> notation instead of a <code>chain</code>/<code>flatMap</code> and vice versa?</li>
  <li>How to work with <code>Do</code> notation? I want to achieve something like:</li>
  </ol>
  <pre><code>/* This is a pseudo-code */
  
  Do
    x &lt;- function1()
    y &lt;- function2()
    z &lt;- function3()
    a &lt;- (x, y, z) =&gt; x + y + z
    b &lt;- (x, y, z, a) =&gt; x + y + z + a
  </code></pre>
  <p>Or in other words, I don't know how to think to use a <code>Do</code> notation</p>
  <p>Any help in understanding this stuff is welcome</p>