Skip to content

Instantly share code, notes, and snippets.

@rauhs
Created February 10, 2017 09:41
Show Gist options
  • Select an option

  • Save rauhs/adcba3e8c48d8fd90104540fc85a1bca to your computer and use it in GitHub Desktop.

Select an option

Save rauhs/adcba3e8c48d8fd90104540fc85a1bca to your computer and use it in GitHub Desktop.
(to-transit [:a :a :aa :aa :aaa :aaa])
;; => "[\"~:a\",\"~:a\",\"~:aa\",\"^0\",\"~:aaa\",\"^1\"]"
;; => keywords >= 2 characters get cached, irregardless of being a map key or not
(to-transit ['a 'a 'aa 'aa 'aaa 'aaa])
;; => "[\"~$a\",\"~$a\",\"~$aa\",\"^0\",\"~$aaa\",\"^1\"]"
;; => same for symbols
(to-transit [{"aaa" "aaa"} {"aaa" "aaa"}
{"aaaa" ""} {"aaaa" ""}])
;; => "[[\"^ \",\"aaa\",\"aaa\"],[\"^ \",\"aaa\",\"aaa\"],[\"^ \",\"aaaa\",\"\"],[\"^ \",\"^0\",\"\"]]"
;; => Strings >= 4 characters get cached
;; => Map values are never cached
(to-transit [{"aaaa" ?/u0} {"aaaa" ?/u0}])
;; => "[[\"^ \",\"aaaa\",\"~u00000000-0000-0000-0000-000000000000\"],[\"^ \",\"^0\",\"~u00000000-0000-0000-0000-000000000000\"]]"
(to-transit [{?/u0 "aaaa"} {?/u0 "aaaa"}])
;; => "[[\"^ \",\"~u00000000-0000-0000-0000-000000000000\",\"aaaa\"],[\"^ \",\"^0\",\"aaaa\"]]"
;; => UUIDs as map keys are also cached!
;; If you want some map values cached, like a UUID that likely occurs often:
(to-transit [{:object/id (symbol (str ?/u0))} {:object/id (symbol (str ?/u0))}])
;; => "[[\"^ \",\"~:object/id\",\"~$00000000-0000-0000-0000-000000000000\"],[\"^ \",\"^0\",\"^1\"]]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment