Fork me on GitHub
Felix Dorner11:07:31

With babashka/cli, trying to figure out a good way to :coerce: coerce string to given type. Can I add my own coercion "types"?

Felix Dorner11:07:12

And if I use :coerce [:type], is there a way to require a minimum argument of 1 element?


You can provide a function I think


Conclusions from a bit of experimentation: • You can add your own coercers as function on the toplevel or inside a vector • I can’t see an easy way to write a coercer that asserts that the collection needs at least one argument.

;; I can parse into a vector that takes a coercing function I've written myself
(babashka.cli/parse-opts ["--items" "one" "two"]
                         {:coerce {:items [(fn [item] (keyword "myns" item))]}})
;; => {:items [:myns/one :myns/two]}

;; With my own toplevel coercer, I just get a single value coerced
(babashka.cli/parse-opts ["--items" "one" "two"]
                         {:coerce {:items (fn [something] something)}})
;; => {:items "one"}
A possibility is to add your own validate function that asserts the things you need after parsing the CLI options,
(defn validate [opts]
  (assert (pos? (count (:items opts))))

(-> (babashka.cli/parse-opts ["--items" "one" "two"]
                             {:coerce {:items [(fn [item] (keyword "myns" item))]}})
;; => {:items [:myns/one :myns/two]}

(-> (babashka.cli/parse-opts ["--items"]
                             {:coerce {:items [(fn [item] (keyword "myns" item))]}})
;; => Execution error (ExceptionInfo) at babashka.cli/parse-opts$fn (cli.cljc:320).
;;    Coerce failure: cannot transform (implicit) true with easy_parallellism_with_pipeline_blocking$eval36639$fn__36640@4a1046de
After all, it’s data 🙂


nice, thanks for checking @U3X7174KS!

❤️ 1

Just checking in. What’s the current go-to method to deploy and write babshka or Clojure code on AWS Lambda? )


Last time I checked it was blambda. Is this still actual and project active?


#C04PSBFMMDJ is still active I think -- cc @U054AT6KT

gratitude-thank-you 1

I also recall holy-lambda was a contender, but never got to try it out. Any there any other entrants in this space?


there is also a babashka lambda layer on aws available, but I'm not sure if that's still up to date. I'm sure there's also "create your own" approach possible ;)

✔️ 1
zy C12:07:57

my method is just building a jar and upload to aws. Remember to use aws-lambda’s snapshot feat to reduce coldstart-time.


I think @U037WH7PKAT is referring to a normal AWS Java lambda


Yup, Blambda is still alive and I do watch the #C04PSBFMMDJ channel. 🙂

👍 1

Holy-lambda has commits in the last months. Never tried it, but it claims it can also do Clojure.


Holy Lambda is nice, and can do Babashka, JVM Clojure, and native image.