<commit_before>extension Array {
    var second: Element? {
        guard count > 1 else { return nil }
        return self[1]
    }
}

let count = CommandLine.arguments.second.flatMap { Int($0) } ?? 1

if count < 1 {
    fatalError("Count should be 1 or more!")
}

func character(from number: Int) -> Character {
    assert(number >= 0)
    assert(number < 26)
    let start = 97
    return Character(UnicodeScalar(number + start)!)
}

func characters(count: Int) -> String {
    let chars = (0..<count).map(character(from:))
                           .map { String($0).uppercased() }
    return chars.joined(separator: ", ")
}

var string = """
// This file is generated via scripts/SequentialOperators.swift. Do not modify manually!

public func >~<Token, A, B>(lhs: Parser<Token, A>, rhs: Parser<Token, B>) -> Parser<Token, B> {
    return Parser { tokens in
        return lhs.parse(tokens).flatMap(f: { _, rest in
            return rhs.parse(rest)
        })
    }
}

public func <~<Token, A, B>(lhs: Parser<Token, B>, rhs: Parser<Token, A>) -> Parser<Token, B> {
    return Parser { tokens in
        return lhs.parse(tokens).flatMap(f: { result, rest in
            return rhs.parse(rest).map(f: { _, _ in
                return result
            })
        })
    }
}
"""

for i in (1...count) {
    
    let chars = characters(count: i)
    let next = String(character(from: i)).uppercased()
    let resultsArray = (0..<i).map({ "result.\($0)" })
    let results = resultsArray.count > 1 ? resultsArray.joined(separator: ", ") : "result"
    
    string += """


public func ~<Token, \(chars), \(next)>(lhs: Parser<Token, (\(chars))>, rhs: Parser<Token, \(next)>) -> Parser<Token, (\(chars), \(next))> {
    return Parser { tokens in
        return lhs.parse(tokens).flatMap(f: { (result, rest) in
            return rhs.parse(rest).map(f: { r, t in (\(results), r) })
        })
    }
}
"""
    
}
<commit_msg>Added ~ for tuples in other direction<commit_after>extension Array {
    var second: Element? {
        guard count > 1 else { return nil }
        return self[1]
    }
}

let count = CommandLine.arguments.second.flatMap { Int($0) } ?? 1

if count < 1 {
    fatalError("Count should be 1 or more!")
}

func character(from number: Int) -> Character {
    assert(number >= 0)
    assert(number < 26)
    let start = 97
    return Character(UnicodeScalar(number + start)!)
}

func characters(count: Int) -> String {
    let chars = (0..<count).map(character(from:))
                           .map { String($0).uppercased() }
    return chars.joined(separator: ", ")
}

var string = """
// This file is generated via scripts/SequentialOperators.swift. Do not modify manually!

public func >~<Token, A, B>(lhs: Parser<Token, A>, rhs: Parser<Token, B>) -> Parser<Token, B> {
    return Parser { tokens in
        return lhs.parse(tokens).flatMap(f: { _, rest in
            return rhs.parse(rest)
        })
    }
}

public func <~<Token, A, B>(lhs: Parser<Token, B>, rhs: Parser<Token, A>) -> Parser<Token, B> {
    return Parser { tokens in
        return lhs.parse(tokens).flatMap(f: { result, rest in
            return rhs.parse(rest).map(f: { _, _ in
                return result
            })
        })
    }
}
"""

for i in (1...count) {
    
    let chars = characters(count: i)
    let next = String(character(from: i)).uppercased()
    let resultsArray = (0..<i).map({ "result.\($0)" })
    let results = resultsArray.count > 1 ? resultsArray.joined(separator: ", ") : "result"
    
    string += """


public func ~<Token, \(chars), \(next)>(lhs: Parser<Token, (\(chars))>, rhs: Parser<Token, \(next)>) -> Parser<Token, (\(chars), \(next))> {
    return Parser { tokens in
        return lhs.parse(tokens).flatMap(f: { (result, rest) in
            return rhs.parse(rest).map(f: { r, t in (\(results), r) })
        })
    }
}
    
"""
    
    if i > 1 {
        string += """
        public func ~<Token, \(chars), \(next)>(lhs: Parser<Token, \(next)>, rhs: Parser<Token, (\(chars))>) -> Parser<Token, (\(next), \(chars))> {
            return Parser { tokens in
                return lhs.parse(tokens).flatMap(f: { (r, rest) in
                    return rhs.parse(rest).map(f: { result, t in (r, \(results)) })
                })
            }
        }
"""
    }
}



{'fraction_non_alphanumeric': 0.1704202461109821, 'fraction_numerical': 0.00812630601346645, 'mean_word_length': 2.365625, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 51, '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': '6323448', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1404, 'n_words': 368}