Last active
December 18, 2015 10:39
-
-
Save jeremyheiler/5770079 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
(require '[paprika.core :as adn]) | |
;; This returns a sequence your of vectors, one for each of the people you follow. | |
;; Each vector contains the user's username and the date of their last post. | |
;; The sequence is in ascending order by the date of their last post | |
;; Careful, though. The lookup is N+1. | |
(sort-by first | |
(map (juxt :created-at #(get-in % [:user :username])) | |
(apply concat | |
(map #(adn/lookup-user-posts % {:count 1 :access-token t})) | |
(adn/lookup-following-ids "me" {:access-token t})))) |
(->> (:data (p/lookup-following-ids "me" {:token t})) (map #(:data (p/lookup-user-posts % {:count 1 :token t}))) (apply concat) (map (juxt :created-at #(get-in % [:user :username]))) (sort-by first))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using a combined monadic bind + thread-last operator:
(Using core's thread-last
->>
macro would flatten out the nesting in your examples a lot.)I based this off distant memories of the monad stuff in Marick's fp-oo book. The
adn/Either
tells the monad library which monad function implementations to use.adn/Either
would be a Paprika-specific Either that knows to treat:data
asRight
and:error
asLeft
. Its bind either extracts Right and feeds that to the function, or skips invoking the function and returns Left directly.(re: https://alpha.app.net/jeremyheiler/post/6815186)