clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
Joe 2020-04-18T12:23:57.144100Z

Is this the correct way to spec a non-empty collection?

(s/def ::things (s/coll-of ::thing :min-count 1))

shooit 2020-04-18T13:34:19.148800Z

That would do it. The other thing that some to mind is from the sequential specs: s/+. It depends on context which is preferred. Just a non-empty collection of things? Your s/coll-of solution is it. A non-empty sequence of things as part of a larger pattern? Look to the sequential specs for their regex like functionality.

πŸ‘ 1
prnc 2020-04-18T17:32:15.154700Z

Spec rationale quote I’m pondering > Invariably, people will try to use a specification system to detail implementation decisions, but they do so to their detriment. The best and most useful specs (and interfaces) are related to purely information aspects. https://clojure.org/about/spec#_informational_vs_implementational Trying to get clear on the distinction β€” what would be the canonical example of the offending type of use and how far you can push the boundary so to speak? Is this mostly about trying to enforce implementation a la types (an thus cussedness/rigidity etc.) ?

alexmiller 2020-04-18T18:00:21.155100Z

Clojure core functions are a good example

alexmiller 2020-04-18T18:01:58.157500Z

You can spec a function as talking PersistentVector (bad, concrete, may change) or as satisfying vector? or seq? or coll? or sequential? (depends on the fn of course)

πŸ™ 1
alexmiller 2020-04-18T18:02:54.158700Z

And it’s common to try to spec what exactly it does now vs leaving open for future