Tiddlywiki5: [IDEA] Consider extending filter run prefixes

Created on 9 Oct 2020  路  5Comments  路  Source: Jermolene/TiddlyWiki5

Should we extend the filter run prefixes with one that behaves similar to the new filter filter operator?

I've been running a couple of custom extensions to the filter run prefixes (=, - , + , ~ ) that add convenience, one of which : behaves as the new filter operator does. However using a filter run prefix allows for more brevity in inline code.

I realize the balance between utility and not wishing to inflate the core size, therefore this is posted as an issue and not a PR. I do have working code though it might need to be reviewed from the point of view of performance.

The following would be equivalent:

\define larger-than-1k() [get[text]length[]compare:integer:gteq[1000]]

{{{ [tag[HelloThere]filter<larger-than-1k>] }}}

and

{{{ [tag[HelloThere]] :[get[text]length[]compare:integer:gteq[1000]] }}}

An excerpt of the relevant part of the code:

case ":":
    return function(results,source,widget) {
        if(results.length > 0) {
            var toRemove = [];
            $tw.utils.each(results,function(result) {
                var filtered = operationSubFunction(self.makeTiddlerIterator([result]),widget);
                if(filtered.length === 0) {
                    toRemove.push(result);
                }
            });
            $tw.utils.removeArrayEntries(results,toRemove);
        }
    }

Are there any performance considerations to be take into account with this approach?

Most helpful comment

Hi @saqimtiaz apologies for the delay. That's a very interesting idea. We do face a challenge that there is a diminishing pool of single character symbols available. I wonder if we might use the : prefix to introduce named prefixes. For example:

{{{ [tag[HelloThere]] :filter[get[text]length[]compare:integer:gteq[1000]] }}}

We would establish a new module type, mapping the existing prefixes so that = is equivalent to :all, - to :remove etc.

All 5 comments

Hi @saqimtiaz apologies for the delay. That's a very interesting idea. We do face a challenge that there is a diminishing pool of single character symbols available. I wonder if we might use the : prefix to introduce named prefixes. For example:

{{{ [tag[HelloThere]] :filter[get[text]length[]compare:integer:gteq[1000]] }}}

We would establish a new module type, mapping the existing prefixes so that = is equivalent to :all, - to :remove etc.

@Jermolene I like the idea of named prefixes a lot!

I've already run into the issue of running out of characters to use; I use ; prefix for an equivalent to the then filter except it allows you to use an inline filter.

:filter or :then are much easier to read and understand. Furthermore making this a module type would make it extensible via plugins.

@Jermolene A quick pass at refactoring the existing filter run prefixes into a new module-type needs review and feedback at #4915

@saqimtiaz ... can this one be closed? The implementation is merged.

@pmario Not yet. The refactoring is merged for implementing the filter run prefixes as a new module-type.

I still need to make a PR for the new :filter prefix that this issue is actually about.
I wanted to refactor existing functionality before adding anything new to reduce chances of any complications.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joshuafontany picture joshuafontany  路  34Comments

pmario picture pmario  路  30Comments

inmysocks picture inmysocks  路  34Comments

Jermolene picture Jermolene  路  42Comments

twMat picture twMat  路  33Comments