Skip to content

Instantly share code, notes, and snippets.

@piranha
Last active April 4, 2024 16:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piranha/41856a8dbc0ca43c3a7af7e2e1b05c0b to your computer and use it in GitHub Desktop.
Save piranha/41856a8dbc0ca43c3a7af7e2e1b05c0b to your computer and use it in GitHub Desktop.
cond+
(defmacro cond+ [& clauses]
(when-some [[test expr & rest] clauses]
(condp = test
:do `(do ~expr (cond+ ~@rest))
:let `(let ~expr (cond+ ~@rest))
:some `(or ~expr (cond+ ~@rest))
`(if ~test ~expr (cond+ ~@rest)))))
(ns example
(:require [cond+ :refer [cond+]])
(cond+
(= a b) :true
:do (prn a)
:some b
:let [b a]
(= a b) :finally)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment