Skip to content

What’s the best way to map a String to a wrapper type in Scala, where optionality is inferred from the target type? #754

Answered by MateuszKubuszok
YannMoisan asked this question in Q&A
Discussion options

You must be logged in to vote

I'm afraid not: most of the time I've met the requirement that validation for errors and optionality are orthogonal concepts:

  • if data is invalid, fail transformation
  • if it's optional but missing, make it succeed with None

Here it's contextual mixing of the two:

  • if transformation fails validation, it should fail the whole transformation when it's a non-optional value
  • but error should be silently discarded when it's an option.

It might be perfectly reasonable in a particular case, but it screams "extraordinary" and it has to be handled as such. In the past any "silent failures" in Chimney were reported as bugs by the community, so I believe the current approach (where one needs to defin…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by YannMoisan
Comment options

You must be logged in to vote
2 replies
@MateuszKubuszok
Comment options

@YannMoisan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants