nubank / matcher-combinators

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

Add `indicates-match?` (and deprecate `core/match?`) #128

Closed dchelimsky closed 4 years ago

dchelimsky commented 4 years ago

There are currently 3 versions of match?:

core/match? receives a match result (map) while the others receive expected/actual values.

This PR eliminates the confusion by deprecating core/match? and replacing it with a new indicates-match? function.

This is not a breaking change, and will have almost no fan-out within Nubank.

fernando-nubank commented 4 years ago

I like this approach but indicates-match feels like a strange name =/

dchelimsky commented 4 years ago

I like this approach but indicates-match feels like a strange name =/

What do you suggest?

fernando-nubank commented 4 years ago

match? receives actual and expected and indicates-match? receives a match-result, so

; currently 
(indicates-match? (match? odd? 1)) ;=> true

;proposal
(matched? (match? odd? 1)) ;=> true

because match-result is the result of an already executed match?

rafaelzlisboa commented 4 years ago

@fernando-nubank I like the fact that indicates-match? reads very different from match?. I think we should move away from having different fns with very similar names (match, match? etc)

dchelimsky commented 4 years ago

I, personally, prefer indicates-match? over matched? for this reason:

matched? makes you think of an event that happened in the past: did it match back then when it happened?

indicates-match? says exactly what it means: does the thing you gave me indicate a match? It doesn't care how or when the thing got made.

fernando-nubank commented 4 years ago

@rafaelzlisboa I would like to have a single worded function, but you got a point. Let's keep it then

dchelimsky commented 4 years ago

I would like to have a single worded function,

Keep in mind that this is really for internal use, or in support of building custom matcher functions in other libs. It's not something people will type very much, if ever, but when they see it, they're very unlikely to confuse it with match? ;)