<commit_before>//
//  OneOrMore.swift
//  SwiftyEcharts
//
//  Created by <NAME> on 19/02/2017.
//  Copyright © 2017 com.pluto-y. All rights reserved.
//

public struct OneOrMore<T>: ArrayLiteralConvertible {
    private var one: T? = nil
    private var more: [T]? = nil
    public init(one: T) {
        self.one = one
    }
    
    public init(more: [T]) {
        self.more = more
    }
    
    public init(arrayLiteral elements: T...) {
        if elements.count == 1 {
            self.one = elements[0]
        } else {
            self.more = elements
        }
    }
}

extension OneOrMore: Jsonable {
    public var jsonString: String {
        if let datas = self.more {
            return datas.jsonString
        } else if let data = self.one {
            return obtainJsonString(from: data)
        }
        return "\"null\""
    }
}

extension OneOrMore {
    public subscript(index: Int) -> T? {
        if one != nil {
            return index == 0 ? one : nil
        }
        return more![index]
    }
}<commit_msg>docs(codes):Add comments for `OneOrMore`<commit_after>//
//  OneOrMore.swift
//  SwiftyEcharts
//
//  Created by <NAME> on 19/02/2017.
//  Copyright © 2017 com.pluto-y. All rights reserved.
//

/// 针对那些可以是一个组件也可以是多个组件组成的属性的抽象
///
/// 例如在 Option 中存在许多即可以传递一个也可以传递多个的组件
///
/// 并且保证其可以通过数组常量来进行创建
public struct OneOrMore<T>: ArrayLiteralConvertible {
    private var one: T? = nil
    private var more: [T]? = nil
    public init(one: T) {
        self.one = one
    }
    
    public init(more: [T]) {
        self.more = more
    }
    
    public init(arrayLiteral elements: T...) {
        if elements.count == 1 {
            self.one = elements[0]
        } else {
            self.more = elements
        }
    }
}

extension OneOrMore: Jsonable {
    public var jsonString: String {
        if let datas = self.more {
            return datas.jsonString
        } else if let data = self.one {
            return obtainJsonString(from: data)
        }
        return "\"null\""
    }
}

// MARK: - 实现下标的拓展
extension OneOrMore {
    public subscript(index: Int) -> T? {
        if one != nil {
            return index == 0 ? one : nil
        }
        return more![index]
    }
}
{'fraction_non_alphanumeric': 0.12134831460674157, 'fraction_numerical': 0.01348314606741573, 'mean_word_length': 1.7146341463414634, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6946749', 'n_tokens_mistral': 787, 'n_tokens_neox': 760, 'n_words': 190}