Created
April 25, 2019 06:40
-
-
Save Jimmy-Prime/31a5d1bee47b83156d4988b26e4cc9ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import RxCocoa | |
import RxSwift | |
import SwiftSoup | |
struct Post { | |
let id: String | |
} | |
class Test { | |
func posts(in page: Single<Document>) -> Single<[Post]> { | |
let elementToPost: (Element) -> Post? = { element in | |
guard let id = try? element.attr("id") else { | |
return nil | |
} | |
return Post(id: id) | |
} | |
return page | |
.map { try $0.select("table#the_table div").array() } | |
.map { $0.compactMap(elementToPost) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment