<commit_before>//
//  SharedSequence.swift
//  RxCocoa
//
//  Created by <NAME> on 8/27/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import RxSwift

/**
    Trait that represents observable sequence that shares computation resources with following properties:

    - it never fails
    - it delivers events on `SharingStrategy.scheduler`
    - sharing strategy is customizable using `SharingStrategy.share` behavior

    `SharedSequence<Element>` can be considered a builder pattern for observable sequences that share computation resources.

    To find out more about units and how to use them, please visit `Documentation/Traits.md`.
*/
public struct SharedSequence<S: SharingStrategyProtocol, Element> : SharedSequenceConvertibleType {
    public typealias SharingStrategy = S

    let _source: Observable<Element>

    init(_ source: Observable<Element>) {
        self._source = S.share(source)
    }

    init(raw: Observable<Element>) {
        self._source = raw
    }

    #if EXPANDABLE_SHARED_SEQUENC
    /**
     This method is extension hook in case this unit needs to extended from outside the library.
     
     By defining `EXPANDABLE_SHARED_SEQUENCE` one agrees that it's up to him to ensure shared sequence
     properties are preserved after extension.
    */
    public static func createUnsafe<O: ObservableType>(source: O) -> SharedSequence<S, O.Element> {
        return SharedSequence<S, O.Element>(raw: source.asObservable())
    }
    #endif

    /**
    - returns: Built observable sequence.
    */
    public func asObservable() -> Observable<Element> {
        return self._source
    }

    /**
    - returns: `self`
    */<commit_msg>Update SharedSequence.swift<commit_after>//
//  SharedSequence.swift
//  RxCocoa
//
//  Created by <NAME> on 8/27/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import RxSwift

/**
    Trait that represents observable sequence that shares computation resources with following properties:

    - it never fails
    - it delivers events on `SharingStrategy.scheduler`
    - sharing strategy is customizable using `SharingStrategy.share` behavior

    `SharedSequence<Element>` can be considered a builder pattern for observable sequences that share computation resources.

    To find out more about units and how to use them, please visit `Documentation/Traits.md`.
*/
public struct SharedSequence<S: SharingStrategyProtocol, Element> : SharedSequenceConvertibleType {
    public typealias SharingStrategy = S

    let _source: Observable<Element>

    init(_ source: Observable<Element>) {
        self._source = S.share(source)
    }

    init(raw: Observable<Element>) {
        self._source = raw
    }

    #if EXPANDABLE_SHARED_SEQUENCE
    /**
     This method is extension hook in case this unit needs to extended from outside the library.
     
     By defining `EXPANDABLE_SHARED_SEQUENCE` one agrees that it's up to him to ensure shared sequence
     properties are preserved after extension.
    */
    public static func createUnsafe<O: ObservableType>(source: O) -> SharedSequence<S, O.Element> {
        return SharedSequence<S, O.Element>(raw: source.asObservable())
    }
    #endif

    /**
    - returns: Built observable sequence.
    */
    public func asObservable() -> Observable<Element> {
        return self._source
    }

    /**
    - returns: `self`
    */
{'fraction_non_alphanumeric': 0.0874074074074074, 'fraction_numerical': 0.005333333333333333, 'mean_word_length': 3.082224909310762, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, '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': '669782', 'n_tokens_mistral': 949, 'n_tokens_neox': 886, 'n_words': 313}