가까운 영화관 찾기
fetchNearCinemas 에 값이 들어오면 실행
withLatestFrom 은 첫번째 Observable 과 파라미터로 받은 Observable 을 묶어 아웃풋을 전달한다
- 대신 첫번째 Observable 이벤트가 일어나지 않으면 전달되지 않는다
- 지금 보면 처음부터
currentCoordinate 옵저버블로 값 넘겨줘도 될 듯
- 소팅해서 상위세개만 tempNearCinemas → nearCinemas
fetchNearCinemas = fetchingNearCinemas.asObserver()
fetchingNearCinemas
.withLatestFrom(self.currentCoordinate)
.subscribe(onNext: { currentCoordinate in
let sortedCinemaListByDistance = IndieCinema.list.sorted { cinema1, cinema2 in
let distance1 = currentCoordinate.distance(to: cinema1.location)
let distance2 = currentCoordinate.distance(to: cinema2.location)
return distance1 < distance2
}
tempNearCinemas.onNext(Array(sortedCinemaListByDistance.prefix(3)))
})
.disposed(by: disposeBag)
nearCinemas = tempNearCinemas