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

[Feature Request] Add extensions for Possibly* types #511

Closed
y9san9 opened this issue Dec 17, 2021 · 1 comment · Fixed by #524
Closed

[Feature Request] Add extensions for Possibly* types #511

y9san9 opened this issue Dec 17, 2021 · 1 comment · Fixed by #524

Comments

@y9san9
Copy link
Collaborator

y9san9 commented Dec 17, 2021

In general, the idea is to add extensions with nullable values for Possibly* types.

For example, it would be nice to write val user: User? = message.user instead of val user: User? = message.asFromUser().user.

When there will be a subtype with user member in a code, the extension will be just ignored.
There is an another way, to make this without extensions, just using member functions/properties. It may be better since the highlighting works faster for member functions. And they do not require imports.

So the functions like as... may become less useful and may be even removed in the future.

This allows users to use two patterns for this cases: fast access to nullable properties whenever the user needs it, and the old good one way - strong types with not null properties.

I saw that the unability to use the first way leads newbies to migrate to libraries like kotlin-telegram-bot where this way is the only one available, but when theirs bots become a bit complex, they have to migrate again to this lib in case they want to avoid nulls.

@InsanusMokrassar
Copy link
Owner

InsanusMokrassar commented Jan 6, 2022

@InsanusMokrassar InsanusMokrassar linked a pull request Jan 6, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants