<commit_before>import Argo
import Curry

public struct Reward {
  public let backersCount: Int?
  public let description: String
  public let estimatedDeliveryOn: NSTimeInterval?
  public let id: Int
  public let limit: Int?
  public let minimum: Int
  public let remaining: Int?
  public let shipping: Shipping
  public let title: String?

  /// Returns `true` is this is the "fake" "No reward" reward.
  public var isNoReward: Bool {
    return id == 0
  }

  public struct Shipping {
    public let enabled: Bool
    public let preference: Preference?
    public let summary: String?

    public enum Preference: String {
      case none
      case restricted
      case unrestricted
    }
  }
}

extension Reward: Equatable {}
public func == (lhs: Reward, rhs: Reward) -> Bool {
  return lhs.id == rhs.id
}

extension Reward: Comparable {}
public func < (lhs: Reward, rhs: Reward) -> Bool {
  if lhs.minimum < rhs.minimum {
    return true
  }
  if lhs.minimum == rhs.minimum && lhs.id < rhs.id {
    return true
  }
  return false
}

extension Reward: Decodable {
  public static func decode(json: JSON) -> Decoded<Reward> {
    let create = curry(Reward.init)
    let tmp = create
      <^> json <|? "backers_count"
      <*> (json <| "description" <|> json <| "reward")
      <*> json <|? "estimated_delivery_on"
      <*> json <| "id"
    return tmp
      <*> json <|? "limit"
      <*> json <| "minimum"
      <*> json <|? "remaining"
      <*> Reward.Shipping.decode(json)
      <*> json <|? "title"
  }
}

extension Reward.Shipping: Decodable {
  public static func decode(json: JSON) -> Decoded<Reward.Shipping> {
    return curry(Reward.Shipping.init)
      <^> json <| "shipping_enabled" <|> .Success(false)
      <*> json <|? "shipping_preference"
      <*> json <|? "shipping_summary"
  }
}
<commit_msg>Use the fancy comparator stuff... (#89)<commit_after>import Argo
import Curry
import Prelude

public struct Reward {
  public let backersCount: Int?
  public let description: String
  public let estimatedDeliveryOn: NSTimeInterval?
  public let id: Int
  public let limit: Int?
  public let minimum: Int
  public let remaining: Int?
  public let shipping: Shipping
  public let title: String?

  /// Returns `true` is this is the "fake" "No reward" reward.
  public var isNoReward: Bool {
    return id == 0
  }

  public struct Shipping {
    public let enabled: Bool
    public let preference: Preference?
    public let summary: String?

    public enum Preference: String {
      case none
      case restricted
      case unrestricted
    }
  }
}

extension Reward: Equatable {}
public func == (lhs: Reward, rhs: Reward) -> Bool {
  return lhs.id == rhs.id
}

private let minimumAndIdComparator = Reward.lens.minimum.comparator <> Reward.lens.id.comparator

extension Reward: Comparable {}
public func < (lhs: Reward, rhs: Reward) -> Bool {
  return minimumAndIdComparator.isOrdered(lhs, rhs)
}

extension Reward: Decodable {
  public static func decode(json: JSON) -> Decoded<Reward> {
    let create = curry(Reward.init)
    let tmp = create
      <^> json <|? "backers_count"
      <*> (json <| "description" <|> json <| "reward")
      <*> json <|? "estimated_delivery_on"
      <*> json <| "id"
    return tmp
      <*> json <|? "limit"
      <*> json <| "minimum"
      <*> json <|? "remaining"
      <*> Reward.Shipping.decode(json)
      <*> json <|? "title"
  }
}

extension Reward.Shipping: Decodable {
  public static func decode(json: JSON) -> Decoded<Reward.Shipping> {
    return curry(Reward.Shipping.init)
      <^> json <| "shipping_enabled" <|> .Success(false)
      <*> json <|? "shipping_preference"
      <*> json <|? "shipping_summary"
  }
}

{'fraction_non_alphanumeric': 0.12662689804772234, 'fraction_numerical': 0.0010845986984815619, 'mean_word_length': 3.0672546857772875, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 44, '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': '1275595', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1206, 'n_words': 353}