noprompt / meander

Tools for transparent data transformation
MIT License
918 stars 55 forks source link

"N or More" operator matches on empty list in m/search when N is nonzero #228

Open sergey-latacora opened 2 years ago

sergey-latacora commented 2 years ago

When using the n or more operator to match a pattern in a vec with a preceding any (_) operator; the n-or-more operator will match empty lists in m/search. This behavior is different from from m/match, which will not match on empty lists.

Code snippet for reproducing:

(comment
  (require '[meander.epsilon :as m])
  (m/match
    []
    [_ ..2] :matched-two-or-more
    _ :didnt-mach)
  ;; => :didnt-mach ;; this is expected, there are no items in the input vec
  (m/search
    []
    [_ ..2] :matched-two-or-more)
  ;; => (:matched-two-or-more) ;; the vec is empty, so this should be nil, but the expression returns :matched-two-or-more
  )

See brief discussion in clojurians slack for a bit more context.