Group Group Group Group Group Group Group Group Group

Chapter 5 - Challenge - toArray creates Single<[Int]> that can't be subscribed to

Picking back up from an old post.

Not sure if this is going to be addressed in the book update this year, but the .toArray method creates a Single that can’t be observed.

func toArray() -> Single<[Int]>

Summary
Converts an Observable into a Single that emits the whole sequence as a single array and then terminates.

The only thing I could come up with was adding .asObservable after .toArray, and then calling subscribe(onNext:).

let input = PublishSubject<Int>()
        input.skipWhile { (number) -> Bool in
            number == 0
        }
        .filter({ (number) -> Bool in
            number < 10 //must be single digit (1-9)
        })
        .take(10)
        .toArray()
        .asObservable()
        .subscribe(onNext: { (element) in
                //code...
         }
        .disposed(by: disposeBag)

Hope that helps anybody who was stuck on this challenge.