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

Pattern matching with https://github.com/HealthSamurai/matcho #2

Closed
matthewdowney opened this issue Dec 9, 2022 · 1 comment

Comments

@matthewdowney
Copy link
Owner

It'd be cool to be able to do pattern matching with https://github.com/HealthSamurai/matcho instead of just comparing for literal equality.

The two main use cases I have in mind are partial matches and predicates:

(comment
  ; The return value is a map containing {:foo :bar}
  (let [big-map (apply assoc {} (repeatedly 10 rand))]
    (assoc big-map :foo :bar))
  ;=> {:foo :bar ...}

  (require 'clojure.spec.alpha :as s)

  (let [http-response-body (slurp "http://example.com")]
    {:status  200
     :body    http-response-body
     :headers {"foo" "bar"}})
  ;=> {:status  200
  ;    :body    string?
  ;    :headers (s/map-of string? string?)}
  )
@matthewdowney
Copy link
Owner Author

For the record, as implemented, matcho assertions must follow =>> instead of the original =>, which remains an assertion of literal equality.

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

No branches or pull requests

1 participant