nubank / matcher-combinators

Library for creating matcher combinator to compare nested data structures
Other
467 stars 23 forks source link

Extra info for seq-of #208

Closed kdmoreira closed 1 year ago

kdmoreira commented 1 year ago

Matcher seq-of expects a non-empty sequence, but it wasn't clear from the docs.

dchelimsky commented 1 year ago

Thinking this through a bit more since first bringing it up: another possibility is to let it validate an empty sequence. That would align with Clojure's handling of sequences in general e.g. (map f []) ;; => ()

An argument against doing this is that it could lead to false positives.

WDYT?

dchelimsky commented 1 year ago

Thinking this through a bit more since first bringing it up: another possibility is to let it validate an empty sequence. That would align with Clojure's handling of sequences in general e.g. (map f []) ;; => ()

An argument against doing this is that it could lead to false positives.

WDYT?

Also:

> (every? odd? [])
true
philomates commented 1 year ago

I'd be up for doing a breaking change (4.0.0?) to fix this to be in-line with clojure's behavior

dchelimsky commented 1 year ago

We could also deprecate seq-of and add an every matcher to avoid a breaking change.

philomates commented 1 year ago

I kind of liked that we had these *-of matchers: any-of, all-of, and seq-of. If we rename seq-of to every, should we also rename any-of and all-of? If so do you have good name suggestions that consider https://github.com/nubank/matcher-combinators/pull/191#discussion_r1090881179 ? There is also the downside of shadowing clojure.core with every.