Skip to content

Instantly share code, notes, and snippets.

-- 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]
We couldn’t find that file to show.
(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]]
(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)))
(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]
@dustingetz
dustingetz / gist:15a5eda645df9694fea7
Last active August 29, 2015 14:12
Pedestal dynamic routes
(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
@dustingetz
dustingetz / gist:d7e859a2a2f121ae9107
Last active August 29, 2015 14:13
Pedestal expanded 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]