Skip to content

Commit

Permalink
Update object comprehensions docs
Browse files Browse the repository at this point in the history
- Add example with a do...while loop
- Fix colon in an existing example
  • Loading branch information
peey committed Nov 7, 2024
1 parent ef813cf commit e833a67
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions civet.dev/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,7 @@ max := for max item of array
### Object Comprehensions
Loops can also accumulate their body values into an object.
When any loop is found is found within an object expression,
When any loop is found is found within a braced object expression,
its body value is spread into the containing object.
<Playground>
Expand All @@ -1951,13 +1951,22 @@ doubled := {
}
</Playground>
<Playground>
i .= 1
squares := {
do
[i]: i * i
while i++ < 10
}
</Playground>
The loop can exist anywhere a property is expected.
It can be freely mixed with other object properties.
<Playground>
rateLimits := {
admin: Infinity,
for user of users:
for user of users
[user.name]: getRemainingLimit(user)
}
</Playground>
Expand Down

0 comments on commit e833a67

Please sign in to comment.