Skip to content
Permalink
Browse files

Omit return for single-expression methods

  • Loading branch information
freak4pc authored and kzaher committed Sep 26, 2019
1 parent 439ed62 commit bd04ea59744c0887e7e6e7eace6bd13a070d0f09
@@ -56,16 +56,16 @@ func load(_ this: AtomicInt) -> Int32 {
@discardableResult
@inline(__always)
func increment(_ this: AtomicInt) -> Int32 {
return add(this, 1)
add(this, 1)
}

@discardableResult
@inline(__always)
func decrement(_ this: AtomicInt) -> Int32 {
return sub(this, 1)
sub(this, 1)
}

@inline(__always)
func isFlagSet(_ this: AtomicInt, _ mask: Int32) -> Bool {
return (load(this) & mask) != 0
(load(this) & mask) != 0
}
@@ -135,7 +135,7 @@ struct Bag<T> : CustomDebugStringConvertible {
extension Bag {
/// A textual representation of `self`, suitable for debugging.
var debugDescription : String {
return "\(self.count) elements in Bag"
"\(self.count) elements in Bag"
}
}

@@ -64,7 +64,7 @@ extension BlockingObservable {
///
/// - returns: Returns the only element of an sequence, and reports an error if there is not exactly one element in the observable sequence.
public func single() throws -> Element {
return try self.single { _ in true }
try self.single { _ in true }
}

/// Blocks current thread until sequence terminates.
@@ -131,19 +131,19 @@ extension DelegateProxyType {
// workaround of Delegate: class
extension DelegateProxyType {
static func _currentDelegate(for object: ParentObject) -> AnyObject? {
return currentDelegate(for: object).map { $0 as AnyObject }
currentDelegate(for: object).map { $0 as AnyObject }
}

static func _setCurrentDelegate(_ delegate: AnyObject?, to object: ParentObject) {
return setCurrentDelegate(castOptionalOrFatalError(delegate), to: object)
setCurrentDelegate(castOptionalOrFatalError(delegate), to: object)
}

func _forwardToDelegate() -> AnyObject? {
return self.forwardToDelegate().map { $0 as AnyObject }
self.forwardToDelegate().map { $0 as AnyObject }
}

func _setForwardToDelegate(_ forwardToDelegate: AnyObject?, retainDelegate: Bool) {
return self.setForwardToDelegate(castOptionalOrFatalError(forwardToDelegate), retainDelegate: retainDelegate)
self.setForwardToDelegate(castOptionalOrFatalError(forwardToDelegate), retainDelegate: retainDelegate)
}
}

@@ -160,7 +160,7 @@ extension DelegateProxyType {
/// Creates new proxy for target object.
/// Should not call this function directory, use 'DelegateProxy.proxy(for:)'
public static func createProxy(for object: AnyObject) -> Self {
return castOrFatalError(factory.createProxy(for: object))
castOrFatalError(factory.createProxy(for: object))
}

/// Returns existing proxy for object or installs new instance of delegate proxy.
@@ -243,7 +243,7 @@ extension DelegateProxyType {
// private extensions
extension DelegateProxyType {
private static var factory: DelegateProxyFactory {
return DelegateProxyFactory.sharedFactory(for: self)
DelegateProxyFactory.sharedFactory(for: self)
}

private static func assignedProxy(for object: ParentObject) -> AnyObject? {
@@ -267,7 +267,7 @@ public protocol HasDelegate: AnyObject {

extension DelegateProxyType where ParentObject: HasDelegate, Self.Delegate == ParentObject.Delegate {
public static func currentDelegate(for object: ParentObject) -> Delegate? {
return object.delegate
object.delegate
}

public static func setCurrentDelegate(_ delegate: Delegate?, to object: ParentObject) {
@@ -28,7 +28,7 @@ extension ObservableType {
- returns: Disposable object that can be used to unsubscribe the observers.
*/
public func bind<Observer: ObserverType>(to observers: Observer...) -> Disposable where Observer.Element == Element? {
return self.map { $0 as Element? }.bind(to: observers)
self.map { $0 as Element? }.bind(to: observers)
}

/**
@@ -39,7 +39,7 @@ extension ObservableType {
- returns: Disposable object that can be used to unsubscribe the observers.
*/
private func bind<Observer: ObserverType>(to observers: [Observer]) -> Disposable where Observer.Element == Element {
return self.subscribe { event in
self.subscribe { event in
observers.forEach { $0.on(event) }
}
}
@@ -38,7 +38,7 @@ import RxSwift
public typealias Driver<Element> = SharedSequence<DriverSharingStrategy, Element>

public struct DriverSharingStrategy: SharingStrategyProtocol {
public static var scheduler: SchedulerType { return SharingScheduler.make() }
public static var scheduler: SchedulerType { SharingScheduler.make() }
public static func share<Element>(_ source: Observable<Element>) -> Observable<Element> {
return source.share(replay: 1, scope: .whileConnected)
}
@@ -19,7 +19,7 @@ public enum SharingScheduler {
**This shouldn't be used in normal release builds.**
*/
static public func mock(scheduler: SchedulerType, action: () -> Void) {
return mock(makeScheduler: { scheduler }, action: action)
mock(makeScheduler: { scheduler }, action: action)
}

/**
@@ -31,12 +31,6 @@ extension SharedSequenceConvertibleType {
/**
Projects each element of an observable sequence into an optional form and filters all optional results.
Equivalent to:
func compactMap<Result>(_ transform: @escaping (Self.E) -> Result?) -> SharedSequence<SharingStrategy, Result> {
return self.map(transform).filter { $0 != nil }.map { $0! }
}
- parameter transform: A transform function to apply to each source element and which returns an element or nil.
- returns: An observable sequence whose elements are the result of filtering the transform function for each element of the source.
@@ -133,7 +133,7 @@ extension SharedSequence {
*/
public static func deferred(_ observableFactory: @escaping () -> SharedSequence<SharingStrategy, Element>)
-> SharedSequence<SharingStrategy, Element> {
return SharedSequence(Observable.deferred { observableFactory().asObservable() })
SharedSequence(Observable.deferred { observableFactory().asObservable() })
}

/**
@@ -31,7 +31,7 @@ extension SharedSequenceConvertibleType where SharingStrategy == SignalSharingSt
- returns: Disposable object that can be used to unsubscribe the observer from the subject.
*/
public func emit<Observer: ObserverType>(to observer: Observer) -> Disposable where Observer.Element == Element? {
return self.asSharedSequence().asObservable().map { $0 as Element? }.subscribe(observer)
self.asSharedSequence().asObservable().map { $0 as Element? }.subscribe(observer)
}

/**
@@ -40,7 +40,7 @@ extension SharedSequenceConvertibleType where SharingStrategy == SignalSharingSt
- returns: Disposable object that can be used to unsubscribe the observer from the relay.
*/
public func emit(to relay: BehaviorRelay<Element>) -> Disposable {
return self.emit(onNext: { e in
self.emit(onNext: { e in
relay.accept(e)
})
}
@@ -51,7 +51,7 @@ extension SharedSequenceConvertibleType where SharingStrategy == SignalSharingSt
- returns: Disposable object that can be used to unsubscribe the observer from the relay.
*/
public func emit(to relay: BehaviorRelay<Element?>) -> Disposable {
return self.emit(onNext: { e in
self.emit(onNext: { e in
relay.accept(e)
})
}
@@ -63,7 +63,7 @@ extension SharedSequenceConvertibleType where SharingStrategy == SignalSharingSt
- returns: Disposable object that can be used to unsubscribe the observer from the relay.
*/
public func emit(to relay: PublishRelay<Element>) -> Disposable {
return self.emit(onNext: { e in
self.emit(onNext: { e in
relay.accept(e)
})
}
@@ -75,7 +75,7 @@ extension SharedSequenceConvertibleType where SharingStrategy == SignalSharingSt
- returns: Disposable object that can be used to unsubscribe the observer from the relay.
*/
public func emit(to relay: PublishRelay<Element?>) -> Disposable {
return self.emit(onNext: { e in
self.emit(onNext: { e in
relay.accept(e)
})
}
@@ -93,7 +93,7 @@ extension SharedSequenceConvertibleType where SharingStrategy == SignalSharingSt
- returns: Subscription object used to unsubscribe from the observable sequence.
*/
public func emit(onNext: ((Element) -> Void)? = nil, onCompleted: (() -> Void)? = nil, onDisposed: (() -> Void)? = nil) -> Disposable {
return self.asObservable().subscribe(onNext: onNext, onCompleted: onCompleted, onDisposed: onDisposed)
self.asObservable().subscribe(onNext: onNext, onCompleted: onCompleted, onDisposed: onDisposed)
}
}

@@ -30,7 +30,7 @@ import RxSwift
public typealias Signal<Element> = SharedSequence<SignalSharingStrategy, Element>

public struct SignalSharingStrategy: SharingStrategyProtocol {
public static var scheduler: SchedulerType { return SharingScheduler.make() }
public static var scheduler: SchedulerType { SharingScheduler.make() }

public static func share<Element>(_ source: Observable<Element>) -> Observable<Element> {
return source.share(scope: .whileConnected)
@@ -1653,7 +1653,6 @@
PRODUCT_NAME = "RxExample-iOS";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
@@ -1672,7 +1671,6 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
name = Release;
};
@@ -1887,7 +1885,6 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
name = "Release-Tests";
};
@@ -17,7 +17,7 @@ extension ObservableType {
- returns: Disposable object that can be used to unsubscribe the observer.
*/
public func bind(to relays: PublishRelay<Element>...) -> Disposable {
return bind(to: relays)
bind(to: relays)
}

/**
@@ -30,7 +30,7 @@ extension ObservableType {
- returns: Disposable object that can be used to unsubscribe the observer.
*/
public func bind(to relays: PublishRelay<Element?>...) -> Disposable {
return self.map { $0 as Element? }.bind(to: relays)
self.map { $0 as Element? }.bind(to: relays)
}

/**
@@ -41,7 +41,7 @@ extension ObservableType {
- returns: Disposable object that can be used to unsubscribe the observer.
*/
private func bind(to relays: [PublishRelay<Element>]) -> Disposable {
return subscribe { e in
subscribe { e in
switch e {
case let .next(element):
relays.forEach {
@@ -63,7 +63,7 @@ extension ObservableType {
- returns: Disposable object that can be used to unsubscribe the observer.
*/
public func bind(to relays: BehaviorRelay<Element>...) -> Disposable {
return self.bind(to: relays)
self.bind(to: relays)
}

/**
@@ -76,7 +76,7 @@ extension ObservableType {
- returns: Disposable object that can be used to unsubscribe the observer.
*/
public func bind(to relays: BehaviorRelay<Element?>...) -> Disposable {
return self.map { $0 as Element? }.bind(to: relays)
self.map { $0 as Element? }.bind(to: relays)
}

/**
@@ -87,7 +87,7 @@ extension ObservableType {
- returns: Disposable object that can be used to unsubscribe the observer.
*/
private func bind(to relays: [BehaviorRelay<Element>]) -> Disposable {
return subscribe { e in
subscribe { e in
switch e {
case let .next(element):
relays.forEach {
@@ -31,7 +31,7 @@ extension ObservableType {
*/
public func catchErrorJustReturn(_ element: Element)
-> Observable<Element> {
return Catch(source: self.asObservable(), handler: { _ in Observable.just(element) })
Catch(source: self.asObservable(), handler: { _ in Observable.just(element) })
}

}
@@ -29,7 +29,7 @@ extension ObservableType {
*/
public static func combineLatest<Collection: Swift.Collection>(_ collection: Collection) -> Observable<[Element]>
where Collection.Element: ObservableType, Collection.Element.Element == Element {
return CombineLatestCollectionType(sources: collection, resultSelector: { $0 })
CombineLatestCollectionType(sources: collection, resultSelector: { $0 })
}
}

@@ -81,7 +81,7 @@ final class CombineLatestSink<%= i %>_<<%= (Array(1...i).map { "E\($0)" }).joine
}

override func getResult() throws -> Result {
return try self._parent._resultSelector(<%= (Array(1...i).map { "self._latestElement\($0)" }).joined(separator: ", ") %>)
try self._parent._resultSelector(<%= (Array(1...i).map { "self._latestElement\($0)" }).joined(separator: ", ") %>)
}
}

@@ -11,19 +11,13 @@ extension ObservableType {
/**
Projects each element of an observable sequence into an optional form and filters all optional results.
Equivalent to:
func compactMap<Result>(_ transform: @escaping (Self.E) throws -> Result?) -> RxSwift.Observable<Result> {
return self.map { try? transform($0) }.filter { $0 != nil }.map { $0! }
}
- parameter transform: A transform function to apply to each source element and which returns an element or nil.
- returns: An observable sequence whose elements are the result of filtering the transform function for each element of the source.
*/
public func compactMap<Result>(_ transform: @escaping (Element) throws -> Result?)
-> Observable<Result> {
return CompactMap(source: self.asObservable(), transform: transform)
CompactMap(source: self.asObservable(), transform: transform)
}
}

@@ -17,7 +17,7 @@ extension ObservableType where Element: Equatable {
*/
public func distinctUntilChanged()
-> Observable<Element> {
return self.distinctUntilChanged({ $0 }, comparer: { ($0 == $1) })
self.distinctUntilChanged({ $0 }, comparer: { ($0 == $1) })
}
}

@@ -32,7 +32,7 @@ extension ObservableType {
*/
public func distinctUntilChanged<Key: Equatable>(_ keySelector: @escaping (Element) throws -> Key)
-> Observable<Element> {
return self.distinctUntilChanged(keySelector, comparer: { $0 == $1 })
self.distinctUntilChanged(keySelector, comparer: { $0 == $1 })
}

/**
@@ -45,7 +45,7 @@ extension ObservableType {
*/
public func distinctUntilChanged(_ comparer: @escaping (Element, Element) throws -> Bool)
-> Observable<Element> {
return self.distinctUntilChanged({ $0 }, comparer: comparer)
self.distinctUntilChanged({ $0 }, comparer: comparer)
}

/**
@@ -20,7 +20,7 @@ extension ObservableType {
- returns: The generated sequence.
*/
public static func generate(initialState: Element, condition: @escaping (Element) throws -> Bool, scheduler: ImmediateSchedulerType = CurrentThreadScheduler.instance, iterate: @escaping (Element) throws -> Element) -> Observable<Element> {
return Generate(initialState: initialState, condition: condition, iterate: iterate, resultSelector: { $0 }, scheduler: scheduler)
Generate(initialState: initialState, condition: condition, iterate: iterate, resultSelector: { $0 }, scheduler: scheduler)
}
}

0 comments on commit bd04ea5

Please sign in to comment.
You can’t perform that action at this time.