docs: function flatMap(parent$, fn) {
    let result$;
    let listener = function updateOuterStream(result) {
      newStream(result);
    };
    function attachToResult$(mapFn, parentValue, listener) {
      let result$ = mapFn(parentValue);
      result$.listeners.push(listener);
      return result$;
    }
    let newStream = fork$(parent$, function getChildStreamValue(value) {
      result$ = attachToResult$(fn, value, listener);
      return result$.value;
    });
    parent$.listeners.push(function flatMapValue(value) {
      // clean up listeners or they will stack on child streams
      if (result$) {
        removeItem(result$.listeners, listener);
      }
  
      result$ = attachToResult$(fn, value, listener);
      newStream(result$.value);
    });
    return newStream;
  }