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

Partial decoding using Regex/Seqexp #387

Open
arunvickram opened this issue Mar 8, 2021 · 5 comments
Open

Partial decoding using Regex/Seqexp #387

arunvickram opened this issue Mar 8, 2021 · 5 comments

Comments

@arunvickram
Copy link

Right now the implementation of :catn has it so that the following example doesn't decode "1.0" if TestEnum fails:

(ns sample.core 
  (:require [malli.core :as m]
            [malli.transform :as mt]))
​
(def GreaterThanZero
	[:fn {:decode/string mt/-string->double}
	 '#(> % 0)])
​
(def TestEnum
	[:enum "A" "B"])
​
(m/decode
 [:catn 
  [:amount GreaterThanZero]
  [:layout TestEnum]]
 ["1.0" "U"]
 mt/string-transformer) ; => ["1.0" "U"]

I was wondering if there were any plans to support partial decoding?

@nilern
Copy link
Contributor

nilern commented Mar 10, 2021

This might be hard (or not). IMHO we should not make any guarantees about how (partially) invalid input is decoded. (Ceterum censeo, it should produce an error but that is not on the roadmap.)

@arunvickram
Copy link
Author

Sorry for the long delay, I've been flooded with work. I'm not sure why this would be difficult, but perhaps I'm missing some context on how decoders work?

@nilern
Copy link
Contributor

nilern commented Mar 25, 2021

We would have to keep the longest partial decoding around and then return that if the full sequence cannot be decoded. Maybe not super difficult but definitely additional complexity and reduced performance and usually the input has (or should have) been validated beforehand anyway. I would rather have #404.

@arunvickram
Copy link
Author

Either way works, in fact a coercer may even be better because at the end of the day, I'm getting stringified data and I'd like to be able to get the correct error reported for fn schemas and schemas with custom errors.

@nilern
Copy link
Contributor

nilern commented Mar 25, 2021

Ah I might have it the wrong way around, in that case you would first decode and then validate... still I think the coercer would be more optimal. Either way quite a bit of work to improve the errors.

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

2 participants