Plea for a new :as filter run prefix

Many times I do filter code that could be set like that:

\function .myFunction(param)
[do[something]with<param>]
:map[all[current]enjoy<currentTiddler>doing[stuff]enlist-input[]join[ ]]
\end

.myFunction takie a parameter and create a list of titles. The parameter has to be tweaked, and this is what does the first line. The second line would use the tweaked value to do the real stuff and its results is a list of titles. I need to use :map to access tghe tweaked value and use it on the current input values with the help of all[current].

But since I use :map I have to do the enlist-input[]join[ ] in the end.

It could be simpler with a :as filter run call that would act as :map in the coding but return, for each input value, all the titles selected at te end of each run. The :as name is surely to be replaced by a more clever name but you get tghe idea.

For instance:

[enlist[Examples Operator Prefix] :as[suffix<currentTiddler>]

wold return all the tiddlers finishing by Examples or Operator or Prefix.

This can currently be achieved using :map:flat[all[tiddlers]...], as in:

{{{ [enlist[Examples Operator Prefix]] :map:flat[all[tiddlers]suffix<currentTiddler>] }}}

-e

2 Likes

thank you @EricShulman . Yet this :flat addition is not told in the :map documentation, but only in the :map examples.

Are there any doc on suffixes for filter run prefix?

It is there actually, but only in the table on the beginning:


But I agree, it is easy to miss, I myself was in a similar situation not so long ago, having missed the flat suffix.

Thanks to @pmario we have a much better organized filter run prefix docs since recently, with the nice railroad diagrams. But map seems to be missing the suffix in its diagram, I’ll fix it. I think it will be much better visible then.


Edit: I made docs PR Improve filter run prefix docs by mateuszwilczek · Pull Request #8067 · Jermolene/TiddlyWiki5 · GitHub

3 Likes

This is in fact, only necessary, if you go ahead and use the function in a way that it only presents the first result, the join is used to stop this. If however you use the function in a filter, one that returns more than the first result, there is no need to join.

  • When I first started using the function I was annoyed at its behaviour returning the first only, but now I realise this is happening in multiple places within tiddlywiki, but I have no found multiple ways to defeat this first only behaviour.
  • The First only behavior also has its advantages and the text only output helps us avoid using the text widget.
  • Keep in mind we can also use functions as function operators. This has other behaviours.

I will try and give some nice examples and edit this reply;

  • I will also explore the use of the map: raw as part of the picture

Here is the simplest example I have that proves my assertion;

  • But we need a more comprehensive documentation of this
\function list.function() A B C

;Return first value only
# <<list.function>>
# {{{ [<list.function>] }}}

;Return list values
# {{{ [list.function[]] }}}

Try it on tiddlywiki.com

@TW_Tones Yes, I agree with you.The point is that I use $let and not the cumbersome $set. Se I only can get a unique value fos%r a varu%iable and thus I need the format trick.

It would be nice to have a kind of $set with all the ease of use of $let: multiple variables definitions, use of {{{ filter }}} to get the values for each variable. We could call it $mset for multi-set.

I am not sure exactly what you mean but have you tried +[format:titlelist[]join[ ]] at the end of a filter or function?

@TW_Tones This is exactly what I do. And enlist or enlist-input at the beginning of the next filter using the result of the previous one.

I find this distracting code. And any code is prone to typing errors, which do hard to find causes errors, so the less boiler plate I have, the best I feel.