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
const makeSingleIO = () => { | |
let put, err; | |
const promise = new Promise((resolve, reject) => { | |
put = resolve; | |
err = reject; | |
}); | |
return { put, err, get: () => promise }; | |
}; | |
const testSingleIO = async () => { |
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 <-> [expr-1 expr-2 & exprs] | |
(let [expr-2-with-expr-1-let `(let ~['<- expr-1] | |
~(if (seq? expr-2) | |
expr-2 | |
`(~expr-2 ~'<-) ) )] | |
(if exprs | |
`(<-> ~expr-2-with-expr-1-let ~@exprs) | |
expr-2-with-expr-1-let ) ) ) | |
;; Example |
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 -> (expr-1 expr-2 &rest exprs) | |
(let ((expr-2-with-expr-1-let `(let ((<- ,expr-1)) ,expr-2))) | |
(if exprs | |
`(-> ,expr-2-with-expr-1-let ,@exprs) | |
expr-2-with-expr-1-let ) ) ) | |
(-> (load-data) | |
(group-by-species <-) | |
(gethash 'iris-virginica <-) | |
(format t "~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
(defmacro should-equal (a b) | |
(let ((a-sym (gensym)) | |
(b-sym (gensym)) ) | |
`(let ((,a-sym ,a) | |
(,b-sym ,b) ) | |
(if (not (equal ,a-sym ,b-sym)) | |
(push (format nil "~a is not equal to ~a" ,a-sym ,b-sym) *results*) ) ) ) ) | |
(defmacro context (description &rest body) | |
`(let ((indent (if (boundp '*indent*) |
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 better-if-let | |
([bindings then] | |
`(better-if-let ~bindings ~then nil)) | |
([[form tst & rest-bindings] then else] | |
`(let [temp# ~tst] | |
(if temp# | |
(let [~form temp#] | |
~(if (seq rest-bindings) | |
`(better-if-let ~(vec rest-bindings) ~then ~else) | |
then)) |
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
(def append-fn #(conj (or % []) %2)) | |
(deftest append-fn-test | |
(testing "works as advertised" | |
(is (= {:a {:b 1 :c [2]}} (update-in {:a {:b 1}} [:a :c] append-fn 2))) | |
(is (= {:a {:b 1 :c [2 3]}} (update-in {:a {:b 1 :c [2]}} [:a :c] append-fn 3))) ) ) | |
(def prepend-fn #(into [%2] (or % []))) | |
(deftest prepend-fn-test |
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
(parse (formatter "MMddyyyy") (str "0102" (year (now)))) | |
; => #<DateTime 2014-01-02T00:00:00.000Z> | |
(minus (parse (formatter "MMddyyyy") (str "0102" (year (now)))) (years 1)) | |
; => #<DateTime 2013-01-02T00:00:00.000Z> |