title: Map IO to array of Either in fp-ts
body: <p>Can anyone help me to figure out how to do this in <code>fp-ts</code>?</p>
  
  <pre class="lang-js prettyprint-override"><code>const $ = cheerio.load('some text');
  const tests = $('table tr').get()
    .map(row =&gt; $(row).find('a'))
    .map(link =&gt; link.attr('data-test') ? link.attr('data-test') : null)
    .filter(v =&gt; v != null);
  </code></pre>
  
  <p>I can do it all with <code>TaskEither</code> but I don't know how to mix it with <code>IO</code>, or maybe I shouldn't use <code>IO</code> at all?</p>
  
  <p>This is what I came up with so far:</p>
  
  <pre class="lang-js prettyprint-override"><code>const selectr = (a: CheerioStatic): CheerioSelector =&gt; (s: any, c?: any, r?: any) =&gt; a(s, c, r);
  
  const getElementText = (text: string) =&gt; {
    return pipe(
      IO.of(cheerio.load),
      IO.ap(IO.of(text)),
      IO.map(selectr),
      IO.map(x =&gt; x('table tr')),
      // ?? don't know what to do here
    );
  }
  
  </code></pre>
  
  <h3>Update:</h3>
  
  <p>I must mention and clarify the most challenging part for me is how to change typings from <code>IO</code> to an array of <code>Either</code> and then filter or ignore the <code>left</code>s and continue with <code>Task</code> or <code>TaskEither</code></p>
  
  <p>TypeScript error is <code>Type 'Either&lt;Error, string[]&gt;' is not assignable to type 'IO&lt;unknown&gt;'</code></p>
  
  <pre><code>const getAttr = (attrName: string) =&gt; (el: Cheerio): Either&lt;Error, string&gt; =&gt; {
    const value = el.attr(attrName);
    return value ? Either.right(value) : Either.left(new Error('Empty attribute!'));
  }
  
  const getTests = (text: string) =&gt; {
    const $ = cheerio.load(text);
    return pipe(
      $('table tbody'),
      getIO,
      // How to go from IO&lt;string&gt; to IOEither&lt;unknown, string[]&gt; or something similar?
      // What happens to the array of errors do we keep them or we just change the typings?
      IO.chain(rows =&gt; A.array.traverse(E.either)(rows, flow($, attrIO('data-test)))),
    );
  </code></pre>