Last active
July 24, 2026 18:59
-
-
Save LeaveNhA/e1839dbaf599afdf1f8e046ded7ea43b to your computer and use it in GitHub Desktop.
Some Clojure don't-s
This file contains hidden or 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
| # abusing partials and almost intentionally avoding named parameters won't make your code more functional. | |
| (fn [xs n] ((comp (partial reduce (partial apply conj) []) (partial map (partial apply drop-last)) (partial map (comp #( | |
| update % 0 (fn [p] (- p (- n 1)))) (juxt count identity))) (partial apply partition-all) reverse vector) xs n)) | |
| # if you think list processing isn't in the nature of the language, you have to see a professional. | |
| (comp (partial apply map vector) (partial apply partition-all) reverse vector) | |
| # lisp family languages can show-off enough for you, stop doing fancy things. | |
| (fn [n xs] | |
| (take (count xs) | |
| (drop (if (pos? n) | |
| n | |
| (+ (count xs) (mod n (count xs)))) | |
| (cycle xs)))) | |
| # types are not just for machines. It also f helps much, after names. | |
| # without good naming skills, you can all day play with s-expressions, you can never be serious enough. | |
| (fn [xs] | |
| (->> xs | |
| (partition 2 1) | |
| ((juxt identity | |
| (comp (partial map (partial apply -))))) | |
| (apply map vector) | |
| (partition-by (comp (partial = -1) second)) | |
| (filter (comp (partial = -1) second first)) | |
| (group-by count) | |
| (sort-by first >) | |
| first | |
| second | |
| first | |
| (map first) | |
| ((juxt (comp reverse first) (comp (partial map second) rest))) | |
| reverse | |
| (apply into))) | |
| # if you grow up with a hammer everything is a nail. | |
| # if you grow up with lisp, everything is list. | |
| (fn [i xs] | |
| (let [c (count xs)] | |
| (filter | |
| (comp (partial = i) | |
| count) | |
| (map #(take %2 (drop %1 xs)) | |
| (range 0 c i) | |
| (repeat i))))) | |
| # frequency Morty, everything is frequency! | |
| # Nothing is true, everything is permitted. | |
| (comp (partial into {}) | |
| (partial apply map #(vector %1 (count (filter (partial = %1) %2)))) | |
| (juxt (partial into #{}) | |
| repeat)) | |
| # The ability to distinguish the a-s from b-s is realising b-s is really a bull-shit. | |
| # functional programming is a long way inwards, not outwards. | |
| # Enough aphorism, just keep it clear. Remember the code itself is not for the machine, | |
| # you don't even feed the code itself to the machine, you translate it to something else. | |
| # So, make it readable, respect it's life-cycle, just try to see things clearly! | |
| #(:acc | |
| (reduce (fn [acc' n] | |
| (let [{:keys [steps acc]} acc'] | |
| (if (contains? steps n) | |
| acc' | |
| {:steps (conj steps n) | |
| :acc (conj acc n)}))) | |
| {:steps #{} | |
| :acc []} | |
| %)) | |
| # if you can't see the light (solution) in the end of the road, turn your face the other way. | |
| # There is always another way, like there is always a function in Clojure standard library | |
| # to save your dead-born idea. | |
| (comp (partial apply merge-with into) | |
| (partial map (partial apply assoc {})) | |
| (partial apply map #(vector (%1 %2) | |
| [%2])) | |
| (juxt (comp repeat first) | |
| (comp second)) | |
| vector) | |
| # ask the questions no one wanted to ask. | |
| # functional programming by nature is closer to the bare metal (math) | |
| # if you don't keep your mind close to how your domain looks in | |
| # your mathematical surface (your software), you are doomed. | |
| (comp | |
| (partial get | |
| {"#" :set "[" :vector "(" :list "{" :map}) | |
| str | |
| first | |
| str) | |
| # I wanna came in like a wrecking vector... | |
| (fn [n] | |
| (->> (range) | |
| (drop 3) | |
| (map (juxt (comp (partial apply repeat) (juxt (comp dec dec) identity)) | |
| (comp (partial range 2) identity))) | |
| (drop 1) | |
| (map (fn [[a b]] (vector (first a) (map rem a b)))) | |
| (filter (comp not (partial some zero?) second)) | |
| (map first) | |
| (concat [2 3]) | |
| (take n))) | |
| # If you can't tell the difference, does it matter? | |
| # For you, no. For a higher being, yes. | |
| # Always think outside of the box. | |
| # Your god can take you out of the box one day | |
| # —alas, that problem you ignored might just become yours. | |
| (fn mw' | |
| ([f m mm & rmm] | |
| (reduce (partial mw' f) | |
| (mw' f m mm) | |
| rmm)) | |
| ([f m mm] | |
| (reduce | |
| (fn [acc [k v]] | |
| (if (contains? acc k) | |
| (assoc acc k (f (get acc k) v)) | |
| (assoc acc k v))) | |
| m | |
| mm))) | |
| # You are not better than me! | |
| # *Said ClojureScript to Clojure* | |
| (comp | |
| (partial map first) | |
| (partial sort-by second) | |
| (partial map (partial map (partial apply str))) | |
| (partial map (comp (partial apply map vector) (partial map (partial map char)))) | |
| (partial filter (complement (partial = [[32 32]]))) | |
| (partial partition-by (comp (partial contains? (into #{} (range 97 123))) second)) | |
| (partial map (juxt first (partial apply +))) | |
| (partial map (juxt identity (comp (partial get {false 0 true 32}) (partial every? true?) (juxt (partial < 64) (partial > 97))))) | |
| (partial filter (partial contains? (into #{32} (concat (range 65 91) (range 97 122))))) | |
| #_(partial map int) (partial map #(.charCodeAt % 0))) | |
| # Still reading? | |
| (fn [[t m b]] | |
| (second (first | |
| (filter (comp (partial = 1) first) | |
| (filter (comp (partial get #{:x :o}) second) | |
| (map (juxt count ffirst) | |
| (map (partial partition-by identity) | |
| (conj (mapv vector t m b) | |
| t m b | |
| (vec (map-indexed (fn [i row] (nth row i)) [t m b])) | |
| (vec (map-indexed (fn [i row] (nth row i)) [b m t])))))))))) | |
| # As a hosted language, you have to know the platform it is running like | |
| # you know clojure/script. So you can stay alive in nuances and many dead-ends. | |
| (comp | |
| (partial apply str) | |
| (partial interpose ",") | |
| (partial filter #(some (set [%]) | |
| (->> (range) (drop 1) ((juxt identity identity)) (apply map *) (take 100)))) | |
| ;; finally, OMFG what a hurdle. | |
| (partial map js/parseInt) | |
| (partial apply clojure.string/split) | |
| reverse | |
| (partial vector #",")) | |
| # If you think you are polygot, that's cute. If you don't learn any language that destroys your | |
| # mental model over your understanding and model of compuation, you are doomed. | |
| (comp | |
| set | |
| (partial map set) | |
| (partial map (partial map first)) | |
| vals | |
| (partial filter (comp (partial < 1) count second)) | |
| (partial group-by (comp second)) | |
| (partial apply map vector) | |
| (juxt identity | |
| (comp (partial map frequencies) | |
| (partial map vec)))) | |
| # ok, I cannot justify this one. This one is all on me. | |
| (comp | |
| first | |
| (partial sort) | |
| (partial map (partial reduce +)) | |
| (partial map (partial map (partial apply get))) | |
| (partial map (partial apply map (comp (juxt (comp first) | |
| (comp first second)) | |
| reverse vector))) | |
| (partial apply map vector) | |
| (juxt (comp | |
| (partial map (comp (partial map vector) (partial drop 1) (partial reductions + 0))) | |
| (partial map (partial map {48 0 49 1})) | |
| (partial map (partial map (comp {48 48 49 49 32 48} int))) | |
| (partial map (partial format "%6s")) | |
| (partial map Integer/toBinaryString) | |
| (partial range) | |
| (partial apply *) | |
| (partial apply repeat) | |
| (juxt identity (constantly 2)) | |
| dec | |
| count) | |
| repeat)) | |
| # same curse, in different cursed language with just a little bit commentary from the author | |
| (comp | |
| ;; original sin. | |
| first | |
| ;; I'm bored. | |
| (partial sort) | |
| ;; if you can't read it, start with something small. | |
| (partial map (partial reduce +)) | |
| ;; ... | |
| (partial map (partial map (partial apply get))) | |
| ;; obvious | |
| (partial map (partial apply map (comp (juxt (comp first) | |
| (comp first second)) | |
| reverse vector))) | |
| ;; combine with original, obviously | |
| (partial apply map vector) | |
| (juxt (comp | |
| ;; obviously taking steps transform them into path into our surface | |
| (partial map (comp (partial map vector) (partial reductions + 0))) | |
| (partial apply map (partial apply into)) | |
| ;; obvious? making it ready to making it into [0]+[1 2]=[0 1 2]? | |
| reverse | |
| ;; take difference and pad it. | |
| (juxt (comp (partial map vector) first) | |
| (comp (partial map (partial apply repeat)) | |
| (partial map reverse) | |
| (partial map (partial vector 0)) | |
| (partial apply map -) | |
| rest)) | |
| ;; composing to pad/f it. | |
| (juxt identity | |
| (comp repeat | |
| (partial apply max) | |
| (partial map count)) | |
| (partial map count)) | |
| (partial map (partial map int)) | |
| ;; numbers -> binary | |
| (partial map #(js/Number.prototype.toString.call % 2) #_Integer/toBinaryString) | |
| ;; extenting the surface | |
| (partial range) | |
| ;; 2^(n-1) | |
| (partial apply *) | |
| (partial apply repeat) | |
| (juxt identity (constantly 2)) | |
| ;; -1 | |
| dec | |
| ;; n | |
| count) | |
| repeat)) | |
| # if you would know if there always another implementation that is cleaner, | |
| # simpler, safer, would you go with the current one? | |
| (comp | |
| (partial apply =) | |
| (juxt | |
| (comp | |
| (partial reduce +) | |
| (partial map second) | |
| (partial filter (comp zero? (partial apply rem))) | |
| (partial apply map vector) | |
| reverse | |
| (fn level [[xs m]] | |
| (vector (vec xs) | |
| (vec (repeat (count xs) m)))) | |
| (juxt (comp | |
| (partial drop 1) | |
| range | |
| inc | |
| (partial apply /) | |
| reverse | |
| (partial vector 2)) | |
| (comp #_repeat identity))) | |
| identity)) | |
| #_"To be continued..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment