Skip to content

Instantly share code, notes, and snippets.

@jaidetree
Created January 18, 2018 07:04
Show Gist options
  • Select an option

  • Save jaidetree/c5155e98ee42525c18e4d3c40751d88c to your computer and use it in GitHub Desktop.

Select an option

Save jaidetree/c5155e98ee42525c18e4d3c40751d88c to your computer and use it in GitHub Desktop.
(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