<commit_before>package com.elpassion.intelijidea.action.configure.selector

import com.elpassion.intelijidea.getTemplateConfigurations
import com.elpassion.intelijidea.task.MFBeforeRunTask
import com.intellij.execution.RunManagerEx
import com.intellij.execution.configurations.RunConfiguration
import com.intellij.openapi.project.Project
import io.reactivex.Maybe

typealias MFUiSelector = (List<MFSelectorItem>) -> Maybe<MFSelectorResult>

fun mfSelector(project: Project, uiSelector: MFUiSelector): Maybe<MFSelectorResult> =
        with(RunManagerEx.getInstanceEx(project)) {
            uiSelector(getConfigurationItems() + getTemplateConfigurationItems())
        }

fun getSelectorResult(uiIn: List<MFSelectorItem>, uiOut: List<MFSelectorItem>): MFSelectorResult {
    if (uiOut != uiIn) {
        val toInject = (uiOut.filter { it.isSelected } - uiIn.filter { it.isSelected })
                .map(MFSelectorItem::configuration)
        val toRestore = (uiOut.filterNot { it.isSelected } - uiIn.filterNot { it.isSelected })
                .map(MFSelectorItem::configuration)
        return MFSelectorResult(toInject, toRestore)
    } else {
        return MFSelectorResult(emptyList(), emptyList())
    }
}

private fun RunManagerEx.getConfigurationItems() = allConfigurationsList
        .map { MFSelectorItem(it, isTemplate = false, isSelected = hasMainframerTask(it)) }

private fun RunManagerEx.getTemplateConfigurationItems() = getTemplateConfigurations()
        .map { MFSelectorItem(it, isTemplate = true, isSelected = hasMainframerTask(it)) }

private fun RunManagerEx.hasMainframerTask(configuration: RunConfiguration) =
        getBeforeRunTasks(configuration).any { it is MFBeforeRunTask }<commit_msg>[Refactoring] [89] Shorten control flow<commit_after>package com.elpassion.intelijidea.action.configure.selector

import com.elpassion.intelijidea.getTemplateConfigurations
import com.elpassion.intelijidea.task.MFBeforeRunTask
import com.intellij.execution.RunManagerEx
import com.intellij.execution.configurations.RunConfiguration
import com.intellij.openapi.project.Project
import io.reactivex.Maybe

typealias MFUiSelector = (List<MFSelectorItem>) -> Maybe<MFSelectorResult>

fun mfSelector(project: Project, uiSelector: MFUiSelector): Maybe<MFSelectorResult> =
        with(RunManagerEx.getInstanceEx(project)) {
            uiSelector(getConfigurationItems() + getTemplateConfigurationItems())
        }

fun getSelectorResult(uiIn: List<MFSelectorItem>, uiOut: List<MFSelectorItem>): MFSelectorResult {
    return if (uiOut != uiIn) {
        val toInject = (uiOut.filter { it.isSelected } - uiIn.filter { it.isSelected }).map { it.configuration }
        val toRestore = (uiOut.filterNot { it.isSelected } - uiIn.filterNot { it.isSelected }).map { it.configuration }
        MFSelectorResult(toInject, toRestore)
    } else {
        MFSelectorResult(emptyList(), emptyList())
    }
}

private fun RunManagerEx.getConfigurationItems() = allConfigurationsList
        .map { MFSelectorItem(it, isTemplate = false, isSelected = hasMainframerTask(it)) }

private fun RunManagerEx.getTemplateConfigurationItems() = getTemplateConfigurations()
        .map { MFSelectorItem(it, isTemplate = true, isSelected = hasMainframerTask(it)) }

private fun RunManagerEx.hasMainframerTask(configuration: RunConfiguration) =
        getBeforeRunTasks(configuration).any { it is MFBeforeRunTask }
{'fraction_non_alphanumeric': 0.09803346052245378, 'fraction_numerical': 0.000587026709715292, 'mean_word_length': 4.855670103092783, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1698112', 'n_tokens_mistral': 980, 'n_tokens_neox': 961, 'n_words': 175}