Array methods in FSCSS (.reverse, .list, .length, and the rest) have been around since v1.1.14. They return strings, not array objects, and chaining is not supported. So for a long time the practical question was: how do you take a method result and keep working with it as a collection?
Derived arrays (v1.2.3+) are the answer. You declare a new @arr whose body is another array’s method output. The compiler resolves that into a proper array you can index, loop, and derive from again.
Docs: fscss.devtem.org/arrays
Core idea
@arr colors[#1E2783, #8C29B2, #C41348]
@arr reversed[@arr.colors!.reverse]
@arr asList[@arr.colors!.list]
@arr idx[count(@arr.colors!.length, 1)]
-
@arr.reversed— reversed values as an array -
@arr.asList— comma-separated list (string-shaped, but held in an@arrdeclaration when you need that form) -
@arr.idx— 1-based index sequence sized to the source length
Methods still need the ! method-access form. Derivation is how you avoid pretending those results are chainable objects.
Mutation using another array’s list
@arr more[#0ea5e9]
@arr.colors!+[@arr.more!.list] /* append items from more */
.list turns the second array into a form the mutation operator can consume. Same family of ideas: method → string-ish payload → use it in a declaration or mutation, don’t chain.
Practical pattern: index + reverse (charts, dual-pass polygons)
Modules like st-core@v2 use this for strokes that walk a path forward, then back:
@arr data[40, 60, 20, 80, 50]
@arr data-idx[count(@arr.data!.length, 1)] /* 1, 2, 3, 4, 5 */
@arr data-reversed-idx[@arr.data-idx!.reverse] /* 5, 4, 3, 2, 1 */
Loop the index arrays, read original values or --varN by index, build clip-path / polygon points in one pass for the top edge and another for the return edge. Derivation keeps “length → indices → reversed indices” explicit and stable under 1.2.3+ resolution rules.
count() can take a length expression (including @arr.name!.length) so index arrays stay tied to the data array instead of a hard-coded 5.
Limitations (still real)
| Constraint | What to do instead |
|---|---|
| No method chaining | Derive @arr step1[...], then method on step1
|
| Methods return strings | New @arr when you need array semantics again |
| Runtime vs ship | Prefer CLI for production static CSS; runtime 1.2.3+ is fine for prototyping |
Invalid:
/* don't */
@arr.x!.unit(px)!.join(+)
Valid shape:
@arr withUnit[@arr.x!.unit(px)]
/* then use withUnit or a method on withUnit */
Methods that pair well with derivation
| Method | Typical derivation use |
|---|---|
.reverse |
Dual-pass polygons, reverse visual order |
.list |
Feed mutations / comma-separated payloads |
.indices |
Explicit 1-based index lists |
.length |
Argument to count() for parallel index arrays |
.unique |
Deduped collections |
.sort |
Ordered variants |
.unit(val) |
Attach units for spacing/size scales |
.prefix(v) |
Class or token name stems |
Mental model
-
Store data in
@arr name[...] -
Inspect / transform with
@arr.name!.method -
Capture the result in
@arr next[@arr.name!.method]when you need another array -
Loop with
@arr.next[]or index into@arr.data[@arr.idx[]]
That four-step loop is how FSCSS stays expressive without pretending methods return rich objects.
Derived arrays don’t add a new runtime type. They make an existing rule reliable: methods yield strings; new @arr declarations turn the ones you care about back into collections. Since 1.2.3, that resolution path is solid enough for real module patterns—index arrays, reversed passes, list-based appends—without hand-duplicating values.
When a transform is only used once, a method in place may be enough. When you need to loop or index the result, derive.
Top comments (0)