Created
June 15, 2018 12:24
-
-
Save danielgomezrico/36cddb327c380e94cc8cd52c14de9576 to your computer and use it in GitHub Desktop.
ios - how to add an extension to Observable and generics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import RxSwift | |
import RxCocoa | |
extension ObservableType where E == String { | |
/// Limit the max size of the string that's been emitted | |
func limit(maxStringSize: Int) -> RxSwift.Observable<String> { | |
return scan("") { (previous, new) -> String in | |
return new.count <= maxStringSize ? new : previous | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment