Collection Operators

Collection operators let you filter, sort, transform, split, and join sequences inline, right in your hyperscript expressions. They chain naturally -- you can filter a list, sort it, then map it, all in one expression.

Inside where and mapped to expressions, it (and its) refers to the current element being tested or transformed.

Examples

<button _="on click
             set items to <li/> where it matches .active
             log items">
  Active items
</button>
<button _="on click
             set sorted to <li/> sorted by its textContent
             log sorted">
  Sort items
</button>
<button _="on click
             set names to <li/> mapped to its textContent
             put names joined by ', ' into #output">
  List names
</button>
<input _="on keyup
            set words to my value split by ' '
            put words.length + ' words' into the next <span/>"/>
<button _="on click
             set items to <li/> where its textContent is not empty
                                 sorted by its textContent descending
                                 mapped to its textContent
             put items joined by ' | ' into #result">
  Chain it all
</button>

Syntax

<collection> where <condition>
<collection> sorted by <expression> [descending]
<collection> mapped to <expression>
<string> split by <expression>
<collection> joined by <expression>