This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-30
Channels
- # bangalore-clj (1)
- # beginners (104)
- # boot (207)
- # cider (173)
- # cljs-dev (157)
- # cljsjs (1)
- # cljsrn (51)
- # clojure (196)
- # clojure-berlin (1)
- # clojure-chicago (1)
- # clojure-italy (4)
- # clojure-new-zealand (1)
- # clojure-nl (1)
- # clojure-russia (28)
- # clojure-spec (17)
- # clojure-uk (73)
- # clojured (13)
- # clojurescript (110)
- # core-async (4)
- # datascript (25)
- # datomic (92)
- # editors (1)
- # emacs (157)
- # events (4)
- # hoplon (16)
- # klipse (74)
- # lein-figwheel (10)
- # leiningen (2)
- # lumo (13)
- # off-topic (78)
- # om (3)
- # om-next (3)
- # onyx (14)
- # protorepl (1)
- # re-frame (17)
- # reagent (23)
- # remote-jobs (1)
- # ring-swagger (33)
- # schema (2)
- # slack-help (3)
- # spacemacs (7)
- # testing (1)
- # yada (7)
Is there a good way to generate an increasing number as id in a variable-length collection?
now if i generate subsegments, how would I get the first one to have the ::id 1, the second one (if there is one) the ::id 2, and the third one (if there is one) the ::id 3 ?
you can’t make that happen automatically, but you could build a generator that did that
I would create a custom generator for ::subsegments
using gen/fmap
- use the default generator to create, then in the fmap function replace the ::id
values to have the index
I'll give that a shot @alexmiller .
How would you keep the index state? There doesn't seem to be a fmap-with-index, nor a multi-arity version where I could pass in a range or something and zip them together
Yeah, you can just map over the generated value and range
Is there a way to spec a mapargs fn? for example:
(defn foo [& {:keys [bar]}] bar)
(foo :bar "value of bar")
(s/def ::bar string?)
(s/def ::baz int?)
(s/def ::mapargs (s/keys* :req-un [::bar ::baz]))
(defn foo [& {:keys [bar baz]}] bar)
(s/fdef foo :args ::mapargs)
(stest/instrument `foo)
(foo :bar "value of bar" :baz 42)
@jr@joshjones wow that's great. thanks!
I didn't realize that keys*
is different in that it transforms a sequence of values into a map