Skip to content

Instantly share code, notes, and snippets.

@henryw374
henryw374 / flexi_clock.clj
Created October 17, 2024 16:11
clojure java.time clock
(ns flexi-clock
(:import (java.time Clock Duration Instant ZonedDateTime)))
(defn clock
"potential library function (e.g. in tick or tempo).
This just implements the platform Clock - which works because non-test code only uses that API.
Any manipulation of time (which happens in testing code) is done via changing
what get-instant and get-zone return"
[get-instant get-zone]
@daveliepmann
daveliepmann / assert-or-not.md
Last active March 2, 2025 12:24
A guide to orthodox use of assertions in Clojure.

When to use assert?

In JVM Clojure, Exceptions are for operating errors ("something went wrong") and Assertions are for programmer and correctness errors ("this program is wrong").

An assert might be the right tool if throwing an Exception isn't enough. Use them when the assertion failing means

  • there's a bug in this program (not a caller)
  • what happens next is undefined