Filter vs subfilter operators

Hi All,

Try as I might, I have been unable to comprehensively understand the difference between the filter operator and the subfilter operator. I’m sure there is a difference and maybe it’s just the way I’ve been using them, but I’m just not getting it. Could someone help explain the difference(s)?

Much appreciated.

1 Like

I like to think that the subfilter does what I would expect a filter to do, and filter does what I would expect a subfilter to do. :grin:

The subfillter filter operator allows you to use a filter defined outside the filter expression as if it were part of the expression. It continues the existing filter run, and it’s output is added to the output just like a regular filter operator.

A filter filter operator makes a decision about what items in the current title list will be kept, and which will be discarded. For instance, you might have a series of tiddlers that represent employees, with a list fields for hours worked every day of the week. Your filter might add up all the hours for each employee and compare with 32. If less, it lets them through. If more, it doesn’t. The numerical results (the calculations) are not passed on.

Yes. The fitler operator discards the result of the subfilter and returns the input title. The subfilter operator returns the results of the subfilter.

To use the descriptions from the tiddlywiki.com docs:

  • Filter operator: purpose: apply a subfilter to each input title and return the titles that return a non-empty result from the subfilter

  • Subfilter operator: output: the selection of titles returned from the subfilter S

If it helps the filter operator and filter run methods only came to tiddlywiki recently, the subfilter operator was around a lot longer.

In a recent reply I demonstrated the subfilter use, see here Keeping track of fields. What are best practises? - #14 by TW_Tones in this case following a list of titles rule out -[subfilter<subfiltername>] or rule in +[subfilter<subfiltername>]

As a result, I now tend to use them according to both their features but also if they sound right in English. Eg subfilter is more of a subset, where filter is a set.

I’m still not clear. Here’s an experiement from my railroad TW.

<$let filt="[statefiled[Nebraska]]">
  <$list filter="[tag[Railroads]subfilter<filt>]">
    <$link><$view field="title"/></$link><br>
  </$list>
</$let>

The filter will only return those railroads chartered in the state of Nebraska. If I replace the subfilter operator with the filter operator, I get the exact same results. I also get the same results with:

[tag[Railroads]] :filter[statefiled[Nebrasaka]]

So far, this is the only way I’ve used them, so maybe I am not using them in a way that highlights their differences.

Still clueless…

Your variable-filter filt doesn’t change the input, only tests it for pass/fail and and returns the passing tiddler titles. So the result would be the same when using both fitler and subfilter operators.

In some cases the two filters will give the same result, like @joshuafontany said.

https://tiddlywiki.com/#filter%20Operator%20(Examples) - go to this tiddler and click the try it button for some of the examples and edit the filter back and forth between subfilter and filter. You should see the output change. Maybe those concrete examples will help make it clear?

As @joshuafontany said.

See my previouse reply where I mention the rule in an out forms of using subfilter

[tag[Railroads]] -[subfilter<filt>] all railroads but NOT those meeting the subfilter test.

[tag[Railroads]] +[subfilter<filt>] all railroads but ONLY those ALSO/AND meeting the subfilter test.

Phew! I think I finally understand now especially after doing what @btheado suggested and seeing what the differences are. Thanks to everyone who helped me out with this. Now the trick is going to be remembering next week!