<commit_before>//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// A sequence of pairs built out of two underlying sequences, where
/// the elements of the `i`th pair are the `i`th elements of each
/// underlying sequence.
public func zip<Sequence1 : SequenceType, Sequence2 : SequenceType>(
  sequence1: Sequence1, _ sequence2: Sequence2
) -> Zip2Sequence<Sequence1, Sequence2> {
  return Zip2Sequence(sequence1, sequence2)
}

/// A generator for `Zip2Sequence`.
public struct Zip2Generator<
  Generator1 : GeneratorType, Generator2 : GeneratorType
> : GeneratorType {
  /// The type of element returned by `next()`.
  public typealias Element = (Generator1.Element, Generator2.Element)

  /// Construct around a pair of underlying generators.
  public init(_ generator1: Generator1, _ generator2: Generator2) {
    _baseStreams = (generator1, generator2)
  }

  /// Advance to the next element and return it, or `nil` if no next
  /// element exists.
  ///
  /// - Requires: `next()` has not been applied to a copy of `self`
  ///   since the copy was made, and no preceding call to `self.next()`
  ///   has returned `nil`.
  public mutating func next() -> Element? {
    // The next() function needs to track if it has reached the end.  If we
    // didn't, and the first sequence is shorter than the second, then, when we
    // have already exhausted the second sequence, on every subsequent call to
    // next() we would consume and discard one additional element from the
    // first sequence, even though next() return nil.

    if _reachedEnd {
      return nil
    }

    guard let e0 = _baseStreams.0.next(), e1 = _baseStreams.1.next() else {
      _reachedEnd = true
      return nil
    }

    return .Some((e0, e1))
  }

  internal var _baseStreams: (Generator1, Generator2)
  internal var _reachedEnd: Bool = false
}

/// A sequence of pairs built out of two underlying sequences, where
/// the elements of the `i`th pair are the `i`th elements of each
/// underlying sequence.
public struct Zip2Sequence<Sequence1 : SequenceType, Sequence2 : SequenceType>
  : SequenceType {

  public typealias Stream1 = Sequence1.Generator
  public typealias Stream2 = Sequence2.Generator

  /// A type whose instances can produce the elements of this
  /// sequence, in order.
  public typealias Generator = Zip2Generator<Stream1, Stream2>
<commit_msg>[stdlib] Unabbreviate local variable names<commit_after>//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// A sequence of pairs built out of two underlying sequences, where
/// the elements of the `i`th pair are the `i`th elements of each
/// underlying sequence.
public func zip<Sequence1 : SequenceType, Sequence2 : SequenceType>(
  sequence1: Sequence1, _ sequence2: Sequence2
) -> Zip2Sequence<Sequence1, Sequence2> {
  return Zip2Sequence(sequence1, sequence2)
}

/// A generator for `Zip2Sequence`.
public struct Zip2Generator<
  Generator1 : GeneratorType, Generator2 : GeneratorType
> : GeneratorType {
  /// The type of element returned by `next()`.
  public typealias Element = (Generator1.Element, Generator2.Element)

  /// Construct around a pair of underlying generators.
  public init(_ generator1: Generator1, _ generator2: Generator2) {
    _baseStreams = (generator1, generator2)
  }

  /// Advance to the next element and return it, or `nil` if no next
  /// element exists.
  ///
  /// - Requires: `next()` has not been applied to a copy of `self`
  ///   since the copy was made, and no preceding call to `self.next()`
  ///   has returned `nil`.
  public mutating func next() -> Element? {
    // The next() function needs to track if it has reached the end.  If we
    // didn't, and the first sequence is shorter than the second, then, when we
    // have already exhausted the second sequence, on every subsequent call to
    // next() we would consume and discard one additional element from the
    // first sequence, even though next() return nil.

    if _reachedEnd {
      return nil
    }

    guard let element0 = _baseStreams.0.next(), element1 = _baseStreams.1.next() else {
      _reachedEnd = true
      return nil
    }

    return .Some((element0, element1))
  }

  internal var _baseStreams: (Generator1, Generator2)
  internal var _reachedEnd: Bool = false
}

/// A sequence of pairs built out of two underlying sequences, where
/// the elements of the `i`th pair are the `i`th elements of each
/// underlying sequence.
public struct Zip2Sequence<Sequence1 : SequenceType, Sequence2 : SequenceType>
  : SequenceType {

  public typealias Stream1 = Sequence1.Generator
  public typealias Stream2 = Sequence2.Generator

  /// A type whose instances can produce the elements of this
  /// sequence, in order.
  public typealias Generator = Zip2Generator<Stream1, Stream2>

{'fraction_non_alphanumeric': 0.14508498335377606, 'fraction_numerical': 0.018223234624145785, 'mean_word_length': 2.6802063185041907, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '5297641', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1486, 'n_words': 630}