metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 204 forks source link

Fallback to use result of first branch when decoding :or and :orn #946

Closed ikitommi closed 10 months ago

ikitommi commented 10 months ago

from #910:

I see. Here's one repro:

(m/decode [:int {:decode/math str}] 1 (mt/transformer {:name :math})) ; => "1"
(m/decode [:and [:int {:decode/math str}]] 1 (mt/transformer {:name :math})) ; => "1"
(m/decode [:or [:int {:decode/math str}]] 1 (mt/transformer {:name :math})) ; => 1

so, options being:

  1. do nothing: it's a feature
  2. use first branch in case none is valid after decode
  3. use first branch where value is changed in decode

Not sure what is the most correct, 1 or 2 here 🤔

this PR implements option 2.

This is a BREAKING change as the behavior changes. But, I think the current implementation is wrong and this is (more) correct.