Closed Taehyeon-Kim closed 1 year ago
extension Sequence where Element: Hashable {
func uniqued() -> [Element] {
var set = Set<Element>()
return filter { set.insert($0).inserted }
}
}
나름대로 뷰 쪽에서 로직을 짜보려고 했던 부분
추천 키워드가 먼저 정렬되도록 해야 함
private func makeAroundedKeywords(with dto: SearchResponseDTO) -> [KeywordItemViewModel] {
let fromRecommend = dto.fromRecommend.map { KeywordItemViewModel(contents: $0, keywordType: .recommended) }
let fromQueueDB = dto.fromQueueDB.flatMap { $0.studylist.map { KeywordItemViewModel(contents: $0, keywordType: .arounded) } }
let fromQueueDBRequested = dto.fromQueueDBRequested.flatMap { $0.studylist.map { KeywordItemViewModel(contents: $0, keywordType: .arounded) } }
var results = fromRecommend + fromQueueDB + fromQueueDBRequested
results = removeDuplicatedKeywords(items: results)
self.items.accept([.arounded(results.map {.keyword($0)})])
return results
}
private func removeDuplicatedKeywords(items: [KeywordItemViewModel]) -> [KeywordItemViewModel] { var items = items items.removeAll { viewModel in viewModel.contents == "anything" || viewModel.contents.isEmpty }
let result = Array(Set(items))
return result.sorted { first, _ in
return first.keywordType == .recommended
}
}
todo
logic
design