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 fizzbuzz | |
([m1 m2 n] | |
(let [ c #(->> % vector (concat (-> %2 dec (repeat nil))) cycle) | |
fb-re #"Fizz|Buzz|FizzBuzz"] | |
(->> [(c "Fizz" m1), (c "Buzz" m2)] | |
(apply map | |
(fn [i m1 m2] | |
(or (re-matches fb-re (str m1 m2)) | |
i)) | |
(range 1 (inc n)))))) |
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
(ns hellospec.fizzbuzz | |
(:require [clojure.spec :as s] | |
[clojure.spec.test :as stest] | |
;; to accomodate KLIPSE: | |
;; "[...]cljs.spec.gen.frequency is undefined[...]" | |
#?(:clj [clojure.spec.gen :as gen] | |
:cljs [clojure.test.check.generators :as gen]))) | |
;; A fizzbuzz which doesn't use condition checking/branching | |
(defn fizzbuzz |
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
(require '[clojure.spec :as s] | |
'[clojure.spec.test :as stest]) | |
(defn fizzbuzz | |
([m1 m2 n] | |
(let [ c #(->> % vector (concat (-> %2 dec (repeat nil))) cycle) | |
fb-re #"Fizz|Buzz|FizzBuzz"] | |
(->> [(c "Fizz" m1), (c "Buzz" m2)] | |
(apply map | |
(fn [i m1 m2] |
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
(ns scratch.transducer | |
(:refer-clojure :exclude [comp map filter mapcat take drop | |
take-while drop-while | |
dedupe | |
distinct | |
reductions | |
;; sequence | |
transduce])) | |
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
(require '[clojure.core.async :as async :refer [chan <!! put!]]) | |
(defn save-to [c save-f] | |
(fn [rf] | |
(fn | |
([] (rf)) | |
([acc] (rf acc)) | |
([acc x] | |
(put! c (save-f x)) | |
(rf acc x))))) |
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
;; see | |
;; https://gist.github.com/ericnormand/81722b80fc7d0b2972fda68652489f65 | |
(ns my-ns-test | |
(:require [my-ns :as sut] | |
[clojure.test.check.properties :as prop] | |
[clojure.test.check.generators :as gen] | |
[clojure.test.check.clojure-test :refer [defspec]])) | |
(let [alias-str "sut" | |
sym (symbol (str alias-str "/parallel?"))] |
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 lazify [[x & xs :as coll]] | |
(lazy-seq | |
(when (seq coll) | |
(cons x (lazify xs))))) | |
(def my-lazy-input (lazify [1 2 4 1 2 3 1])) | |
(type my-lazy-input) ;; => clojure.lang.LazySeq | |
(type (rest my-lazy-input)) ;; => clojure.lang.LazySeq | |
;; So my-lazy-input is truly lazy all the wal...Now I want to feed it to 'sequence |
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
(ns cond-let) | |
;; (cond-let | |
;; (odd? x) [x n] (inc x) | |
;; (< n 10) [y (inc n)] 10 | |
;; :else n)) | |
;; we want the above to yield | |
;; (let [x n] | |
;; (if (odd? x) | |
;; (inc x) |
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 monoid* [init body] | |
`(fn f# | |
([] | |
(fn [& ~'xs] ~init)) | |
([~'r] | |
(fn [& ~'xs] (~body (apply ~'r ~'xs)))) | |
([~'r1 ~'r2] | |
(fn [& ~'xs] (~body(apply ~'r1 ~'xs) (apply ~'r2 ~'xs)))) | |
([~'r1 ~'r2 & ~'rs] | |
(fn [& ~'xs] |
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 slow-assoc [m & [k v & kvs :as dat]] | |
(if (empty? dat) | |
m | |
(apply slow-assoc (assoc m k v) kvs))) | |
(defn emit-assoc [ [ksym vsym]] | |
`(assoc ~ksym ~vsym)) | |
(defmacro fast-assoc [msym & kvsyms] | |
(let [assocs (map #(emit-assoc %) |
OlderNewer