This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-07
Channels
- # architecture (35)
- # babashka (9)
- # beginners (31)
- # biff (15)
- # calva (8)
- # catalyst (3)
- # cider (7)
- # clerk (4)
- # clj-kondo (24)
- # clj-yaml (10)
- # clojure (58)
- # clojure-europe (65)
- # clojure-japan (1)
- # clojure-nl (1)
- # clojure-norway (89)
- # clojure-spec (1)
- # clojure-sweden (1)
- # clojure-uk (8)
- # clojurescript (14)
- # cursive (3)
- # datahike (1)
- # datomic (29)
- # emacs (8)
- # graalvm (20)
- # graphql (1)
- # gratitude (2)
- # helix (6)
- # hyperfiddle (65)
- # jobs-discuss (7)
- # leiningen (1)
- # lsp (6)
- # malli (14)
- # missionary (12)
- # nrepl (8)
- # off-topic (24)
- # polylith (29)
- # reagent (14)
- # sci (14)
- # shadow-cljs (6)
- # spacemacs (10)
- # sql (4)
I'm playing around with clj-yaml. I'm not seeing how to 'dump' a collection value to a block style.
Hiya Ingy! Are the https://github.com/clj-commons/clj-yaml/blob/master/doc/01-user-guide.adoc#dumper-options not working for you?
Heh. Should have read docs first I guess.
user=> (defn load [s] (yaml/parse-string s))
#'user/load
user=> (defn dump [o] (yaml/generate-string o :dumper-options {:flow-style :block}))
#'user/dump
user=> (->> {"a" 1, :b 2} dump load dump print)
a: 1
b: 2
nil
user=>
:dumper-options {:flow-style :block}
is an unfortunate naming choice
better as :coll-style :block
yaml collections have 2 styles: block and flow.
"flow style" makes no sense in a yaml context.
but there's a lot of unfortunate choices in this lib wrt yaml vocabulary (which many implementors seem to not learn). I think it goes to show that the yaml spec is not used so much by implementors except for reference on edge cases.
btw, this doesn't bother me much. just pointing it out.
I'm hoping to make a reference implementation in clojure eventually.
This was probably just picked up from https://www.javadoc.io/doc/org.yaml/snakeyaml/latest/org/yaml/snakeyaml/DumperOptions.FlowStyle.html. I suppose we could make :coll-style
be a synonym for :flow-style
. And update docs to describe :coll-style
. But... maybe this would only really eat at a person who wrote the YAML spec?
user=> (defn load [s] (yaml/parse-string s))
#'user/load
user=> (defn dump [o] (yaml/generate-string o :dumper-options {:flow-style :block}))
#'user/dump
user=> (-> {{"a" nil} 1, [:b] 2} dump load dump print)
? a: null
: 1
? - b
: 2
nil
is what I wanted to check. clj-yaml supporting collection keys. 👍