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

/// Orderable value `T` augmented with an upper bound `.End`.
public enum Ended<T : Orderable> : Orderable, Comparable {
    case Another(T)
    case End
    
    public init() {
        self = .End
    }
    
    public init(_ value: T?) {
        self = value.map {x in .Another(x)} ?? .End
    }
    
    public var another: T? {
        switch self {
        case let .Another(x): return .Some(x)
        case     .End:        return .None
        }
    }
    
    public var isEnd: Bool {
        switch self {
        case .Another: return false
        case .End:     return true
        }
    }
}

extension Ended : Printable {
    public var description: String {
        switch self {
        case let .Another(x): return "Another(\(x))"
        case     .End:        return "End"
        }
    }
}

/// Ordering based on `a <=> b == .Another(a) <=> .Another(b)` and
/// `.Another(_) < .End`.
public func <=> <T>(a: Ended<T>, b: Ended<T>) -> Ordering {
    switch (a, b) {
    case     (.Another,    .End       ): return .LT
    case     (.End,        .End       ): return .EQ
    case     (.End,        .Another   ): return .GT
    case let (.Another(a), .Another(b)): return a <=> b
    }
}<commit_msg>Rename `Ended<T>.Another` to `Ended<T>.Value`<commit_after>//
//  Ended.swift
//  Allsorts
//
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

/// Orderable value `T` augmented with an upper bound `.End`. An `Ended<T>` is
/// structurally equivalent to `Optional<T>` but flips the ordering of the
/// `Optional.Some(T)` (~ `Ended.Value(T)`) and the `Optional.None` (~
/// `Ended.End`) cases such that `.Value(x)` compares less than `.End`.
public enum Ended<T : Orderable> : Orderable, Comparable {
    case Value(T)
    case End
    
    public init() {
        self = .End
    }
    
    public init(_ value: T?) {
        self = value.map {x in .Value(x)} ?? .End
    }
    
    public static func pure(value: T) -> Ended {
        return .Value(value)
    }
    
    public var value: T? {
        switch self {
        case let .Value(x): return .Some(x)
        case     .End:      return .None
        }
    }
    
    public func map<U>(f: T -> U) -> Ended<U> {
        switch self {
        case let .Value(x): return .Value(f(x))
        case     .End:      return .End
        }
    }
    
    public func flatMap<U>(f: T -> Ended<U>) -> Ended<U> {
        switch self {
        case let .Value(x): return f(x)
        case     .End:      return .End
        }
    }
}

extension Ended : Printable {
    public var description: String {
        switch self {
        case let .Value(x): return "Value(\(x))"
        case     .End:      return "End"
        }
    }
}

/// Ordering based on `a <=> b == .Value(a) <=> .Value(b)` and
/// `.Value(_) < .End`.
public func <=> <T>(a: Ended<T>, b: Ended<T>) -> Ordering {
    switch (a, b) {
    case let (.Value(a), .Value(b)): return a <=> b
    case     (.Value,    .End     ): return .LT
    case     (.End,      .End     ): return .EQ
    case     (.End,      .Value   ): return .GT
    }
}
{'fraction_non_alphanumeric': 0.15931989924433249, 'fraction_numerical': 0.0025188916876574307, 'mean_word_length': 1.6475, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 37, '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': '3264423', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1067, 'n_words': 322}