Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create speced/promise speced/promise-of #72

Open
vemv opened this issue Jul 9, 2019 · 2 comments
Open

Create speced/promise speced/promise-of #72

vemv opened this issue Jul 9, 2019 · 2 comments

Comments

@vemv
Copy link
Contributor

vemv commented Jul 9, 2019

Context

'Promise' return values are non-trivial to spec: derefing them on :post would make that defn blocking, defeating the purpose of promises

Task

Implement speced/promise (a promise replacement), plus speced/promise-of(a spec predicate)

Example:

(defn promise [spec]
  (let [p (clojure.core/promise)]
    (fn [deliverable]
      (assert (check! spec deliverable))
      (deliver p deliverable))))

(spec/valid? (speced/promise-of ::foo) (speced/promise ::foo)) ;; true

Acceptance criteria

  • Works analogously to clojure.core/promise
  • The resulting spec checking is meaningful / strong

Additional resources

https://github.com/nedap/postman-clj/pull/38

@thumbnail
Copy link
Member

Would promise-of block/defer the promise to check the result of the promise; or check whether the value is a speced/promise is passed and the spec matches.

If the latter; how would we determine the match?

(spec/def ::foo string?)
(spec/def ::bar (spec/and ::foo (complement (clojure.string/blank?)))

(spec/valid? (speced/promise-of ::foo) (speced/promise ::bar))

this should be valid, but on spec1 i'm not sure we can determine this 🤔 (spec2 might have possibilities)

@vemv
Copy link
Contributor Author

vemv commented Mar 15, 2020

or check whether the value is a speced/promise is passed and the spec matches.

the latter - the point of distinguishing between promise and promise-of is being able to check specs without blocking. Else we'd just have a unified promise API

i'm not sure we can determine this

Specs are a protocol:

https://github.com/clojure/spec.alpha/blob/5a4834eeb2967b2eca382efe0afcb3f590bdb3c2/src/main/clojure/clojure/spec/alpha.clj#L44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants