<commit_before>// MARK: Monadic Operators for the Decoded type

/**
  flatMap a function over a `Decoded` value (right associative)

  - If the value is a failing case (`.TypeMismatch`, `.MissingKey`), the function will not be evaluated and this will return the value
  - If the value is `.Success`, the function will be applied to the unwrapped value

  - parameter a: A value of type `Decoded<A>`
  - parameter f: A transformation function from type `A` to type `Decoded<B>`

  - returns: A value of type `Decoded<B>`
*/
public func >>- <A, B>(a: Decoded<A>, f: A -> Decoded<B>) -> Decoded<B> {
  return a.flatMap(f)
}

/**
  map a function over a `Decoded` value

  - If the value is is a failing case (`.TypeMismatch`, `.MissingKey`), the function will not be evaluated and this will return the value
  - If the value is `.Success`, the function will be applied to the unwrapped value

  - parameter f: A transformation function from type `A` to type `B`
  - parameter a: A value of type `Decoded<A>`

  - returns: A value of type `Decoded<B>`
*/
public func <^> <A, B>(f: A -> B, a: Decoded<A>) -> Decoded<B> {
  return a.map(f)
}

/**
  apply a `Decoded` function to a `Decoded` value

  - If the function is a failing case (`.TypeMismatch`, `.MissingKey`), this will return the function's value
  - If the function is a `.Success` case and the value is a failure case, this will return the value
  - If both self and the function are `.Success`, the function will be applied to the unwrapped value

  - parameter f: A `Decoded` transformation function from type `A` to type `B`
  - parameter a: A value of type `Decoded<A>`

  - returns: A value of type `Decoded<B>`
*/
public func <*> <A, B>(f: Decoded<A -> B>, a: Decoded<A>) -> Decoded<B> {
  return a.apply(f)
}

// MARK: Alternative operator

/**
  return the left `Decoded` value if it is `.Success`, otherwise return the right side

  - If the left hand side is successful, this will return the left hand side
  - If the left hand side is unsuccesful, this will return the right hand side

  - parameter lhs: A value of type `Decoded<A>`
  - parameter rhs: A value of type `Decoded<A>`

  - returns: A value of type `Decoded<A>`
*/

infix operator <|> { associativity left precedence 140 }

public func <|><A>(lhs: Decoded<A>, rhs: Decoded<A>) -> Decoded<A> {
  if case .Success = lhs {
    return lhs
  }
  return rhs
}

// MARK: Failure coalescing operator

/**
  return the unwrapped value of the `Decoded` value on the left if it is `.Success`, otherwise return the default on the right

  - If the left hand side is successful, this will return the unwrapped value from the left hand side argument
  - If the left hand side is unsuccesful, this will return the default value on the right hand side

  - parameter lhs: A value of type `Decoded<A>`
  - parameter rhs: A value of type `A`<commit_msg>Update documentation for the ?? autoclosure<commit_after>// MARK: Monadic Operators for the Decoded type

/**
  flatMap a function over a `Decoded` value (right associative)

  - If the value is a failing case (`.TypeMismatch`, `.MissingKey`), the function will not be evaluated and this will return the value
  - If the value is `.Success`, the function will be applied to the unwrapped value

  - parameter a: A value of type `Decoded<A>`
  - parameter f: A transformation function from type `A` to type `Decoded<B>`

  - returns: A value of type `Decoded<B>`
*/
public func >>- <A, B>(a: Decoded<A>, f: A -> Decoded<B>) -> Decoded<B> {
  return a.flatMap(f)
}

/**
  map a function over a `Decoded` value

  - If the value is is a failing case (`.TypeMismatch`, `.MissingKey`), the function will not be evaluated and this will return the value
  - If the value is `.Success`, the function will be applied to the unwrapped value

  - parameter f: A transformation function from type `A` to type `B`
  - parameter a: A value of type `Decoded<A>`

  - returns: A value of type `Decoded<B>`
*/
public func <^> <A, B>(f: A -> B, a: Decoded<A>) -> Decoded<B> {
  return a.map(f)
}

/**
  apply a `Decoded` function to a `Decoded` value

  - If the function is a failing case (`.TypeMismatch`, `.MissingKey`), this will return the function's value
  - If the function is a `.Success` case and the value is a failure case, this will return the value
  - If both self and the function are `.Success`, the function will be applied to the unwrapped value

  - parameter f: A `Decoded` transformation function from type `A` to type `B`
  - parameter a: A value of type `Decoded<A>`

  - returns: A value of type `Decoded<B>`
*/
public func <*> <A, B>(f: Decoded<A -> B>, a: Decoded<A>) -> Decoded<B> {
  return a.apply(f)
}

// MARK: Alternative operator

/**
  return the left `Decoded` value if it is `.Success`, otherwise return the right side

  - If the left hand side is successful, this will return the left hand side
  - If the left hand side is unsuccesful, this will return the right hand side

  - parameter lhs: A value of type `Decoded<A>`
  - parameter rhs: A value of type `Decoded<A>`

  - returns: A value of type `Decoded<A>`
*/

infix operator <|> { associativity left precedence 140 }

public func <|><A>(lhs: Decoded<A>, rhs: Decoded<A>) -> Decoded<A> {
  if case .Success = lhs {
    return lhs
  }
  return rhs
}

// MARK: Failure coalescing operator

/**
  return the unwrapped value of the `Decoded` value on the left if it is `.Success`, otherwise return the default on the right

  - If the left hand side is successful, this will return the unwrapped value from the left hand side argument
  - If the left hand side is unsuccesful, this will return the default value on the right hand side

  - parameter lhs: A value of type `Decoded<A>`
  - parameter rhs: An autoclosure returning a value of type `A`
{'fraction_non_alphanumeric': 0.10748228788664248, 'fraction_numerical': 0.0010368066355624676, 'mean_word_length': 3.455735180908391, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 81, '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': '7133555', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1758, 'n_words': 852}