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
-- Both exercises have a common pattern of "filter by a transformed list, then untransform the result". | |
-- Is there an idiomatic way to do this? | |
-- I am thinking like `filterBy :: (b -> Bool) -> (a -> b) -> [a] -> [b]`, | |
-- but i also need (b->a) and that's no better than what i already have | |
-- exercise 1 | |
skips :: [a] -> [[a]] | |
skips xs = map (\n -> skip n xs) [1..(length xs)] | |
skip :: Integral n => n -> [a] -> [a] |
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
(ns clojure-examples.tree) | |
(defn array? [thing] | |
(.isArray (class thing))) | |
(defn map-tree [t f path state] | |
(cond | |
(map? t) | |
(reduce | |
(fn [acc [k v]] |
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
(ns streaker-service.util) | |
(defn deep-merge | |
"Recursively merges maps. If vals are not maps, the last value wins. | |
(from https://groups.google.com/forum/#!topic/clojure/UdFLYjLvNRs)" | |
[& vals] | |
(if (every? map? vals) | |
(apply merge-with deep-merge vals) | |
(last vals))) |
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
(ns streaker-service.routes | |
(:require [io.pedestal.http :as bootstrap] | |
[io.pedestal.http.route :as route] | |
[io.pedestal.http.body-params :as body-params] | |
[io.pedestal.http.route.definition :refer [defroutes]] | |
[io.pedestal.interceptor :as interceptor] | |
[streaker-service.api :as api] | |
[streaker-service.page :as page] | |
[streaker-service.pedestal-util :as pedestal-util] | |
[streaker-service.models.question :as question] |
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
(defn questions-get [req] | |
(api/collection-read ::questions-get | |
'[:find ?e :where [?e :Question/text]] | |
question/typeinfo)) | |
(defn mk-handlers [] | |
`{:get questions-get}) | |
(def routes | |
(expand-routes |
(def routes
(expand-routes
`[[["/echo" {:any page/echo}]
["/api" {:get api-get}
^:interceptors [(body-params/body-params)
pedestal-util/auto-content-type
pedestal-util/combine-body-params]
["/questions" {:get questions-get :post questions-post}
streaker-service.routes> (-> (route "questions" '[:find ?e :where [?e :Question/text]] question/typeinfo)
(clojure.pprint/pprint))
["/questions"
{:get
[:questions
#<routes$mk_coll_get$fn__25468 streaker_service.routes$mk_coll_get$fn__25468@29a0eb18>],
:post
[:questions/post
#<routes$mk_coll_post$fn__25474 streaker_service.routes$mk_coll_post$fn__25474@751a8975>]}]
(defn route2 [root]
(let [coll-route (keyword root)
coll-handler (fn [req] {:ok :ok})]
`~[(str "/" root) {:get [coll-route coll-handler]}]))
(def routes2
(expand-routes
(ns streaker-service.routes
(:require [io.pedestal.http :as bootstrap]
[io.pedestal.http.route :as route]
[io.pedestal.http.body-params :as body-params]
[io.pedestal.http.route.definition :refer [expand-routes]]
[io.pedestal.interceptor :githuas interceptor :refer [defhandler]]
[ring.util.response :as ring-resp]
[streaker-service.api :as api]
[streaker-service.page :as page]