This page is part of a static HTML representation of the TiddlyWiki at https://tiddlywiki.com/

reduce Operator (Examples)

 4th December 2020 at 1:11pm

These examples use the following predefined variables:

  • add-price: [get[price]multiply{!!quantity}add<accumulator>]
  • num-items: [get[quantity]add<accumulator>]
  • join-with-commas: [<index>compare:number:gt[0]then<accumulator>addsuffix[, ]addsuffix<currentTiddler>else<currentTiddler>]
  • multiply-input: [multiply<accumulator>]

They also use the following data tiddlers:

[tag[shopping]reduce<num-items>]

[tag[shopping]reduce<add-price>]

[tag[shopping]reduce<join-with-commas>]
→ Uses <index> to act differently on the first item than the rest

[tag[non-existent]reduce<add-price>]
→ Empty input produces empty output

[tag[non-existent]reduce<add-price>else[0]]
→ Use else to ensure output if input was empty

=1 =2 =3 +[reduce<multiply-input>]
→ Empty initial value is treated as 0 by mathematical operators

=1 =2 =3 +[reduce<multiply-input>,[1]]
→ Setting initial value is sometimes necessary for correct results