Skip to content

Instantly share code, notes, and snippets.

@Jimmy-Prime
Created April 25, 2019 06:40
Show Gist options
  • Save Jimmy-Prime/31a5d1bee47b83156d4988b26e4cc9ab to your computer and use it in GitHub Desktop.
Save Jimmy-Prime/31a5d1bee47b83156d4988b26e4cc9ab to your computer and use it in GitHub Desktop.
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