<commit_before>//
//  Observable+Multiple.swift
//  Rx
//
//  Created by <NAME> on 3/12/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

// switch

public func switchLatest<T>
    (sources: Observable<Observable<T>>)
    -> Observable<T> {
        
    // swift doesn't have co/contravariance
    return Switch(sources: sources)
}


// concat

public func concat<E>
    (sources: [Observable<E>])
    -> Observable<E> {
        return Concat(sources: sources)
}

// merge

public func merge<E>
    (sources: Observable<Observable<E>>)
    -> Observable<E> {
        return Merge(sources: sources, maxConcurrent: 0)
}

public func merge<E>
    (maxConcurrent: Int)
    -> (Observable<Observable<E>> -> Observable<E>) {
    return  { sources in
        return Merge(sources: sources, maxConcurrent: maxConcurrent)
    }
}

// catch

public func catchOrDie<E>
    (handler: (ErrorType) -> Result<Observable<E>>)
    -> (Observable<E> -> Observable<E>) {
    return { source in
        return Catch(source: source, handler: handler)
    }
}

public func catch<E>
    (handler: (ErrorType) -> Observable<E>)
    -> (Observable<E> -> Observable<E>) {
    return { source in
        return Catch(source: source, handler: { success(handler($0)) })
    }
}

// When error happens `error` will be forwarded as a next `Result<E>` value
// and sequence will be completed
public func catchToResult<E>
    (source: Observable<E>)
    -> Observable<Result<E>> {
    return CatchToResult(source: source)
}<commit_msg>Adds catch variant.<commit_after>//
//  Observable+Multiple.swift
//  Rx
//
//  Created by <NAME> on 3/12/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

// switch

public func switchLatest<T>
    (sources: Observable<Observable<T>>)
    -> Observable<T> {
        
    // swift doesn't have co/contravariance
    return Switch(sources: sources)
}


// concat

public func concat<E>
    (sources: [Observable<E>])
    -> Observable<E> {
        return Concat(sources: sources)
}

// merge

public func merge<E>
    (sources: Observable<Observable<E>>)
    -> Observable<E> {
        return Merge(sources: sources, maxConcurrent: 0)
}

public func merge<E>
    (maxConcurrent: Int)
    -> (Observable<Observable<E>> -> Observable<E>) {
    return  { sources in
        return Merge(sources: sources, maxConcurrent: maxConcurrent)
    }
}

// catch

public func catchOrDie<E>
    (handler: (ErrorType) -> Result<Observable<E>>)
    -> (Observable<E> -> Observable<E>) {
    return { source in
        return Catch(source: source, handler: handler)
    }
}

public func catch<E>
    (handler: (ErrorType) -> Observable<E>)
    -> (Observable<E> -> Observable<E>) {
    return { source in
        return Catch(source: source, handler: { success(handler($0)) })
    }
}

// In case of error, terminates sequence with `replaceErrorWith`.
public func catch<E>
    (replaceErrorWith: E)
    -> (Observable<E> -> Observable<E>) {
    return { source in
        return Catch(source: source, handler: { _ in success(returnElement(replaceErrorWith)) })
    }
}

// When error happens `error` will be forwarded as a next `Result<E>` value
// and sequence will be completed.
public func catchToResult<E>
    (source: Observable<E>)
    -> Observable<Result<E>> {
    return CatchToResult(source: source)
}
{'fraction_non_alphanumeric': 0.14315538323889054, 'fraction_numerical': 0.00656128839844915, 'mean_word_length': 3.0556227327690446, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 94, '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': '7315998', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1071, 'n_words': 280}