Not removing duplicate values?

49 views
Skip to first unread message

TonyM

unread,
May 21, 2019, 11:22:17 PM5/21/19
to TiddlyWiki
Folks,

Perhaps I am making a basic mistake, but I thought the get[fieldname] operator returns the values found in all fields named fieldname, and deduplicates them?

However in this example the select dropdown is returning multiples of each tiddler-type field found, presumably one for every tiddler that has the tiddler-type field

<$select tiddler="$:/temp/gototype/type"> default='task'>
<$list filter='[get[tiddler-type]sort[]]'>
<option value=<
<currentTiddler>>><$view field='title'/></option>
</$list>
</$select>

Why is it not removing duplicates?

Tw 5.1.19


Thanks in advance
Tony

Mark S.

unread,
May 21, 2019, 11:25:45 PM5/21/19
to TiddlyWiki
Oh, I knew there was an operator that worked differently. Why couldn't I remember it when I needed it?

Unlike most other Filter Operators, the selection output by get can contain duplicates. To avoid duplicates, use each[F]get[F].

HTH

TonyM

unread,
May 21, 2019, 11:33:28 PM5/21/19
to TiddlyWiki
Yes, Curious, thanks

[each[tiddler-type]get[tiddler-type]sort[]]
worked

Is this a clue to making it happen for maths operators without loosing duplicates?

Regards
Tony

Mark S.

unread,
May 21, 2019, 11:42:06 PM5/21/19
to TiddlyWiki
I guess it's a clue that it should be possible?

TonyM

unread,
May 22, 2019, 12:01:35 AM5/22/19
to TiddlyWiki
I tested this, nothing to do with select

;Numbers
<$list filter="[get[num]]">

</$list>

Sum: <$list filter="[get[num]sum[]]">

</
$list>

It is fine with duplicate values in the "num" field.

These filters can also be placed in {{{ [get[num]sum[]] }}} or "set filter="

Perhaps for maths we should have

{{{ [get[num]sum[]] ~[[0]] }}} for the nul case

Regards
Tony

TonyM

unread,
May 22, 2019, 5:41:48 AM5/22/19
to TiddlyWiki
This also works on pre-release

<$set name=count value={{{ [get[num]count[]] }}}>

Average: {{{ [get[num]sum[]] ~[[0]] +[divide
<count>] }}}

</$set>

So I expect we can say when manipulating values found in fields and keeping maths operators to a small set of rules it works.
  • Use {{{ to wrap }}}
  • use set to store intermediate values
  • Use + to act on the result so far
  • Use ~[[else]] for the missing /default value
  • use get to source number then immediately a maths operator
Tony

Mark S.

unread,
May 22, 2019, 11:21:48 AM5/22/19
to TiddlyWiki
Hi Tony,

Very neat!

I guess for more complicated operations you could have a first process that puts your intermediate results into fields. Then a second process that uses those fields to calculate the result.

-- Mark
Reply all
Reply to author
Forward
0 new messages