<commit_before>import UIKit
import Cartography

protocol PagingContentViewControllerDelegate: class {
  func pagingContentViewController(pagingContentViewController: PagingContentViewController, didChangeOffset: CGFloat, towardsIndex: Int)
  func pagingContentViewController(pagingContentViewController: PagingContentViewController, didMoveToIndex: Int)
}

class PagingContentViewController: UIViewController {
  
  var pagingState: PagingState
  weak var delegate: PagingContentViewControllerDelegate?
  private let dataSource: PagingDataSource
  private let pageViewController: UIPageViewController
  
  private var pendingViewController: UIViewController?
  private var upcomingViewController: UIViewController?
  
  init(dataSource: PagingDataSource, pagingState: PagingState) {
    
    self.pagingState = pagingState
    self.dataSource = dataSource
    self.pageViewController = UIPageViewController(
      transitionStyle: .Scroll,
      navigationOrientation: .Horizontal,
      options: nil)
    
    super.init(nibName: nil, bundle: nil)
    
    pageViewController.dataSource = dataSource
    pageViewController.delegate = self
    pageViewController.view.subviews.forEach {
      if let scrollView = $0 as? UIScrollView {
        scrollView.delegate = self
      }
    }
  }

  required init?(coder: NSCoder) {
    fatalError(Error.InitCoder.rawValue)
  }
  
  override func viewDidLoad() {
    super.viewDidLoad()
    addViewController(pageViewController)
    constrain(pageViewController.view, view) { pageView, view in
      pageView.edges == view.edges
    }
  }
  
  func setViewControllerForIndex(index: Int, direction: PagingDirection, animated: Bool) {
    let viewController = dataSource.viewControllers[index]
    upcomingViewController = viewController
    pageViewController.setViewControllers([viewController],
      direction: direction.pageViewControllerNavigationDirection,
      animated: animated,
      completion: { completed in
        if completed {
          self.delegate?.pagingContentViewController(self, didMoveToIndex: index)
          self.upcomingViewController = nil
        }
    })
  }
  
}

extension PagingContentViewController: UIScrollViewDelegate {
  
  func scrollViewDidScroll(scrollView: UIScrollView) {
    let offset = CGFloat(scrollView.contentOffset.x / scrollView.bounds.width) - 1
    
    if let upcomingViewController = self.upcomingViewController {
      if let upcomingIndex = dataSource.viewControllers.indexOf(upcomingViewController) {
        delegate?.pagingContentViewController(self, didChangeOffset: offset, towardsIndex: upcomingIndex)
      }
    } else if offset < 0 {
      delegate?.pagingContentViewController(self, didChangeOffset: offset, towardsIndex: pagingState.currentIndex - 1)
    } else if offset > 0 {
      delegate?.pagingContentViewController(self, didChangeOffset: offset, towardsIndex: pagingState.currentIndex + 1)
    }
  }
  
}

extension PagingContentViewController: UIPageViewControllerDelegate {
 
  func pageViewController(pageViewController: UIPageViewController, willTransitionToViewControllers pendingViewControllers: [UIViewController]) {
    if let viewController = pendingViewControllers.first {
      pendingViewController = viewController
    }
  }
  
  func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
    guard
      let viewController = self.pendingViewController,
      let index = dataSource.viewControllers.indexOf(viewController) else { return }
    
    if completed {
      delegate?.pagingContentViewController(self, didMoveToIndex: index)
    }
    
    pendingViewController = nil
  }
  
}
<commit_msg>Clean up delegate method calls<commit_after>import UIKit
import Cartography

protocol PagingContentViewControllerDelegate: class {
  func pagingContentViewController(pagingContentViewController: PagingContentViewController, didChangeOffset: CGFloat, towardsIndex: Int)
  func pagingContentViewController(pagingContentViewController: PagingContentViewController, didMoveToIndex: Int)
}

class PagingContentViewController: UIViewController {
  
  var pagingState: PagingState
  weak var delegate: PagingContentViewControllerDelegate?
  private let dataSource: PagingDataSource
  private let pageViewController: UIPageViewController
  
  private var pendingViewController: UIViewController?
  private var upcomingViewController: UIViewController?
  
  init(dataSource: PagingDataSource, pagingState: PagingState) {
    
    self.pagingState = pagingState
    self.dataSource = dataSource
    self.pageViewController = UIPageViewController(
      transitionStyle: .Scroll,
      navigationOrientation: .Horizontal,
      options: nil)
    
    super.init(nibName: nil, bundle: nil)
    
    pageViewController.dataSource = dataSource
    pageViewController.delegate = self
    pageViewController.view.subviews.forEach {
      if let scrollView = $0 as? UIScrollView {
        scrollView.delegate = self
      }
    }
  }

  required init?(coder: NSCoder) {
    fatalError(Error.InitCoder.rawValue)
  }
  
  override func viewDidLoad() {
    super.viewDidLoad()
    addViewController(pageViewController)
    constrain(pageViewController.view, view) { pageView, view in
      pageView.edges == view.edges
    }
  }
  
  func setViewControllerForIndex(index: Int, direction: PagingDirection, animated: Bool) {
    let viewController = dataSource.viewControllers[index]
    upcomingViewController = viewController
    pageViewController.setViewControllers([viewController],
      direction: direction.pageViewControllerNavigationDirection,
      animated: animated,
      completion: { completed in
        if completed {
          self.delegate?.pagingContentViewController(self, didMoveToIndex: index)
          self.upcomingViewController = nil
        }
    })
  }
  
}

extension PagingContentViewController: UIScrollViewDelegate {
  
  func scrollViewDidScroll(scrollView: UIScrollView) {
    let offset = CGFloat(scrollView.contentOffset.x / scrollView.bounds.width) - 1
    
    if let upcomingViewController = self.upcomingViewController {
      if let upcomingIndex = dataSource.viewControllers.indexOf(upcomingViewController) {
        delegate?.pagingContentViewController(self,
          didChangeOffset: offset,
          towardsIndex: upcomingIndex)
      }
    } else if offset < 0 {
      delegate?.pagingContentViewController(self,
        didChangeOffset: offset,
        towardsIndex: pagingState.currentIndex - 1)
    } else if offset > 0 {
      delegate?.pagingContentViewController(self,
        didChangeOffset: offset,
        towardsIndex: pagingState.currentIndex + 1)
    }
  }
  
}

extension PagingContentViewController: UIPageViewControllerDelegate {
 
  func pageViewController(pageViewController: UIPageViewController, willTransitionToViewControllers pendingViewControllers: [UIViewController]) {
    if let viewController = pendingViewControllers.first {
      pendingViewController = viewController
    }
  }
  
  func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
    guard
      let viewController = self.pendingViewController,
      let index = dataSource.viewControllers.indexOf(viewController) else { return }
    
    if completed {
      delegate?.pagingContentViewController(self, didMoveToIndex: index)
    }
    
    pendingViewController = nil
  }
  
}

{'fraction_non_alphanumeric': 0.06699195569036001, 'fraction_numerical': 0.0015824871422919688, 'mean_word_length': 4.212371134020619, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5552672', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1931, 'n_words': 418}