I have it sooo often that I have to unwrap inline ...
# language-proposals
m
I have it sooo often that I have to unwrap inline classes, do some basic operation and then wrap it again. That’s quite annoying and you can change the result to a different inline class without even noticing.
m
I realize this is fabricated, so my response may not be generally applicable. Why aren’t you defining a
toLowerCase
function on the UserName object. I know it’s more work BUT it provides the required safety as it’s unlikely you’d cross inline classes. But I do agree that inline class is very powerful, but currently, quite cumbersome to use.
m
I do for now but it has some downsides: • You have to do it for plenty of inline classes, leading to a lot of redundant code. • You can’t possibly know what functions of the wrapped object consumers of your inline class actually want to use. They may want to use
toUpperCase()
or maybe the variant with a locale or maybe
trim()
or whatever.
m
Ok. We’re on same page. You’re solving it the same way I would, BUT we both agree it’s very cumbersome to work with inline classes right now. It would be nice if the inline class would delegate function calls to the wrapped and somehow return a newly wrapped class, so any proposal that gets us closer to that is good to me.
m
Yes, exactly! But shouldn’t happen automatically for all inline classes since in some cases you may see the wrapped type as an implementation detail while not in other cases.