37

Journal 2019.11 - spec/select, clj jiras, tools.deps

 1年前 阅读数 37
以下为 快照 页面,建议前往来源网站查看,会有更好的阅读体验。
原文链接: https://www.tuicool.com/articles/hit/yiIRj2R

spec/select

I spent most of the week on spec/select and committed the first version of it. The idea with s/select is to separate the set of attributes allowed in a map from which ones are required in a given context - see Maybe Not . In the talk, Rich uses s/schema to declare the keyset but that is still in flux, so you can currently use either an s/keys spec or a vector of attrs to declare the keyset.

(require '[clojure.spec-alpha2 :as s] 
         '[clojure.spec-alpha2.gen :as gen])

(s/def ::street string?)
(s/def ::city string?)
(s/def ::state string?) ;; for demo
(s/def ::zip int?)      ;; for demo
(s/def ::addr (s/keys :opt [::street ::city ::state ::zip]))

(s/def ::id int?)
(s/def ::first string?)
(s/def ::last string?)
(s/def ::user (s/keys :opt [::id ::first ::last ::addr]))

;; (s/select keyset selection)
;; The selection pattern is a vector of either keywords for 
;; required attrs or maps of optional attrs to a selection pattern
;; to use in a submap.
(s/valid? (s/select ::user [::id ::addr {::addr [::zip]}]) 
          {::id 100 ::addr {::zip 63011}})
;;=> true

;; And it gens, using all the optional sub-parts, but ensures all
;; the required selected paths
(gen/sample (s/gen (s/select ::user [::id ::addr {::addr [::zip]}])))
;;=> (#:user{:last "", :id 0, :addr #:user{:city "", :zip -1}}
;;    #:user{:last "", :id 0, :addr #:user{:zip 0}}
;;    #:user{:first "ie", :id -2, :addr #:user{:city "", :zip -1}}
;;    #:user{:last "uS", :id -1, :addr #:user{:city "9G2", :zip -4}}
;;    #:user{:id -2, :addr #:user{:zip -2}}
;;    #:user{:last "i0T97", :first "", :id -3, 
;;           :addr #:user{:street "88", :city "joOc", :zip 1}}
;;    ...)

You can reuse the same keyset but select different paths (and get different gen and conform):

(gen/sample
  (s/gen
    (s/select ::user [::first ::last ::addr
                      {::addr [::street ::city ::state ::zip]}])))
;;=> (#:user{:id -1, :first "", :last "",
;;           :addr #:user{:city "", :street "", :state "", :zip -1}}
;;    #:user{:id 0, :first "", :last "",
;;           :addr #:user{:city "", :street "C", :state "x", :zip 0}}
;;    #:user{:first "vU", :last "",
;;           :addr #:user{:city "", :street "0", :state "d", :zip 1}}
;;    ... )

select can also take a vector of possible keys (as a keyspec):

(gen/sample (s/gen (s/select [::first ::last] [])))
;;=> (#:user{:last ""}
;;    #:user{:last "", :first "J"}
;;    {}
;;    #:user{:first "p"}
;;    #:user{:first "a9", :last "0"} ...)

Note that this spec has no required keys (the second vector), so may be empty, or have :first, :last, or both.

And the vector keyspec can provide inline specs for unqualified keys:

(gen/sample (s/gen (s/select [{:a int? :b string?}] [])))
;;=> ({} {:a -1} {:a 1, :b "f"} {:a 1, :b "5j9"} ...)

THIS SYNTAX AND MANY DETAILS IS ALL A WORK IN PROGRESS. It will change, don’t get stuck on it.

Clojure jiras

Stu screened the two jiras I’ve discussed in prior journals, CLJ-2484 (the Java performance regression when loading user.clj) and CLJ-2463 (improving error printing for the clojure.main runner). Rich will look at them next. Still moving towards a 1.10.1 RC with these.

tools.deps

A number of people installed and tested clj on Windows this week. Some known issues to work through and seems to be a lot of ways people like to install things. Try it if you haven’t!

I spent some time this week on TDEPS-74 (and related TDEPS-106) for fixing issues around using relative paths in local deps, and I committed some changes for that. Also going to look at the proxy support ticket TDEPS-20 and get all this stuff released.

It also came to my attention that the newest versions of jgit have greatly expanded support for ssh keys and other things via Apache MINA which would potentially resolve several issues we’ve seen in ssh git deps. Hoping to take a look at that soon.

Other stuff I enjoyed this week…

This time of year, my heart is in one place - the SXSW music festival in Austin. My parents lived there for about 15 years and I started going to SXSW in 1996. I went almost every year for a number of years and last attended in 2007 (and brought my 1 and 2 year olds along at the time!). I know Austin has changed a lot in the decade since, and SXSW too I have no doubt, but I’m going to choose to believe that the spirit of serendipity and love of music continues to thrive there.

Literally the first music I saw at the first SXSW I went to was an Iggy Pop show, on a stage in the middle of 6th St. Amazing. Back when I was attending regularly, one of my favorite venues was the Steamboat (long gone) where I discovered local Austin bands I loved for years, like Sister 7 (nee Little Sister), Vallejo, and Pushmonkey. I spent many magical sxsw nights there with my closest friends seeing great shows. I’ll be throwing back a Shiner Bock this weekend to these and dozens more memories of those times.

Here’s a good video of Vallejo doing House at the Steamboat in 1996. I’m pretty sure when we saw them in 1996 at sxsw they were at the Ritz (name changed many times since then, not sure what it is now). Never in my life have I seen a band hit the stage with so much energy. It was like walking into a tornado. Instantly hooked. I saw them more times than I could count - every SXSW but also many other times in Austin and other cities. Me and a good buddy saw them in Cincinnati once on a frigid winter night and we were literally the only people in the place, but they did an incredible gig anyways.


猜你喜欢

  • 0

    Journal 2019.24 - spec and-, tools.deps.graph I’ve fallen off the pace on these journals but here’s an update! Spec 2 Most fresh in my head is some ongoing work on Spec 2. This week I added s/and-...

  • 1

    Journal 2019.7 - jdk regression, spec, sets, tools.deps JDK regression There was a rash of reports this week about significant startup time slowdowns after switching to the latest version of Java 8 and 11. I tr...

  • 2

    Clojure 1.10 Kicked the week off with a bang, releasing Clojure 1.10. We do small Clojure releases all the time and with every release there are a bunch of mundane tasks -...

  • 2

    Journal 2019.25 - dep graphs, s3 transporter, spec 2 Probably the last update of the year. I had hoped to do it this weekly in 2019. That didn’t quite happen but since this is the 25th update of the year, I average about...

  • 0
    • insideclojure.org 1个月前
    • 快照

    Journal 2019.16 - closed spec checking

    Closed spec checking As I mentioned last week, I’ve been working on adding a new form of closed spec checking and that’s in master for spec 2 now, or at least the first cut of it. The idea is that you can mark one or more (or all) s...

  • 0

    Journal 2019.9 - jdk regression, clojure.main, spec JDK regression Following up on this from last week, I had the idea that maybe moving all of the cod...

  • 0
    • insideclojure.org 1个月前
    • 快照

    Journal 2019.14 - schema and select

    Journal 2019.14 - schema and select Spec schema and select This week was spent on some additional updates to the schema/select stuff from last week. The

  • 1
    • insideclojure.org 1个月前
    • 快照

    Journal 2019.13 - schema and select

    Journal 2019.13 - schema and select Spec schema and select I spent the bulk of the week this week focused on implementing schema support and modifying s/select in spec-alpha2. Rather than leave long-winded stuf...

  • 35

    Spec 2 - closed spec checking redo I’ve mostly been doing spec 2 work in the last couple weeks. I finally completed the closed check rewrite that I started a while back. When Ilast visited closed spec checking,...

  • 93

    <p>In the Java/Maven ecosystem there are many repositories that publish JARs publicly. This is an up-to-date list of the ones that you are likely to encounter.</p> <p></p>

关于极客头条


聚合每日国内外有价值,有趣的链接。

AD