mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Update syntax-list-comprehensions.md
This commit is contained in:
parent
e52d036000
commit
14e40671fc
1 changed files with 12 additions and 0 deletions
|
@ -63,3 +63,15 @@ let vector = c![x, for x in 1..10, if x % 2 == 0];
|
||||||
|
|
||||||
### Function syntax
|
### Function syntax
|
||||||
List comprehensions could be implemented as functions with ``table.map`` or ``table.filter``
|
List comprehensions could be implemented as functions with ``table.map`` or ``table.filter``
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
#### Perl
|
||||||
|
```perl
|
||||||
|
my @doubles = map {$_*2} 1..9;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Rust
|
||||||
|
```rust
|
||||||
|
let ns: Vec<_> = (0..100).filter(|x| x * x > 3).map(|x| 2 * x).collect();
|
||||||
|
```
|
||||||
|
|
Loading…
Add table
Reference in a new issue