Runtime specified filtered for loops
|
|
Redundant
|
Status: |
Redundant
This feature has already been implemented, or is already achievable with existing methods.
|
|
|
There are some optimizations in filtered loops that you can't match with soft code, in particular loops over the world, or view, and some other such special "lists". However the filter of a for loop can only be specified at compile time, some usecases need to be able to filter what they loop over at runtime, like say mob ai looking for various objects around them. It would be a good optimization if we could make use of the faster filtered for loops in these cases instead of having to write our own filter checks inside unfiltered loops.
So instead of
var/search_type = /mob/tasty_critter //[...] for(var/atom/thing in view()) if(!istype(thing, search_type)) continue //[do stuff to found target]
You'd write something like
var/search_type = /mob/tasty_critter //[...] for(var/atom/thing as search_type in view()) //[do stuff to found target]
Or another usecase that would be nice would be filtering for multiple types at once.
var/search_types = list(/mob/tasty_critter, /obj/tasty_snack) //[...] for(var/atom/thing as search_types in view()) //[do stuff to found target]
|