Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Created June 15, 2018 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielgomezrico/36cddb327c380e94cc8cd52c14de9576 to your computer and use it in GitHub Desktop.
Save danielgomezrico/36cddb327c380e94cc8cd52c14de9576 to your computer and use it in GitHub Desktop.
ios - how to add an extension to Observable and generics
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