cyclestylus

Stylus 'for' cycle: possible to combine range and single values?


Is it possible to use both range and single values (combined) for the for cycle in Stylus ?

for item in range(2, 7) 14 33
    li:nth-child({item})
        color red

or

for item in 2..7 14 33
    li:nth-child({item})
        color red

that code is not working. It can only work if either range or a set of single values is used.


Solution

  • Unfortunately, Stylus doesn't have anything like concat in the standard library, only push, but you can easily write it:

    concat()
      ret = ()
      for item in arguments
        push(ret, item)
      ret
    
    body
      for i in concat(range(0, 5), 10, 55)
        test: i