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 subs-to | |
"Like subs, but does not throw if index is out of range" | |
([s start] | |
(subs-to s start (count s))) | |
([s start end] | |
(if (or (<= (count s) start) (<= end start)) | |
"" | |
(subs s start (min (count s) end))))) | |
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
(->> [1 2 3 4 5] ; the initial vector | |
(filter odd?) ; after this step we have: (1 3 5) | |
(take 2) ; (1 3) | |
last ; 3 | |
inc) ; 4 |
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
(inc (last (take 2 (filter odd? [1 2 3 4 5])))) |
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
(defmacro ->> | |
([x form] (if (seq? form) | |
(with-meta `(~(first form) ~@(next form) ~x) (meta form)) | |
(list form x))) | |
([x form & more] `(->> (->> ~x ~form) ~@more))) |
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
I did a lot of my initial learning with https://www.4clojure.com/problems | |
The Joy of Clojure book is a great reference. | |
A nice basic tutorial on how to use common macros: | |
http://cjohansen.no/clojure-to-die-for | |
I still spend a lot of time on: | |
http://clojuredocs.org/quickref/Clojure%20Core to get an overview of | |
the functions that exist and examples using them. |
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
{;; HTTP-related info | |
:path "/entries/" | |
:method :post | |
:description | |
"Add a new entry to the guestbook" | |
;; information about the HTTP request that the handler expects | |
:request | |
{:body Entry |