devxoul
5/28/2017 - 8:04 PM

RxImmutableMappable.swift

extension ObservableType where E: Any {
  func map<T: ImmutableMappable>(_ mappableType: T.Type) -> Observable<T> {
    return self
      .map { try Mapper<T>().map(JSONObject: $0) }
      .do(onError: { error in
        if error is MapError {
          log.error(error)
        }
      })
  }

  func map<T: ImmutableMappable>(_ mappableType: [T].Type) -> Observable<[T]> {
    return self
      .map { try Mapper<T>().mapArray(JSONObject: $0) }
      .do(onError: { error in
        if error is MapError {
          log.error(error)
        }
      })
  }
}