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
| ;; (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 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
| (defn debounce [in ms] | |
| (let [out (chan)] | |
| (go-loop [last-val nil] | |
| (let [val (if (nil? last-val) (<! in) last-val) | |
| timer (timeout ms) | |
| [new-val ch] (alts! [in timer])] | |
| (condp = ch | |
| timer (do (>! out val) (recur nil)) | |
| in (recur new-val)))) | |
| out)) |
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
| ;; The deps.edn file describes the information needed to build a classpath. | |
| ;; | |
| ;; When using the `clojure` or `clj` script, there are several deps.edn files | |
| ;; that are combined: | |
| ;; - install-level | |
| ;; - user level (this file) | |
| ;; - project level (current directory when invoked) | |
| ;; | |
| ;; For all attributes other than :paths, these config files are merged left to right. | |
| ;; Only the last :paths is kept and others are dropped. |
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
| (defn stateful-map | |
| "Returns a stateful transducer similar to `clojure.core/map-indexed` that | |
| transforms each item with `(f state <the item>)` where `state` is built by | |
| applying `state-building-fn` to the previous state (starting with `init`) and | |
| the transformed item. | |
| Ex., re-implementing map-indexed: | |
| ```clojure | |
| (sequence (stateful-map vector (fn build-state [idx _] (if idx (inc idx) 5))) \"abc\") | |
| ; => ([nil \\a] [5 \\b] [6 \\c]) |
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
| ;; A macro to create a decorator (wrapper) for a objects implementing a Java interface | |
| ;; Disclaimer: The code most certainly is not perfect and does not handle some corner cases | |
| ;; License: The Unlicense http://unlicense.org/ | |
| (require '[clojure.string :as str]) | |
| (defn type->tag [parameter-type] | |
| (let [array? (-> parameter-type name (str/ends-with? "<>")) | |
| primitive? '#{int long float double short boolean byte char} | |
| type (if array? | |
| (-> parameter-type name (str/replace #"<>$" "") symbol) |
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
| (ns complex-business-process-example-missionary | |
| "A stupid example of a more complex business process to implement as a flowchart." | |
| (:require [missionary.core :as m]) | |
| (:import missionary.Cancelled)) | |
| ;;;; Config | |
| (def config | |
| "When set to :test will trigger the not-boosted branch which won't write to db. | |
| When set to :prod will trigger the boosted branch which will try to write to the db." |
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
| (ns complex-business-process-example | |
| "A stupid example of a more complex business process to implement as a flowchart.") | |
| ;;;; Config | |
| (def config | |
| "When set to :test will trigger the not-boosted branch which won't write to db. | |
| When set to :prod will trigger the boosted branch which will try to write to the db." | |
| {:env :prod}) |
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
| #!/bin/sh | |
| #_( | |
| true; exec clj -J-Xmx256M -J-XX:-OmitStackTraceInFastThrow -Sdeps "`sed -n -e '/;;(DEPS$/,/;;DEPS)$/p' $0`" -M -i $0 -e '(user/main)' | |
| ) | |
| (ns user | |
| #?(:cljs (:require-macros [user :as m])) | |
| (:require | |
| #?@(:clj ([cljs.build.api :as cljs] |
A gist containing a problem example and different implementations based on what is being discussed at How are clojurians handling control flow on their projects?.
Feel free to leave a comment and feedback is welcome 😃
- Bult-in exceptions in a thread macro
- didibus'
tryletmacro
OlderNewer