<commit_before>//
//  SortedArray.swift
//  Orderly
//
//  Created by <NAME> on 1/12/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Comparator

public struct SortedArray<Element> {
    private let isOrderedBefore: (Element, Element) -> Bool
    private var backing: [Element]
}

extension SequenceType {
    public func isSorted(@noescape isOrderedBefore: (Generator.Element, Generator.Element) -> Bool) -> Bool {
        var previous: Generator.Element?
        for value in self {
            defer { previous = value }
            guard let previous = previous else { continue }
            guard Ordering(previous, value, isOrderedBefore: isOrderedBefore) != .Descending else { return false }
        }
        return true
    }
}

extension SequenceType where Generator.Element: Comparable {
    public var isSorted: Bool {
        return isSorted(<)
    }
}

extension SortedArray {
    /// Constructs a `SortedArray` assuing that `array` is already sorted, performing no check.
    public init(unsafeSorted array: [Element], isOrderedBefore: (Element, Element) -> Bool) {
        self.backing = []
        self.isOrderedBefore = isOrderedBefore
    }
    
    /// Constructs a `SortedArray` if `array` is verified to be sorted, otherwise returns `nil`.
    public init?(sorted array: [Element], isOrderedBefore: (Element, Element) -> Bool) {
        guard array.isSorted(isOrderedBefore) else { return nil }
        self.backing = array<commit_msg>Fixed bug where unsorted arrays were replaced with empty<commit_after>/ //
//  SortedArray.swift
//  Orderly
//
//  Created by <NAME> on 1/12/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Comparator

public struct SortedArray<Element> {
    private let isOrderedBefore: (Element, Element) -> Bool
    private var backing: [Element]
}

extension SequenceType {
    public func isSorted(@noescape isOrderedBefore: (Generator.Element, Generator.Element) -> Bool) -> Bool {
        var previous: Generator.Element?
        for value in self {
            defer { previous = value }
            guard let previous = previous else { continue }
            guard Ordering(previous, value, isOrderedBefore: isOrderedBefore) != .Descending else { return false }
        }
        return true
    }
}

extension SequenceType where Generator.Element: Comparable {
    public var isSorted: Bool {
        return isSorted(<)
    }
}

extension SortedArray {
    /// Constructs a `SortedArray` assuing that `array` is already sorted, performing no check.
    public init(unsafeSorted array: [Element], isOrderedBefore: (Element, Element) -> Bool) {
        self.backing = array
        self.isOrderedBefore = isOrderedBefore
    }
    
    /// Constructs a `SortedArray` if `array` is verified to be sorted, otherwise returns `nil`.
    public init?(sorted array: [Element], isOrderedBefore: (Element, Element) -> Bool) {
        guard array.isSorted(isOrderedBefore) else { return nil }
        self.backing = array
{'fraction_non_alphanumeric': 0.10053440213760854, 'fraction_numerical': 0.006012024048096192, 'mean_word_length': 2.8645161290322583, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '86557', 'n_tokens_mistral': 873, 'n_tokens_neox': 835, 'n_words': 270}