Skip to content

Instantly share code, notes, and snippets.

@wevre
wevre / let_not.clj
Last active July 17, 2020 00:51
Clojure monad for short-circuiting computation based on a `fail?` predicate
(ns let-not
^{:author "Mike Weaver"
:see-also [["https://github.com/clojure/algo.monads"]
["https://brehaut.net/blog/2011/error_monads_revisited" "Error monads revisited"]]
:doc "A monad for short-circuiting computation based on a `fail?` predicate."}
(:require [clojure.algo.monads :refer [monad domonad]]))
(defn break-m
"An extension to the `maybe-m` monad that in addition to checking for `nil?`
checks if the computation fails using predicate `fail?`."
@wevre
wevre / natural_compare.clj
Last active July 17, 2020 00:46
Natural sort comparator in Clojure/ClojureScript
(ns natural-compare
^{:author "Mike Weaver"
:see-also [["https://gist.github.com/wilkerlucio/db54dc83a9664124f3febf6356f04509"
"Alphabetical/Natural sorting in Clojure/Clojurescript"]]
:doc "A comparator for natural sorting."}
(:require [clojure.string :as str]))
(defn split-digits
"Splits string into sequence of alternating text and numbers."
[s]