<commit_before>//
//  Node.Sequence.swift
//  Yams
//
//  Created by <NAME> on 2/24/17.
//  Copyright (c) 2016 Yams. All rights reserved.
//

import Foundation

extension Node {
    public struct Sequence {
        private var nodes: [Node]
        public var tag: Tag
        public var style: Style
        public var mark: Mark?

        public enum Style: UInt32 {
            /// Let the emitter choose the style.
            case any
            /// The block sequence style.
            case block
            /// The flow sequence style.
            case flow
        }

        public init(_ nodes: [Node], _ tag: Tag = .implicit, _ style: Style = .any, _ mark: Mark? = nil) {
            self.nodes = nodes
            self.tag = tag
            self.style = style
            self.mark = mark
        }
    }

    public var sequence: Sequence? {
        get {
            if case let .sequence(sequence) = self {
                return sequence
            }
            return nil
        }
        set {
            if let newValue = newValue {
                self = .sequence(newValue)
            }
        }
    }
}

// MARK: - Node.Sequence

extension Node.Sequence: Comparable {
    public static func < (lhs: Node.Sequence, rhs: Node.Sequence) -> Bool {
        return lhs.nodes < rhs.nodes
    }
}

extension Node.Sequence: Equatable {
    public static func == (lhs: Node.Sequence, rhs: Node.Sequence) -> Bool {
        return lhs.nodes == rhs.nodes && lhs.resolvedTag == rhs.resolvedTag
    }
}

extension Node.Sequence: ExpressibleByArrayLiteral {
    public init(arrayLiteral elements: Node...) {
        self.init(elements)
    }
}

extension Node.Sequence: MutableCollection {
    // Sequence
    public func makeIterator() -> Array<Node>.Iterator {
        return nodes.makeIterator()
    }

    // Collection
    public typealias Index = Array<Node>.Index

    public var startIndex: Index {
        return nodes.startIndex
    }

    public var endIndex: Index {
        return nodes.endIndex
    }

    public func index(after index: Index) -> Index {
        return nodes.index(after: index)
    }

    public subscript(index: Index) -> Node {
        get {
            return nodes[index]
        }
        // MutableCollection
        set {
            nodes[index] = newValue
        }
    }

    public subscript(bounds: Range<Index>) -> Array<Node>.SubSequence {
        get {
            return nodes[bounds]
        }
        // MutableCollection
        set {
            nodes[bounds] = newValue
        }
    }

    public var indices: Array<Node>.Indices {
        return nodes.indices
    }
}

extension Node.Sequence: RandomAccessCollection {
    // BidirectionalCollection
    public func index(before index: Index) -> Index {
        return nodes.index(before: index)
    }

    // RandomAccessCollection
    public func index(_ index: Index, offsetBy num: Int) -> Index {
        return nodes.index(index, offsetBy: num)
    }

    public func distance(from start: Index, to end: Int) -> Index {
        return nodes.distance(from: start, to: end)
    }
}

extension Node.Sequence: RangeReplaceableCollection {
    public init() {
        self.init([])
    }

    public mutating func replaceSubrange<C>(_ subrange: Range<Index>, with newElements: C)
        where C: Collection, C.Iterator.Element == Node {
            nodes.replaceSubrange(subrange, with: newElements)
    }
}

extension Node.Sequence: TagResolvable {
    static let defaultTagName = Tag.Name.seq
}<commit_msg>Add docstrings to Node.Sequence.swift<commit_after>//
//  Node.Sequence.swift
//  Yams
//
//  Created by <NAME> on 2/24/17.
//  Copyright (c) 2016 Yams. All rights reserved.
//

import Foundation

// MARK: Node+Sequence

extension Node {
    /// Sequence node.
    public struct Sequence {
        private var nodes: [Node]
        /// This node's tag (its type).
        public var tag: Tag
        /// The style to be used when emitting this node.
        public var style: Style
        /// The location for this node.
        public var mark: Mark?

        /// The style to use when emitting a `Sequence`.
        public enum Style: UInt32 {
            /// Let the emitter choose the style.
            case any
            /// The block sequence style.
            case block
            /// The flow sequence style.
            case flow
        }

        /// Create a `Node.Sequence` using the specified parameters.
        ///
        /// - parameter nodes: The array of nodes to generate this sequence.
        /// - parameter tag:   This sequence's `Tag`.
        /// - parameter style: The style to use when emitting this `Sequence`.
        /// - parameter mark:  This sequence's `Mark`.
        public init(_ nodes: [Node], _ tag: Tag = .implicit, _ style: Style = .any, _ mark: Mark? = nil) {
            self.nodes = nodes
            self.tag = tag
            self.style = style
            self.mark = mark
        }
    }

    /// Get or set the `Node.Sequence` value if this node is a `Node.sequence`.
    public var sequence: Sequence? {
        get {
            if case let .sequence(sequence) = self {
                return sequence
            }
            return nil
        }
        set {
            if let newValue = newValue {
                self = .sequence(newValue)
            }
        }
    }
}

// MARK: - Node.Sequence

extension Node.Sequence: Comparable {
    /// :nodoc:
    public static func < (lhs: Node.Sequence, rhs: Node.Sequence) -> Bool {
        return lhs.nodes < rhs.nodes
    }
}

extension Node.Sequence: Equatable {
    /// :nodoc:
    public static func == (lhs: Node.Sequence, rhs: Node.Sequence) -> Bool {
        return lhs.nodes == rhs.nodes && lhs.resolvedTag == rhs.resolvedTag
    }
}

extension Node.Sequence: ExpressibleByArrayLiteral {
    /// :nodoc:
    public init(arrayLiteral elements: Node...) {
        self.init(elements)
    }
}

extension Node.Sequence: MutableCollection {
    // Sequence
    /// :nodoc:
    public func makeIterator() -> Array<Node>.Iterator {
        return nodes.makeIterator()
    }

    // Collection
    /// :nodoc:
    public typealias Index = Array<Node>.Index

    /// :nodoc:
    public var startIndex: Index {
        return nodes.startIndex
    }

    /// :nodoc:
    public var endIndex: Index {
        return nodes.endIndex
    }

    /// :nodoc:
    public func index(after index: Index) -> Index {
        return nodes.index(after: index)
    }

    /// :nodoc:
    public subscript(index: Index) -> Node {
        get {
            return nodes[index]
        }
        // MutableCollection
        set {
            nodes[index] = newValue
        }
    }

    /// :nodoc:
    public subscript(bounds: Range<Index>) -> Array<Node>.SubSequence {
        get {
            return nodes[bounds]
        }
        // MutableCollection
        set {
            nodes[bounds] = newValue
        }
    }

    /// :nodoc:
    public var indices: Array<Node>.Indices {
        return nodes.indices
    }
}

extension Node.Sequence: RandomAccessCollection {
    // BidirectionalCollection
    /// :nodoc:
    public func index(before index: Index) -> Index {
        return nodes.index(before: index)
    }

    // RandomAccessCollection
    /// :nodoc:
    public func index(_ index: Index, offsetBy num: Int) -> Index {
        return nodes.index(index, offsetBy: num)
    }

    /// :nodoc:
    public func distance(from start: Index, to end: Int) -> Index {
        return nodes.distance(from: start, to: end)
    }
}

extension Node.Sequence: RangeReplaceableCollection {
    /// :nodoc:
    public init() {
        self.init([])
    }

    /// :nodoc:
    public mutating func replaceSubrange<C>(_ subrange: Range<Index>, with newElements: C)
        where C: Collection, C.Iterator.Element == Node {
            nodes.replaceSubrange(subrange, with: newElements)
    }
}

extension Node.Sequence: TagResolvable {
    static let defaultTagName = Tag.Name.seq
}
{'fraction_non_alphanumeric': 0.10754434174369223, 'fraction_numerical': 0.0027479390457157134, 'mean_word_length': 1.7811740187565126, 'pattern_counts': {'":': 0, '<': 23, '<?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': '6415961', 'n_tokens_mistral': 2264, 'n_tokens_neox': 2191, 'n_words': 657}