Created
January 18, 2018 07:04
-
-
Save jaidetree/c5155e98ee42525c18e4d3c40751d88c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (ns async-reddit | |
| (:require [reddit :refer [get-reddit-posts]] | |
| [clojure.core.async :as async])) | |
| (defn get-post-link | |
| [post] | |
| (str "https://reddit.com" (:permalink post))) | |
| (defn get-post-footer | |
| [post] | |
| (str (:score post) " | " (:num_comments post) " comments")) | |
| (defn print-post | |
| [post] | |
| (doseq [display-fn [:title get-post-link get-post-footer]] | |
| (println (display-fn post))) | |
| (println "\n")) | |
| (defn -main | |
| [] | |
| (let [in-chan (async/chan)] | |
| (-> in-chan | |
| (async/pipe (async/chan 1 (map :data))) ;; each EDN post stores relevant data in :data key | |
| (async/take! print-post)) | |
| (->> (get-reddit-posts "limit=5") ;; returns an EDN list of 5 EDN post objects | |
| (async/onto-chan in-chan)))) | |
| (-main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment