Skip to content

Instantly share code, notes, and snippets.

@LukasRychtecky
Last active December 29, 2022 12:40
Show Gist options
  • Save LukasRychtecky/b7bf73d2133c07b9b7e5c480e2960898 to your computer and use it in GitHub Desktop.
Save LukasRychtecky/b7bf73d2133c07b9b7e5c480e2960898 to your computer and use it in GitHub Desktop.
(ns org.example.playground.handler.visitor)
(defmulti ->json type)
(defmethod ->json java.lang.Boolean
[x]
(str x))
(defmethod ->json java.lang.Long
[x]
(str x))
(defmethod ->json clojure.lang.PersistentVector
[x]
(->> (concat ["["] (interpose ", " (map ->json x)) ["]"])
(reduce str "")))
(defmethod ->json :default
[x]
(str x))
(comment
(->json [1 2 3]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment