<commit_before>import UIKit
import RxSwift

public final class TargetActionObservable<Element>: NSObject, ObservableType {
    public typealias E = Element
    public let actionSelector: Selector = "action"
    
	private let _unsubscribe: (NSObjectProtocol, Selector) -> ()
    private let subject = PublishSubject<Element>()
    private let valueGenerator: () throws -> Element
    private let complete: Observable<Void>
	
    public init(valueGenerator generator: () throws -> Element, subscribe subscribeAction: (NSObjectProtocol, Selector) -> (), unsubscribe: (NSObjectProtocol, Selector) -> (), complete completeEvents: Observable<Void>) {
		valueGenerator = generator
		_unsubscribe = unsubscribe
        complete = completeEvents
		super.init()
		subscribeAction(self, actionSelector)
	}
	
	public convenience init (control: UIControl, forEvents controlEvents: UIControlEvents, valueGenerator generator: () throws -> Element) {
		self.init(
			valueGenerator: generator,
			subscribe: { (target, action) in
				control.addTarget(target, action: action, forControlEvents: controlEvents)
			},
			unsubscribe: { (target, action) in
				control.removeTarget(target, action: action, forControlEvents: controlEvents)
			},
            complete: control.rxs.onDeinit
		)
	}
	
    public convenience init<ObservedType: RXSObject>(notificationName: String, onObject: ObservedType, valueGenerator: (ObservedType) throws -> Element) {
		self.init(
            valueGenerator: { [unowned onObject] in try valueGenerator(onObject) },
			subscribe: { (target, action) in
				NSNotificationCenter.defaultCenter().addObserver(target, selector: action, name: notificationName, object: onObject)
			},
			unsubscribe: { (target, _) in
				NSNotificationCenter.defaultCenter().removeObserver(target, name: notificationName, object: onObject)
            },
            complete: onObject.rxs.onDeinit
		)
	}
    
    public func subscribe<O: ObserverType where O.E == Element>(observer: O) -> Disposable {
        let subjectDisposable = subject.takeUntil(complete).subscribe(observer)
        let triggerDisposable = AnonymousDisposable { _ = self }
        return CompositeDisposable() ++ subjectDisposable ++ triggerDisposable
    }
	
    func action() {
        guard let value = try? valueGenerator() else { subject.onError(RxsError()); return }
		subject.onNext(value)
	}
	
	deinit {
		subject.onCompleted()
		_unsubscribe(self, actionSelector)
	}
}<commit_msg>Use new #selector syntax for generics<commit_after>import UIKit
import RxSwift

public final class TargetActionObservable<Element>: NSObject, ObservableType {
    public typealias E = Element
    public let actionSelector = #selector(TargetActionObservable<Element>.action)
    
	private let _unsubscribe: (NSObjectProtocol, Selector) -> ()
    private let subject = PublishSubject<Element>()
    private let valueGenerator: () throws -> Element
    private let complete: Observable<Void>
	
    public init(valueGenerator generator: () throws -> Element, subscribe subscribeAction: (NSObjectProtocol, Selector) -> (), unsubscribe: (NSObjectProtocol, Selector) -> (), complete completeEvents: Observable<Void>) {
		valueGenerator = generator
		_unsubscribe = unsubscribe
        complete = completeEvents
		super.init()
		subscribeAction(self, actionSelector)
	}
	
	public convenience init (control: UIControl, forEvents controlEvents: UIControlEvents, valueGenerator generator: () throws -> Element) {
		self.init(
			valueGenerator: generator,
			subscribe: { (target, action) in
				control.addTarget(target, action: action, forControlEvents: controlEvents)
			},
			unsubscribe: { (target, action) in
				control.removeTarget(target, action: action, forControlEvents: controlEvents)
			},
            complete: control.rxs.onDeinit
		)
	}
	
    public convenience init<ObservedType: RXSObject>(notificationName: String, onObject: ObservedType, valueGenerator: (ObservedType) throws -> Element) {
		self.init(
            valueGenerator: { [unowned onObject] in try valueGenerator(onObject) },
			subscribe: { (target, action) in
				NSNotificationCenter.defaultCenter().addObserver(target, selector: action, name: notificationName, object: onObject)
			},
			unsubscribe: { (target, _) in
				NSNotificationCenter.defaultCenter().removeObserver(target, name: notificationName, object: onObject)
            },
            complete: onObject.rxs.onDeinit
		)
	}
    
    public func subscribe<O: ObserverType where O.E == Element>(observer: O) -> Disposable {
        let subjectDisposable = subject.takeUntil(complete).subscribe(observer)
        let triggerDisposable = AnonymousDisposable { _ = self }
        return CompositeDisposable() ++ subjectDisposable ++ triggerDisposable
    }
	
    func action() {
        guard let value = try? valueGenerator() else { subject.onError(RxsError()); return }
		subject.onNext(value)
	}
	
	deinit {
		subject.onCompleted()
		_unsubscribe(self, actionSelector)
	}
}
{'fraction_non_alphanumeric': 0.10026172740084559, 'fraction_numerical': 0.0, 'mean_word_length': 4.2075471698113205, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 32, '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': '1991891', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1302, 'n_words': 344}