Fork me on GitHub
#clojure
<
2018-06-18
>
valerauko13:06:22

How am I supposed to spec (with spec.alpha) XML endpoints on a Reitit API?

ikitommi14:06:18

@UAEH11THP if you figure out how to spec XML, I can try to cook up an example how to integrate it to reitit.

ikitommi14:06:18

Haven’t specced XML, #clojure-spec might help with that.

valerauko14:06:49

I've found some Stack Overflow responses about Swagger specs for XML

jerger_at_dda15:06:02

Is there a predicate to distinguish set or hashsets from other kind of sequences ?

noisesmith15:06:02

user=> (set? #{})
true

jerger_at_dda15:06:47

jupp works 🙂

jerger_at_dda15:06:43

looked at the wrong place in https://clojure.org/api/cheatsheet ... thanx

noisesmith15:06:36

clojure.repl which is used for you by default has a few useful functions for finding things: apropos which can find things by regex or substring of name and find-doc which finds things by regex or substring of their documentation

noisesmith15:06:42

user=> (apropos "set")
(clojure.core/-reset-methods clojure.core/aset clojure.core/aset-boolean clojure.core/aset-byte clojure.core/aset-char clojure.core/aset-double clojure.core/aset-float clojure.core/aset-int clojure.core/aset-long clojure.core/aset-short clojure.core/bit-set clojure.core/compare-and-set! clojure.core/hash-set clojure.core/ref-set clojure.core/reset! clojure.core/reset-meta! clojure.core/reset-vals! clojure.core/resultset-seq clojure.core/set clojure.core/set-agent-send-executor! clojure.core/set-agent-send-off-executor! clojure.core/set-error-handler! clojure.core/set-error-mode! clojure.core/set-validator! clojure.core/set? clojure.core/sorted-set clojure.core/sorted-set-by clojure.core/var-set clojure.core/vreset! clojure.pprint/set-pprint-dispatch clojure.repl/set-break-handler! clojure.spec.gen.alpha/set)
- it's a lot, but set? is in there

noisesmith15:06:26

and there's also doc of course

user=> (doc set?)
-------------------------
clojure.core/set?
([x])
  Returns true if x implements IPersistentSet
nil

noisesmith15:06:09

it would be cool to see the doc strings fixed up so that find-doc would be more likely to find the right thing for the intuitive query (eg. if #"predicate.*set" matched that doc string)

jerger_at_dda15:06:44

yea I know these, unfortunately I expected the set? predicate in the clojure.set namespace ... so I read in the wrong direction ...

benzap16:06:51

associative?

benzap16:06:19

nvm, that is way off

danlebrero15:06:09

FYI, if you are using the compression ns of https://github.com/Raynes/fs be aware that it suffers the Zip Slip vulnerability https://snyk.io/research/zip-slip-vulnerability. We released a patched version under https://clojars.org/akvo/fs

💯 12
hlship21:06:12

Is it possible to with-redefs-fn a private Var? I'm trying to mock up the underpinnings of io.pedestal.log/error in a test:

(deftest go-resolve-expr-throws
  (let [*keyvals (atom nil)
        log-expr (ns-resolve (find-ns 'io.pedestal.log) 'log-expr)]
    (with-redefs-fn {log-expr (fn [_ _ kvs]
                                (swap! *keyvals conj (apply array-map kvs)))}
      (fn []
        (is (= [nil {:errors [{:message "Exception in expr"}]}]
               (result-value
                 (go-resolve _
                   (throw (ex-info "Exception in expr" {}))))))

        (is (= []
               @*keyvals))))))
But my test runs as if the redef is not in place. Thoughts?

delaguardo04:06:08

Try to use fully qualified var name - (with-redefs-fn {io.pedestal.log/log-expr ...

hlship16:06:26

Does not work with a private var.

arohner21:06:28

I need to design a complicated feature. It’s a webapp that needs to collect a bunch of forms from a user, and save them to a DB. The trouble is, there are a bunch of forms, there’s a workflow for determining which forms to collect from the user, and the workflow will change over time, so I’d like the UI, the backend service and the DB to be driven from the same workflow/ruleset. Are there any good blog posts / talks / libraries for dealing with that problem?

myguidingstar06:06:35

Fulcro (a battery-included fork of om.next) can be a good building block for your problem. It provides a full-stack framework (or in your words: workflow/ruleset) so you won't be overwhelmed by too many decisions to make. Its data driven nature of the whole system (client side db, server-client communication) keeps your app flexible at the same time. Subsystems are pretty independent hence easy to refactor. It takes time to learn, though http://book.fulcrologic.com

sundarj07:06:12

haven't used either of these myself (yet), but perhaps using a rules engine would serve your purposes? https://github.com/cerner/clara-rules https://github.com/CoNarrative/precept

hiredman22:06:50

sounds like it might a be a good fit for some kind of finite state machine or finite state transducer

hiredman22:06:19

I don't have a go to library for that. in the past I have created a defrecord to hold the parts of a fst (https://en.wikipedia.org/wiki/Finite-state_transducer shows it as a 6-tuple), and then gone from there, accumulating little helper functions for things like adding state transitions to a machine, and querying the machine for which states can receive certain events. macros for closed dispatch over machine states and outputs (because the machine is a effectively a compile time constant macros can use it to validate things).

👍 8
dadair22:06:21

@arohner @yogthos has a blogpost describing (if I’m understanding correctly) something like that here https://yogthos.net/posts/2016-09-25-ReagentComponents.html

arohner22:06:47

Thanks! This is interesting, and part of the problem, but not the whole thing. I have a workflow that says “The user needs to fill in form A, or form B. If check box ‘foo’ on form B is checked, they also need to fill out form C, etc. I would like that workflow to be 1) obviously laid out in one place. 2) kept in sync between browser and backend, so both sides agree on which forms need to be gathered

arohner22:06:20

and for extra fun, some forms are only necessary if a backend server calculation says so

hiredman22:06:43

depending on how you represent a state machine, you can get very abstract. each state is a set of required form names, inputs sets of completed and validated form names

arohner22:06:47

huh, I hadn’t thought of just using a pure state machine, interesting.

cddr22:06:47

Nice! And bundles of rules can be composed as data and switched in as required.

arohner23:06:44

As usual, @ztellman has already solved the problem https://github.com/ztellman/automat

lilactown23:06:29

holy crap that’s a cool library

hiredman23:06:04

I haven't actually found automat to be super useful for state machines. automat seems to be all about compiling a state machine for accepting a sequence of events as something that runs really fast, which is cool, but for how I have used state machines in the past, the running time of transitions of the state machine aren't so important, the ability to query the machine about states and assert that certain states accept similar inputs, and really manipulating the fsm as an object versus "running" it has been much more important

12