Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TODO:
@see
section of the flags methodsATM I am leaning towards adding this flag in 1.0.0. However, I am against enabling it by default:
The issue only arises when one uses Chimney as a compile time proof that some transformation is valid. This is WRONG. Chimney is only able to prove that there exists a path of a least resistance converting value of one type into another.
If the input type is
String
but the output expects non-emptyString
- without making it explicitly a distinct type with a smart constructor (e.g.NonEmptyString
from Refined/Iron/etc) compile-time logic would not be able to validate that. Same withInt
s and non-negativeInt
s, checking regexps, etc. If types are the same, then anything more than passing the value unchanged can only be verified by runtime tests. Basically, by defaultA => A
conversion always succeeds for everyA
.Option
, most of the time, is a replacement for nullable values. In a world whennull
is not supposed to be a thing, verifying that nullable has to be different than null to make it non-nullable is rather obvious and expected outcome. Requiring explicitOption[A] => A
(orOption[A] => B
) parsing is rather non-standard.And that's the problem: handling empty
Option
s is a primary reason users try to usePartialTransformer
s. It is the main use case that advertised the feature on landing page, half the documentation examples, it lowers the barrier to entry for everyone who uses Chimney to decode JSONs or Protobufs into domain models. Disabling it by default would be discouraging as suddenly 90% of use cases would require additional flag. I would stop using Partials myself if I had to do this every time.If the code performs any sort of validation
PartialTransformer
s helps write that logic - but that logic would inevitably have branches depending on runtime data, and as such Chimney was, is, and will be only removing the boilerplate in the production code, tests still have to be written and run. (For similar reasons I still write JSON roundtrip tests even if I derive codecs with Circe, Play JSON, Jsoniter or whatever - the fact that I used derivation doesn't remove the need to write tests, and writing tests don't undermine usability of code generators).If one intends to make
Option[A] => A
"type-safe", I suggest:A
withopaque type
orNewType
then types would enforce a manual intervention.