I'm trying to use concatMap on BehaviorRelay but I'm getting this error:

Instance method 'concatMap' requires that '[Int]' conform to 'ObservableConvertibleType'

This is my implementation:

class MyClass{

    var disposeBag = DisposeBag()
    var subject: BehaviorRelay<[Int]> = BehaviorRelay(value: [1,2,3,4,5])


    func doSomething() {
        subject.asObservable().concatMap { $0 }
            .subscribe { print($0) }
            .disposed(by: disposeBag)

    }
}

I'm getting the error on this line:

subject.asObservable().concatMap { $0 }

Any of you knows why I'm getting this error or how can fix this error on my implementation ?

I'll really appreciate your help.

1

There are 1 best solutions below

0
On

The problem here is conceptual. It doesn't make any sense to use concatMap on an array of Ints. The error is basically telling you that an array of Ints is not an Observable. There aren't any Observables to concat here.

You need to go back and think about what you are trying to accomplish and find the right operator for the job.