You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. //
  2. // mapTo.swift
  3. // RxSwiftExt
  4. //
  5. // Created by Marin Todorov on 4/12/16.
  6. // Copyright © 2016 RxSwift Community. All rights reserved.
  7. //
  8. import Foundation
  9. import RxSwift
  10. extension ObservableType {
  11. /**
  12. Returns an observable sequence containing as many elements as its input but all of them are the constant provided as a parameter
  13. - parameter value: A constant that each element of the input sequence is being replaced with
  14. - returns: An observable sequence containing the values `value` provided as a parameter
  15. */
  16. public func mapTo<Result>(_ value: Result) -> Observable<Result> {
  17. return map { _ in value }
  18. }
  19. }
  20. extension PrimitiveSequence where Trait == SingleTrait {
  21. /**
  22. Returns a Single which success event is mapped to constant provided as a parameter
  23. - parameter value: A constant that element of the input sequence is being replaced with
  24. - returns: A Single containing the value `value` provided as a parameter in case of success
  25. */
  26. public func mapTo<Result>(_ value: Result) -> Single<Result> {
  27. return map { _ in value }
  28. }
  29. }
  30. extension PrimitiveSequence where Trait == MaybeTrait {
  31. /**
  32. Returns a Maybe which success event is mapped to constant provided as a parameter
  33. - parameter value: A constant that element of the input sequence is being replaced with
  34. - returns: A Maybe containing the value `value` provided as a parameter in case of success
  35. */
  36. public func mapTo<Result>(_ value: Result) -> Maybe<Result> {
  37. return map { _ in value }
  38. }
  39. }