This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-01
Channels
- # babashka (2)
- # beginners (45)
- # calva (2)
- # cider (20)
- # clj-kondo (9)
- # cljsrn (1)
- # clojure (25)
- # clojure-europe (7)
- # clojure-nl (24)
- # clojure-spec (4)
- # clojure-uk (3)
- # clojurescript (16)
- # datahike (6)
- # datalevin (6)
- # emacs (35)
- # fulcro (3)
- # holy-lambda (1)
- # lsp (55)
- # nrepl (2)
- # off-topic (17)
- # spacemacs (11)
- # specter (1)
- # xtdb (3)
I'm trying to test for a list in a unit test. The tested function returns a list but when writing the test I have issues with quoting the list. When the test is executed doing '("testdata")
results in (quote ("testdata"))
which is not equal to ("testdata")
. Maybe I should read up on quoting?
I've also tried (list ("testdata"))
but that doesn't work either. Funny enough, though, it did work in another test. 😕
(quote ("testdata"))
should not be a problem:
=> (= (quote (a)) (list 'a))
true
It sounds like you're comparing not the data itself but the forms. Are you sure you need to compare forms?Thanks a lot for this hint. Something else in my test data wasn't right. I was just distracted by the fact that the output printed (quote (a))
. 😄
Also, I probably need to cut my tests into smaller pieces. If I had done that right away, I would have noticed the issue without any help.
I am using "https://github.com/iamkun/dayjs duration objects" in my ClojureScript frontend and I would like to transfer them to Clojure backend using Transit.
I'm supposed to give the Transit "write handler" a type... how do I figure out which type Day.js durantion objects are. Running (type duration-object)
returns #object[l]
, but I cannot see where I go from there.
This is what I've got:
(def write-handlers
{???? (transit/write-handler "time/duration"
^^^^ (fn [duration]
What "type" goes here? (.toISOString duration)))})
AFAICT, Day.js does not export the Duration
class itself so there's no way to get it in an explicit way via an import.
ahhh :thinking_face: I know what to test next... I'm going to get something to eat first 😁
but makes sense (now that I think about it)
For anyone who might find themselves in the same bind as me:
(ns app.transit-format
(:require ["dayjs" :as dayjs]
["dayjs/plugin/duration" :as duration]
[cognitect.transit :as transit]))
;; Extend Day.js with more functionality
(.extend dayjs duration)
(def duration-type
(type (dayjs/duration 1)))
(def write-handlers
{duration-type (transit/write-handler "time/duration"
(fn [duration]
(.toISOString duration)))})
(def read-handlers
{"time/duration" (transit/read-handler #(dayjs/duration %))})
(def custom
"Read and write data encoded in transit+json."
(reify fmt/Format
(read [_ s] (transit/read (transit/reader :json {:handlers read-handlers}) s))
(write [_ v] (transit/write (transit/writer :json {:handlers write-handlers}) v))))
ups... was supposed to have been in "thread", sorry 😄
It would also probably be better as a Gist - much easier to find and share when you're outside of Slack.
now it also exists as a Gist: https://gist.github.com/jacobemcken/82d5df5822a44c5ed646182515c9ffb7