OK, I recently found out this technique isn't more efficient that filter(), I must've made a mistake somewhere. Although there /are/ a few situations where this would be more efficient, like when you need to filter elements multiple times with different criteria, like splitting a list of objects based on what type they are putting one type in one list, another type in another list etc, but I think they are rare. This tip is about my new way of filtering lists of stuff. Since this technique has so many possible uses there's no possible way of putting em all on my functions object #111.

For our purposes we'll be pulling out the players from a list of dbrefs.

Until now, the usual way of doing this would either be to run it through filter() or to squish(iter(List,if(hastype(##,PLAYER),##))).
Recently I came up with a new way of doing this that could save quite a few function invocations with larger lists.
[elements(List,matchall(iter(List,hastype(##,PLAYER)),1))] Seems simple huh? When I first thought of this I was kicking myself for never thinking of it before, it seemed so simple, but then I've never seen anybody else use it before either.
This technique can be altered with a few more functions, to /remove/ the stuff instead of keeping it.
[elements(List,setdiff(lnum(1,words(List)),matchall(iter(List,hastype(##,PLAYER)),1),,n))]
Well for this particular example, I could of just changed the 1 to a 0 in matchall(), but if you were for example removing stuff that resulted in #-1, or in the case of conn(), -1 you'd need something like this.

Anyway, there it is, hardly worth the effort of making this webpage huh?, but I had nothing else to do while stuck in the dungeon cell. As with everything I code, I hope somebody finds it useful, even if it's just a cute toy.
Back