-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed as not planned
Labels
awaiting submitterneeds a reproduction, or clarificationneeds a reproduction, or clarificationfeature requestpopularmore than 20 upthumbsmore than 20 upthumbs
Description
Never thought I'd say this but I think we need range blocks — we've had so many questions along the lines of 'how do I iterate n times?'.
The usual answer is one of these...
{#each Array(n) as _, i}
<p>{i}</p>
{/each}
{#each { length: n } as _, i}
<p>{i}</p>
{/each}
...but neither is particularly satisfying.
Anyway, we're a compiler, so we can add this for free, if we want to. The only real question is syntax. We could emulate Ruby's range operator:
<!-- 1,2,3,4,5 -->
{#range 1..5 as n}
{n}
{/range}
<!-- 1,2,3,4 -->
{#range 1...5 as n}
{n}
{/range}
{#range 5 as n}
could be shorthand for {#range 0...5 as n}
, perhaps.
Complications: Ruby's operator also handles decrementing ranges (5...1
) and strings ('a'...'z'
and 'z'...'a'
), so if we were to steal that syntax then presumably we should also support those.
Any thoughts?
NellWaliczek, paulocoghi, rodryquintero, YarivGilad, itswillta and 112 moresmithliam and dummdidummPaulMaly, maxmilton, aubergene and smithliamdunhamjared, HMGAscend and felipetesc
Metadata
Metadata
Assignees
Labels
awaiting submitterneeds a reproduction, or clarificationneeds a reproduction, or clarificationfeature requestpopularmore than 20 upthumbsmore than 20 upthumbs