-
Notifications
You must be signed in to change notification settings - Fork 54
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
initial POC for 'as' API addition #51
Conversation
I just reread:
is in the same vein of what i was thinking. |
@@ -8,6 +8,8 @@ trait ValueReader[A] { self => | |||
/** Reads the value at the path `path` in the Config */ | |||
def read(config: Config, path: String): A | |||
|
|||
def read(config : Config) : A = throw new Exception("bla") //TODO: FIX THIS EXCEPTION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difficulty of deciding what to do here is an indicator that it doesn't belong to this trait. A new trait (possibly inheriting this one) makes sense.
So, I updated this to use a separate trait. It's better than the first commit, for sure, but I'm still not super happy because:
Anyways I think this current impl is what was suggested in those previous comments I read. |
let's close this for now. we can reopen if anyone is interested in restart the work |
I had a longer than expected plane ride the other day, and decided to take a stab at #8 .
This PR is a more of a POC than an actual formal PR, to generate some discussion.
Codewise, there is not much to this, however the larger discussion is had the use case for this feature. The issue is that 99% of the (default) use cases don't need to read in multiple values from a Config object(and thus a path parameter makes sense), since its one field per value usually. However, case classes are the very large exception to that rule AND also one of this libraries greater conveniences, so there is a bit of a weird relationship going on there. They are a bit at odds with each other.
That being said, I still decided to go ahead with this POC, just to show what a potential fix could look like:
I added a new function to ValueReader
In an effort to not break compatibility, I opted to give it a default implementation of..throwing 🥇 🤕 🤒 . (which I totally do not like, but there really is no good default for this).
The
ArbitraryTypeReader
macro was updated to give an implementation to this new function, which allows it to take aConfig
object and directly pull values from it, without the need for the optionalpath
parameter.I updated some tests to make sure it all works, which so far seem to be a go.
So...outstanding issues:
ArbitraryTypeReader
s macro generate an impl for that. Then, theas
function on theFicusConfig
instance could match on theValueReader
type and throw if theValueReader
is not of that type. Not a 100% better, but at least a bit more obvious and not a throwing mess.getAs
function? If so, should the catching behavior catch the above mismatch, or is that something that should still be thrown? I lean towards having it throw if theValueReader
is not of the appropriate type, as this could mean a programming error, not a configuration error(potentially). I feel like either side could be argued successfully.