Skip to content

Instantly share code, notes, and snippets.

@jebberjeb
jebberjeb / wrap-java.clj
Last active December 20, 2015 22:49
Wrap a java method call for easy use w/ map, filter, etc using a macro. memfn obviates this mess.
(defmacro ->j-fn [j-fn]
(let [args (gensym "args")]
`(fn [~args]
(eval (cons '~j-fn (if (coll? ~args) ~args (list ~args)))))))
;trivial
((->j-fn .length) "foo")
;useful, since you can't do (map .length ["foo" "bar"])
(map (->j-fn .length) ["foo" "bar"])
@jebberjeb
jebberjeb / foozle.clj
Last active December 19, 2015 12:29
This is that example from yesterday's TDD that was tripping me up. Looks easy here -- think I just need to do more apply (partial map foo) coll of colls.
(def ->num {[" "
" |"
" |"
" "] 1
[" _ "
" _|"
"|_ "
" "] 2
[" _ "
" _|"