Open thareh opened 4 months ago
I think I would prefer if this wasn't allowed.
The "old" EachIn
using ObjectEnumerator
does this by basically casting each element to the type of the variable and then skipping over Null
s, had to do it this way because it couldn't know the type of the objects in the collection, but that also causes issues. IIterable
is an opportunity to improve things there.
One problem is that you can't properly use EachIn
on a collection that might actually have Null
s in it Some types like String
get special treatment, but that makes it even more confusing. Another problem is that it makes it easier to accidentally break your code: Imagine you have a TLinkedList<TBar>
and then at some point you change it to a TLinkedList<TFoo>
- if you you forget to change one of the For Local f:TBar = EachIn list
anywhere in your code, then that loop will now suddenly start skipping some elements, which is a pretty subtle, hard-to-find bug waiting to happen (it has happened to me before). I think it isn't not worth the risk, especially since it's not much harder to do something like
For Local f:TFoo = EachIn list
Local b:TBar = TBar(f)
If Not b Then Continue
Print b.name
Next
to replicate the ObjectEnumerator
behaviour explicitly.
Good day,
Would it be possible for EachIn to be able to convert objects from generics types when possible such as the code below?
Thanks!