<commit_before>const {find, filter, forEach, pluck, propEq} = require('ramda');
const asArray = require('./asArray');
const connect = require('./connect');

module.exports = function (virtualNodes, handleConnectionToOutput = ()=>{}) {
  forEach((virtualAudioNode) =>
    forEach((connection) => {
      if (connection === 'output') {
        return handleConnectionToOutput(virtualAudioNode);
      }

      if (Object.prototype.toString.call(connection) === '[object Object]') {
        const {id, destination} = connection;
        const destinationVirtualAudioNode = find(propEq('id', id))(virtualNodes);

        return connect(virtualAudioNode,
                       destinationVirtualAudioNode.audioNode[destination]);
      }

      const destinationVirtualAudioNode = find(propEq('id', connection))(virtualNodes);

      if (destinationVirtualAudioNode.isCustomVirtualNode) {
        return forEach(connect(virtualAudioNode),
                       pluck('audioNode',
                             filter(propEq('input', 'input'),
                                    destinationVirtualAudioNode.virtualNodes)));
      }

      connect(virtualAudioNode, destinationVirtualAudioNode.audioNode);
    }, asArray(virtualAudioNode.output)), filter(propEq('connected', false),
                                                 virtualNodes));
};
<commit_msg>update for new api<commit_after>const {equals, filter, forEach, keys, pluck, propEq, values} = require('ramda');
const asArray = require('./asArray');
const connect = require('./connect');

const isPlainOldObject = x => equals(Object.prototype.toString.call(x),
                                     '[object Object]');

module.exports = (virtualGraph, handleConnectionToOutput = () => {}) =>
  forEach(id => {
            const virtualNode = virtualGraph[id];
            if (virtualNode.connected) {
              return;
            }
            forEach(output => {
                      if (output === 'output') {
                        return handleConnectionToOutput(virtualNode);
                      }

                      if (isPlainOldObject(output)) {
                        const {id, destination} = output;
                        return connect(virtualNode,
                                       virtualGraph[id].audioNode[destination]);
                      }

                      const destinationVirtualAudioNode = virtualGraph[output];

                      if (destinationVirtualAudioNode.isCustomVirtualNode) {
                        return forEach(connect(virtualNode),
                                       pluck('audioNode',
                                             filter(propEq('input', 'input'),
                                                    values(destinationVirtualAudioNode.virtualNodes))));
                      }

                      connect(virtualNode, destinationVirtualAudioNode.audioNode);
                    },
                    asArray(virtualNode.output));
          },
          keys(virtualGraph));

{'fraction_non_alphanumeric': 0.10971579643093192, 'fraction_numerical': 0.0, 'mean_word_length': 1.8053753475440222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5692936', 'n_tokens_mistral': 678, 'n_tokens_neox': 647, 'n_words': 121}