<commit_before>// Copyright 2016 The Shear Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

import Foundation

public enum ArrayIndex: NilLiteralConvertible, IntegerLiteralConvertible, ArrayLiteralConvertible {
    
    case All
    case SingleValue(Int)
    case Range(Int, Int)
    case List([Int])
    
    public init(nilLiteral: ()) {
        self = .All
    }
    
    public init(integerLiteral value: Int) {
        self = .SingleValue(value)
    }
    
    public init(arrayLiteral elements: Int...) {
        self = .List(elements)
    }
    
    func isInbounds(bound: Int) -> Bool {
        switch self {
        case .All:
            return true
        case .SingleValue(let index):
            return index < bound
        case .Range(let startIndex, let endIndex):
            return startIndex <= endIndex && endIndex < bound
        case .List(let indices):
            return indices.filter {$0 >= bound}.isEmpty
        }
    }
    
}

// "RangeLiteralConvertibles" of a sort.
public func ..<(start: Int, end: Int) -> ArrayIndex {
    precondition(start <= end, "ArrayIndex.Range: start must be less than or equal to end")
    return .Range(start, end)
}

public func ...(start: Int, end: Int) -> ArrayIndex {
    return start ..< end - 1
}

public let $ = ArrayIndex.All // TODO: decide if this or nil or some other symbol is best to express grabbing all of a dim<commit_msg>Fix: ArrayIndex's ...() definition and .Range bounds check.<commit_after>// Copyright 2016 The Shear Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

import Foundation

public enum ArrayIndex: NilLiteralConvertible, IntegerLiteralConvertible, ArrayLiteralConvertible {
    
    case All
    case SingleValue(Int)
    case Range(Int, Int)
    case List([Int])
    
    public init(nilLiteral: ()) {
        self = .All
    }
    
    public init(integerLiteral value: Int) {
        self = .SingleValue(value)
    }
    
    public init(arrayLiteral elements: Int...) {
        self = .List(elements)
    }
    
    func isInbounds(bound: Int) -> Bool {
        switch self {
        case .All:
            return true
        case .SingleValue(let index):
            return index < bound
        case .Range(let startIndex, let endIndex):
            return startIndex <= endIndex && endIndex <= bound
        case .List(let indices):
            return indices.filter {$0 >= bound}.isEmpty
        }
    }
    
}

// "RangeLiteralConvertibles" of a sort.
public func ..<(start: Int, end: Int) -> ArrayIndex {
    precondition(start <= end, "ArrayIndex.Range: start must be less than or equal to end")
    return .Range(start, end)
}

public func ...(start: Int, end: Int) -> ArrayIndex {
    return start ..< (end + 1)
}

public let $ = ArrayIndex.All // TODO: decide if this or nil or some other symbol is best to express grabbing all of a dim
{'fraction_non_alphanumeric': 0.10082918739635158, 'fraction_numerical': 0.003980099502487562, 'mean_word_length': 2.343680709534368, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '732213', 'n_tokens_mistral': 852, 'n_tokens_neox': 834, 'n_words': 311}