<commit_before>/**
Combines two compare functions into a new compare function, such that
the first function is used as the first-order comparison and the second
function as second-order comparison.

- parameter f: first-order compare function
- parameter g: second-order compare function

- returns: composed compare function
*/
public func combineCompareFunctions<T>(_ f: @escaping (T, T) -> Bool, _ g: @escaping (T, T) -> Bool) -> ((T, T) -> Bool) {
  return { (a, b) in
    let isLesser = f(a, b)
    if isLesser {
      return true
    }
    
    let isGreater = f(b, a)
    if isGreater {
      return false
    }
    
    return g(a, b)
  }
}

/**
*  Infix operator for combineCompareFunctions
*/
infix operator <|> { associativity left }
public func <|><T>(f: @escaping (T, T) -> Bool, g: @escaping (T, T) -> Bool) -> ((T, T) -> Bool) {
  return combineCompareFunctions(f, g)
}

/**
Generates a compare function (suitable for Swift Arrays' sort methods)
using the provided transformation function f.
Elements are sorted by the result of applying each element to f.
 <commit_msg>Use new operator precedence mechanism<commit_after>/**
Combines two compare functions into a new compare function, such that
the first function is used as the first-order comparison and the second
function as second-order comparison.

- parameter f: first-order compare function
- parameter g: second-order compare function

- returns: composed compare function
*/
public func combineCompareFunctions<T>(_ f: @escaping (T, T) -> Bool, _ g: @escaping (T, T) -> Bool) -> ((T, T) -> Bool) {
  return { (a, b) in
    let isLesser = f(a, b)
    if isLesser {
      return true
    }
    
    let isGreater = f(b, a)
    if isGreater {
      return false
    }
    
    return g(a, b)
  }
}

/**
*  Infix operator for combineCompareFunctions
*/
precedencegroup CompareFunctionCompositionPrecedence {
    lowerThan: AssignmentPrecedence
    associativity: left
}
infix operator <|>: CompareFunctionCompositionPrecedence
public func <|><T>(f: @escaping (T, T) -> Bool, g: @escaping (T, T) -> Bool) -> ((T, T) -> Bool) {
  return combineCompareFunctions(f, g)
}

/**
Generates a compare function (suitable for Swift Arrays' sort methods)
using the provided transformation function f.
Elements are sorted by the result of applying each element to f.
 
{'fraction_non_alphanumeric': 0.10877042132416165, 'fraction_numerical': 0.0, 'mean_word_length': 3.4578544061302683, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, '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': '4492741', 'n_tokens_mistral': 730, 'n_tokens_neox': 701, 'n_words': 279}