<commit_before>import Foundation

public typealias ChoreResult = (result: Int32, stdout: String, stderr: String)

private func string_trim(string: NSString!) -> String {
    return string.stringByTrimmingCharactersInSet(.whitespaceAndNewlineCharacterSet()) ?? ""
}

private func chore_task(command: String, arguments: [String]) -> ChoreResult {
    let task = NSTask()

    task.launchPath = command
    task.arguments = arguments

    if !(task.launchPath as NSString).absolutePath {
        task.launchPath = (chore_task("/usr/bin/which", [task.launchPath])).stdout
    }

    if !NSFileManager.defaultManager().fileExistsAtPath(task.launchPath) {
        return (255, "", String(format: "%@: launch path not accessible", task.launchPath))
    }

    let stderrPipe = NSPipe()
    task.standardError = stderrPipe
    let stderrHandle = stderrPipe.fileHandleForReading

    let stdoutPipe = NSPipe()
    task.standardOutput = stdoutPipe
    let stdoutHandle = stdoutPipe.fileHandleForReading

    task.launch()
    task.waitUntilExit()

    let stderr = string_trim(NSString(data: stderrHandle.readDataToEndOfFile(), encoding: NSUTF8StringEncoding)) ?? ""
    let stdout = string_trim(NSString(data: stdoutHandle.readDataToEndOfFile(), encoding: NSUTF8StringEncoding)) ?? ""

    return (task.terminationStatus, stdout, stderr)
}

prefix operator > {}

public prefix func > (command: String) -> ChoreResult {
    return chore_task(command, [String]())
}

public prefix func > (command: [String]) -> ChoreResult {
    switch command.count {
        case 0:
            return (0, "", "")
        case 1:
            return chore_task(command[0], [String]())
        default:
            break
    }

    return chore_task(command[0], Array(command[1..<command.count]))
}<commit_msg>Simplify by giving `arguments` a default value.<commit_after>import Foundation

public typealias ChoreResult = (result: Int32, stdout: String, stderr: String)

private func string_trim(string: NSString!) -> String {
    return string.stringByTrimmingCharactersInSet(.whitespaceAndNewlineCharacterSet()) ?? ""
}

private func chore_task(command: String, _ arguments: [String] = [String]()) -> ChoreResult {
    let task = NSTask()

    task.launchPath = command
    task.arguments = arguments

    if !(task.launchPath as NSString).absolutePath {
        task.launchPath = (chore_task("/usr/bin/which", [task.launchPath])).stdout
    }

    if !NSFileManager.defaultManager().fileExistsAtPath(task.launchPath) {
        return (255, "", String(format: "%@: launch path not accessible", task.launchPath))
    }

    let stderrPipe = NSPipe()
    task.standardError = stderrPipe
    let stderrHandle = stderrPipe.fileHandleForReading

    let stdoutPipe = NSPipe()
    task.standardOutput = stdoutPipe
    let stdoutHandle = stdoutPipe.fileHandleForReading

    task.launch()
    task.waitUntilExit()

    let stderr = string_trim(NSString(data: stderrHandle.readDataToEndOfFile(), encoding: NSUTF8StringEncoding)) ?? ""
    let stdout = string_trim(NSString(data: stdoutHandle.readDataToEndOfFile(), encoding: NSUTF8StringEncoding)) ?? ""

    return (task.terminationStatus, stdout, stderr)
}

prefix operator > {}

public prefix func > (command: String) -> ChoreResult {
    return chore_task(command)
}

public prefix func > (command: [String]) -> ChoreResult {
    switch command.count {
        case 0:
            return (0, "", "")
        case 1:
            return chore_task(command[0])
        default:
            break
    }

    return chore_task(command[0], Array(command[1..<command.count]))
}
{'fraction_non_alphanumeric': 0.11925327389244915, 'fraction_numerical': 0.007244357759821678, 'mean_word_length': 3.7174770039421814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '6918064', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1053, 'n_words': 237}