Skip to content

Commit c5e04a6

Browse files
committed
Document table.foreach's propagating behavior
1 parent eadb04b commit c5e04a6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/Runtime Environment/Table.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ t:foreach(print)
168168
--> 2
169169
--> 3
170170
```
171+
If the callback has a non-nil return, it is propagated:
172+
```pluto
173+
local t = { 1, 2, 3 }
174+
print(t:foreach(function(value)
175+
if value % 2 == 0 then
176+
return value
177+
end
178+
end)) --> 2
179+
```
171180
---
172181
### `table.filter`
173182
Filters away keys (both array and non-array) that fail to meet the condition established by `callback`. Elimination is done by setting the value to `nil`, consider using `table.reorder` if you want a continuous array after filtering.

0 commit comments

Comments
 (0)