View transducerfun.clj
(require '[clojure.core.async :as a])
(def xform (comp (map inc)
(filter even?)
(flatmap range)
(partition-all 3)
(partition-by #(< (apply + %) 7))
(flatmap flatten)
(random-sample 1.0)
View mapperf.clj
(ns bitmapmap-test.core-test
(:use clojure.test))
#_(defn bitmap-map
"Constructs a bitmap-map. If any keys are equal, they are handled as
if by repeated uses of assoc."
{:added "1.6"
:static true}
([] (. clojure.lang.PersistentBitmapMap EMPTY))
([& keyvals]
View codeq-examples.clj
(require '[datomic.api :as d])
(require '[clojure.pprint :refer [pprint]])
(def uri "datomic:free://localhost:4334/git")
(def conn (d/connect uri))
(def db (d/db conn))
;; committers
(d/q '[:find ?email
[_ :commit/committer ?u]
View thread.clj
(defmacro test->
"Takes an expression and a set of test/form pairs. Threads expr (via ->)
through each form for which the corresponding test expression (not threaded) is true."
& clauses]
(assert (even? (count clauses)))
(let [g (gensym)
pstep (fn [[test step]] `(if ~test (-> ~g ~step) ~g))]
`(let [~g ~expr
~@(interleave (repeat g) (map pstep (partition 2 clauses)))]
View bintree.clj
;; The Computer Language Benchmarks Game
;; Adapted from the Java -server version
;; contributed by Marko Kocic
;; modified by Kenneth Jonsson, restructured to allow usage of 'pmap'
;; modified by Andy Fingerhut to use faster primitive math ops, and
;; deftype instead of defrecord for smaller tree nodes.
;; modified by RH for 1.3
View gist:605527
{:code (prn "Hello world")}
View gist:440102
;new num branch results
(defn fib [n]
(if (>= 1 n)
(+ (fib (dec n)) (fib (- n 2)))))
(time (fib 38))
"Elapsed time: 3716.828 msecs"
View gist:432465
(defn ^:static fib ^long [^long n]
(if (>= (long 1) n)
(long 1)
(+ (fib (dec n)) (fib (- n (long 2))))))
(dotimes [_ 10] (time (fib 38)))
View gist:430205
[java] FAIL in (test-annotations) (test_clojure.clj:92)
[java] Parameter annotations: void foo(@Retention(?) String)
[java] expected: (instance? Retention retention)
[java] actual: $Proxy2
[java] FAIL in (test-annotations) (test_clojure.clj:92)
[java] Parameter annotations: void foo(@Target(?) String)
[java] expected: (instance? Target target)
[java] actual: $Proxy1
View gist:377213
;annotation syntax
(import [java.lang.annotation Retention RetentionPolicy Target ElementType]
[ WebServiceRef WebServiceRefs])
(definterface Foo (foo []))
;annotation on type
(deftype ^{Deprecated true
Retention RetentionPolicy/RUNTIME
javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]