<commit_before>//
//  cascade.swift
//  RxSwiftExtDemo
//
//  Created by <NAME> on 17/04/16.
//  Copyright © 2016 RxSwift Community. All rights reserved.
//

import Foundation
import RxSwift

extension Observable where Element : ObservableType {
	
	typealias T = Element.E
	
	/**
	Cascade through a sequence of observables: every observable that sends a `next` value becomes the "current"
	observable (like in `switchLatest`), and the subscription to all previous observables in the sequence is disposed.
	
	This allows subscribing to multiple observable sequences while irrevocably switching to the next when it starts emitting. If any of the
	currently subscribed-to sequences errors, the error is propagated to the observer and the sequence terminates.
	
	- parameter observables: a sequence of observables which will all be immediately subscribed to
	- returns: An observable sequence that contains elements from the latest observable sequence that emitted elements
	*/
	
	
	public static func cascade<S : Sequence>(_ observables : S) -> Observable<T> where S.Iterator.Element == Element, S.Iterator.Element.E == T {
		let flow = Array(observables)
		if flow.isEmpty {
			return Observable<T>.empty()
		}
		
		return Observable<T>.create { observer in
			var current = 0, initialized = false
			var subscriptions: [SerialDisposable?] = flow.map { _ in SerialDisposable() }

			let lock = NSRecursiveLock()
			lock.lock()<commit_msg>Fix Xcode 8.3 warnings<commit_after>//
//  cascade.swift
//  RxSwiftExtDemo
//
//  Created by <NAME> on 17/04/16.
//  Copyright © 2016 RxSwift Community. All rights reserved.
//

import Foundation
import RxSwift

extension Observable where Element : ObservableType {
	
	public typealias T = Element.E
	
	/**
	Cascade through a sequence of observables: every observable that sends a `next` value becomes the "current"
	observable (like in `switchLatest`), and the subscription to all previous observables in the sequence is disposed.
	
	This allows subscribing to multiple observable sequences while irrevocably switching to the next when it starts emitting. If any of the
	currently subscribed-to sequences errors, the error is propagated to the observer and the sequence terminates.
	
	- parameter observables: a sequence of observables which will all be immediately subscribed to
	- returns: An observable sequence that contains elements from the latest observable sequence that emitted elements
	*/
	
	
	public static func cascade<S : Sequence>(_ observables : S) -> Observable<T> where S.Iterator.Element == Element, S.Iterator.Element.E == T {
		let flow = Array(observables)
		if flow.isEmpty {
			return Observable<T>.empty()
		}
		
		return Observable<T>.create { observer in
			var current = 0, initialized = false
			var subscriptions: [SerialDisposable?] = flow.map { _ in SerialDisposable() }

			let lock = NSRecursiveLock()
			lock.lock()
{'fraction_non_alphanumeric': 0.07583102493074792, 'fraction_numerical': 0.008310249307479225, 'mean_word_length': 3.981034482758621, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '4502377', 'n_tokens_mistral': 861, 'n_tokens_neox': 725, 'n_words': 329}