Fork me on GitHub
#babashka
<
2020-03-22
>
farenzer_house02:03:03

👋 it seems some sort of combination of -o and piping to “jet” has an Map literal must contain an even number of forms

farenzer_house02:03:15

:~ $ bb -o '(filter (fn [c] (#{ "Arizona" } (:state c))) (-> (curl/get "") (json/parse-string true)))' | jet --pretty
{:state Arizona,
 :cases 104,
 :todayCases 0,
 :deaths 1,
 :todayDeaths 0,
 :recovered 1,
 :active 102}
:~ $ bb -o '(filter (fn [c] (#{ "New Jersey" } (:state c))) (-> (curl/get "") (json/parse-string true)))' | jet --pretty
Exception in thread "main" clojure.lang.EdnReader$ReaderException: java.lang.RuntimeException: Map literal must contain an even number of forms
	at clojure.lang.EdnReader.read(EdnReader.java:180)
	at clojure.lang.EdnReader.read(EdnReader.java:111)
	at clojure.edn$read.invokeStatic(edn.clj:35)
	at jet.formats$parse_edn.invokeStatic(formats.clj:29)
	at jet.main$_main$fn__2186.invoke(main.clj:106)
	at jet.main$_main.invokeStatic(main.clj:113)
	at jet.main$_main.doInvoke(main.clj:90)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at jet.main.main(Unknown Source)
Caused by: java.lang.RuntimeException: Map literal must contain an even number of forms
	at clojure.lang.Util.runtimeException(Util.java:221)
	at clojure.lang.EdnReader$MapReader.invoke(EdnReader.java:682)
	at clojure.lang.EdnReader.read(EdnReader.java:145)
	... 8 more
:~ $ bb  '(filter (fn [c] (#{ "New Jersey" } (:state c))) (-> (curl/get "") (json/parse-string true)))' | jet --pretty
({:state "New Jersey",
  :cases 1327,
  :todayCases 0,
  :deaths 16,
  :todayDeaths 0,
  :recovered 0,
  :active 1311})
:~ $ bb -o '(filter (fn [c] (#{ "New Jersey" } (:state c))) (-> (curl/get "") (json/parse-string true)))'
{:state New Jersey, :cases 1327, :todayCases 0, :deaths 16, :todayDeaths 0, :recovered 0, :active 1311}
:~ $

farenzer_house02:03:42

am i missing something here 🙂

farenzer_house02:03:51

but this seems specific to ‘new jersey’ and ‘new york’ (states with a space??)

farenzer_house02:03:53

:~ $ bb -o  '(filter (fn [c] (#{ "New Jersey" } (:state c))) (-> (curl/get "") (json/parse-string true)))' | jet --pretty
Exception in thread "main" clojure.lang.EdnReader$ReaderException: java.lang.RuntimeException: Map literal must contain an even number of forms
	at clojure.lang.EdnReader.read(EdnReader.java:180)
	at clojure.lang.EdnReader.read(EdnReader.java:111)
	at clojure.edn$read.invokeStatic(edn.clj:35)
	at jet.formats$parse_edn.invokeStatic(formats.clj:29)
	at jet.main$_main$fn__2186.invoke(main.clj:106)
	at jet.main$_main.invokeStatic(main.clj:113)
	at jet.main$_main.doInvoke(main.clj:90)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at jet.main.main(Unknown Source)
Caused by: java.lang.RuntimeException: Map literal must contain an even number of forms
	at clojure.lang.Util.runtimeException(Util.java:221)
	at clojure.lang.EdnReader$MapReader.invoke(EdnReader.java:682)
	at clojure.lang.EdnReader.read(EdnReader.java:145)
	... 8 more
:~ $ bb -o  '(filter (fn [c] (#{ "Arizona" } (:state c))) (-> (curl/get "") (json/parse-string true)))' | jet --pretty
{:state Arizona,
 :cases 104,
 :todayCases 0,
 :deaths 1,
 :todayDeaths 0,
 :recovered 1,
 :active 102}
:~ $

farenzer_house02:03:47

changing ‘new jersey’ to ‘arizona’ fixes it in this last case here ^

farenzer_house02:03:41

or removing the -o fixes it in that case

nate03:03:56

Maybe throw a pr-str in there so the data comes out as edn?

nate03:03:44

ah! or capitalize the option (`-O` instead of -o)

nate03:03:57

$ bb -O '(filter (fn [c] (#{ "New Jersey" } (:state c))) (-> (curl/get "") (json/parse-string true)))' | jet --pretty
{:state "New Jersey",
 :cases 1327,
 :todayCases 0,
 :deaths 16,
 :todayDeaths 0,
 :recovered 0,
 :active 1311}

farenzer_house03:03:59

Ahhhh thank you !!

borkdude10:03:23

@farenzer_house -o is for outputting text lines, -O is for outputting EDN lines. See this overview: https://github.com/borkdude/babashka/#input-and-output-flags

borkdude10:03:56

but you can also just use doseq + prn if you want 🙂

borkdude22:03:32

nrepl server kinda works 🙂

borkdude22:03:05

if you want to test, check out the nrepl-server branch or download a binary from #babashka_circleci_builds. report any rough edges to https://github.com/borkdude/babashka/issues/301

nate23:03:12

Wow. Very cool.

sogaiu23:03:13

some success with linux and monroe