Add a description and examples for "strict" results from getindex (#7333)

* Add a description and examples for "strict" results

* Add another example

* Amend description of output with suffix "index"
This commit is contained in:
yaisog 2023-03-06 17:14:08 +01:00 committed by GitHub
parent 1946f173a9
commit 6732d96f78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 15 deletions

View File

@ -1,8 +1,22 @@
created: 20150203140000000
modified: 20170608150301791
modified: 20230306140231272
tags: [[getindex Operator]] [[Operator Examples]]
title: getindex Operator (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 "[[$:/palettes/Vanilla]getindex[background]]" "returns the value at index ''background'' of the [[DataTiddler|DataTiddlers]] [[$:/palettes/Vanilla]]">>
<<.operator-example 2 "[all[shadows+tiddlers]tag[$:/tags/Palette]getindex[background]]" "returns all background colors defined in any of the ColourPalettes">>
<<.operator-example 1 "[[$:/palettes/Vanilla]getindex[background]]" "returns the value at index <<.value background>> of the [[DataTiddler|DataTiddlers]] [[$:/palettes/Vanilla]]">>
<<.operator-example 2 "[all[shadows+tiddlers]tag[$:/tags/Palette]getindex[background]]" "returns all background colors defined in any of the ColourPalettes">>
[[ListopsData]] contains an empty index <<.value ~DataIndex>> which is not returned by the filter operator:
<<.operator-example 3 "[[ListopsData]getindex[DataIndex]]">>
This filter expression can be used to return the value, even if it is an empty string:
<<.operator-example 4 "[[ListopsData]] :filter[has:index[DataIndex]] :and[getindex[DataIndex]else[]]">>
There are 5 palettes which define the index <<.value diff-equal-background>>, but none defines a value:
<<.operator-example 5 "[all[shadows+tiddlers]tag[$:/tags/Palette]] :filter[has:index[diff-equal-background]] :map[getindex[diff-equal-background]else[]]">>
In the above example, the [[Map Filter Run Prefix]] is used instead of `:and` as it does not de-duplicate its results.
Another way to check if an index has an empty value is to [[count|count Operator]] the results from the [[getindex Operator]]:
<<.operator-example 6 "[[$:/palettes/Vanilla]indexes[]] :filter[[$:/palettes/Vanilla]getindex<currentTiddler>count[]compare:number:eq[0]]">>
Here, the input to `:filter` is the [[list of indexes|indexes Operator]] which are contained in [[$:/palettes/Vanilla]].

View File

@ -1,17 +1,20 @@
caption: getindex
created: 20150203140000000
modified: 20150203140000000
modified: 20230306131335009
op-purpose: select all values of a data property in the input titles
op-input: a [[selection of titles|Title Selection]]
op-parameter: the name of a [[property|DataTiddlers]]
op-parameter-name: P
op-output: the values of property <<.place P>> in each of the input titles
tags: [[Filter Operators]] [[Field Operators]]
title: getindex Operator
caption: getindex
op-purpose: select all values of a data property in the input titles
<$macrocall $name=".operator-def"
input="a [[selection of titles|Title Selection]]"
parameter="the name of a [[property|DataTiddlers]]"
paramName="P"
output="the values of property <<.place P>> in each of the input titles"
/>
Each input title is processed in turn, and is ignored if it does not denote a [[data tiddler|DataTiddlers]]. If the tiddler contains property <<.place P>>, the value of that property is [[dominantly appended|Dominant Append]] to the output.
<<.tip """If a data tiddler contains index <<.place P>> with an empty value, the empty string is not appended. The following [[Filter Expression]] can be used to also return an empty string
<pre>:filter[has:index[P]] :and[getindex[P]else[]]</pre>""">>
<<.operator-examples "getindex">>

View File

@ -1,9 +1,9 @@
caption: has
created: 20140410103123179
modified: 20190518145446047
modified: 20230306143207920
op-input: a [[selection of titles|Title Selection]]
op-neg-output: ''without suffix''<br>&raquo; those input tiddlers in which field <<.place F>> does <<.em not>> exist or has an empty value<br>''suffix `field`''<br>&raquo; those input tiddlers in which field <<.place F>> does <<.em not>> exist<br>''suffix `index`''<br>&raquo; those input tiddlers in which index <<.place F>> does <<.em not>> exist
op-output: ''without suffix''<br>&raquo; those input tiddlers in which field <<.place F>> has a non-empty value<br>''suffix `field`''<br>&raquo; those input tiddlers in which field <<.place F>> exists
op-neg-output: ''without suffix''<br>&raquo; those input tiddlers in which field <<.place F>> does <<.em not>> exist or has an empty value<br>''suffix `field`''<br>&raquo; those input tiddlers in which field <<.place F>> does <<.em not>> exist<br>''suffix `index`''<br>&raquo; those input data tiddlers in which index <<.place F>> does <<.em not>> exist
op-output: ''without suffix''<br>&raquo; those input tiddlers in which field <<.place F>> has a non-empty value<br>''suffix `field`''<br>&raquo; those input tiddlers in which field <<.place F>> exists<br>''suffix `index`''<br>&raquo; those input data tiddlers in which index <<.place F>> exists
op-parameter: the name of a [[field|TiddlerFields]]<br>''suffix `index`''<br>&raquo; those input tiddlers in which index <<.place F>> exists
op-parameter: the name of a [[field|TiddlerFields]] or, optionally an [[index|TextReference]]
op-parameter-name: F