Niki Tonsky on Nostr: Useful Clojure functions that fit in toot (defn zip [& xs] (apply map vector xs)) ...
Useful Clojure functions that fit in toot
(defn zip [& xs]
(apply map vector xs))
(defn now []
(System/currentTimeMillis))
(defn between? [x from to]
(and
(<= from x)
(< x to)))
(defn index-of [x xs]
(loop [i 0 xs xs]
(cond
(nil? xs) nil
(= (first xs) x) i
:else (recur (inc i) (next xs)))))
(defn index-by [pred xs]
(loop [i 0 xs xs]
(cond
(nil? xs) nil
(pred (first xs)) i
:else (recur (inc i) (next xs)))))
Published at
2024-05-31 17:44:01Event JSON
{
"id": "321e66b1a93c852fab23334881f8b4beb5c0ef8496d44012e50b3880b7d99697",
"pubkey": "5ff668c99bd4862e80a7c65340fe52863bda29fc1217bf35f8da498b66c299cb",
"created_at": 1717177441,
"kind": 1,
"tags": [
[
"proxy",
"https://mastodon.online/users/nikitonsky/statuses/112536940796403157",
"activitypub"
]
],
"content": "Useful Clojure functions that fit in toot\n\n(defn zip [\u0026 xs]\n (apply map vector xs))\n\n(defn now []\n (System/currentTimeMillis))\n\n(defn between? [x from to]\n (and\n (\u003c= from x)\n (\u003c x to)))\n\n(defn index-of [x xs]\n (loop [i 0 xs xs]\n (cond\n (nil? xs) nil\n (= (first xs) x) i\n :else (recur (inc i) (next xs)))))\n\n(defn index-by [pred xs]\n (loop [i 0 xs xs]\n (cond\n (nil? xs) nil\n (pred (first xs)) i\n :else (recur (inc i) (next xs)))))",
"sig": "09b448ad0b48984027db624e4df604bd0d166d46fa030f9abac9329feebf4adadf534b62b043412034d2d615e155abb5c825708f68f70a6de7f7edc0c855dea4"
}