-
Notifications
You must be signed in to change notification settings - Fork 61
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
Missing empty constructors #140
Comments
Could you please elaborate on why you need a separate implementation though? |
I can think quickly on 3 reasons:
Actually, I would be interested in reading your thoughts on which approach would you take and which advantages? Problably there is something really nice that I'm missing or could be improved on my side. |
I second what is said in 3. As a new user of this library, the first thing I intuitively typed when I wanted to create an empty immutable list was "empty", as in stdlib collections. When no completions appeared, I had to find (and subscribe to) this issue to actually discover how to properly create an empty list. |
I think @qwwdfsad's point is that the impl could be simply fun <T> emptyImmutableList(): ImmutableList<T> = EmptyImmutableList
internal val EmptyImmutableList = persistentListOf() unless that's what you say in 2. which I don't really understand. But here's another thing: It's possible that in the future (about that of valhalla) persistent collections will be made |
What I meant with point 2, is that I will loose the type, in case I had something mutable passed, similar to what we have in the val emptyMutableList: ImmutableList<String> = emptyImmutableList()
val emptyMutableList2: ImmutableList<String> = persistentListOf()
val testA = (emptyMutableList as? PersistentList) // null
val testB = (emptyMutableList2 as? PersistentList) // Persistant, or SmthVector, I think I think then that your suggestion in on point, cause unlike the old traditional lists, I could do a successful cast to So, about in the future, I wasn't aware of the migration to Anyway, I think we can go with EDIT: about 3/4, btw, I still think is what a lot of people like me will try to find before having to understand the mechanism behind this, I'm fine with switching back, but maybe something to consider for the new people jumping on the topic to ease the learning process. |
I'm neither, I only expect this may be sensible to do, at least for some classes like As to point 2. yes, it will be safe, even more than stdlib, as all implementations are immutable. Even if they weren't they are The problem of discoverability remains though, so it may be sensible to have |
Ok then I will keep my original suggestion, because 1st. if it is not know if the value is happening or not, I was assuming this was a fact, then creating instances won't be ideal, second, not all the implementations of |
Can we have something like:
The text was updated successfully, but these errors were encountered: