<commit_before>//
//  Bounded.swift
//  Allsorts
//
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

public protocol BoundedType {
    class var min: Self { get }
    class var max: Self { get }
}

public enum Bounded<T : Orderable> : Comparable, Orderable, BoundedType {
    case Min
    case Med(T)
    case Max
    
    public init(_ value: T) { self = .Med(value) }
    
    public static var min: Bounded { return .Min }
    public static var max: Bounded { return .Max }
}

extension Bounded : Printable {
    public var description: String {
        switch self {
        case     .Min:    return "Min"
        case let .Med(x): return "Med(\(x))"
        case     .Max:    return "Max"
        }
    }
}

public func <=> <T>(a: Bounded<T>, b: Bounded<T>) -> Ordering {
    switch a {
    case .Min: switch b { case .Min: return .EQ; default: return .LT }
    case .Max: switch b { case .Max: return .EQ; default: return .GT }
    case let .Med(a):
        switch b {
        case     .Max:    return .LT
        case let .Med(b): return a <=> b
        case     .Min:    return .GT
        }
    }
}<commit_msg>Add case analysis ("switch") to `Bounded<T>`<commit_after>//
//  Bounded.swift
//  Allsorts
//
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

public protocol BoundedType {
    class var min: Self { get }
    class var max: Self { get }
}

public enum Bounded<T : Orderable> : Comparable, Orderable, BoundedType {
    case Min
    case Med(T)
    case Max
    
    public init(_ value: T) { self = .Med(value) }
    
    public static func pure(value: T) -> Bounded {
        return .Med(value)
    }
    
    public static var min: Bounded { return .Min }
    public static var max: Bounded { return .Max }
    
    public func analysis<R>(#ifMin: () -> R,
                             ifMed: T -> R,
                             ifMax: () -> R) -> R
    {
        switch self {
        case     .Min:    return ifMin()
        case let .Med(x): return ifMed(x)
        case     .Max:    return ifMax()
        }
    }
}

extension Bounded : Printable {
    public var description: String {
        switch self {
        case     .Min:    return "Min"
        case let .Med(x): return "Med(\(x))"
        case     .Max:    return "Max"
        }
    }
}

public func <=> <T>(a: Bounded<T>, b: Bounded<T>) -> Ordering {
    switch (a, b) {
    case     (.Min,    .Min   ): return .EQ
    case     (.Min,    _      ): return .LT
    
    case     (.Med,    .Max   ): return .LT
    case let (.Med(a), .Med(b)): return a <=> b
    case     (.Med,    .Min   ): return .GT
    
    case     (.Max,    .Max   ): return .EQ
    case     (.Max,    _      ): return .GT
    }
}
{'fraction_non_alphanumeric': 0.13355530891601924, 'fraction_numerical': 0.0029596744358120607, 'mean_word_length': 1.635477582846004, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 26, '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': '6574436', 'n_tokens_mistral': 923, 'n_tokens_neox': 884, 'n_words': 289}