-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): adding learn by for Wing
- Loading branch information
David Boyne
authored and
David Boyne
committed
Aug 27, 2024
1 parent
f57f78a
commit d41202d
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: Structs | ||
id: structs | ||
slug: /structs | ||
sidebar_label: 10. Structs | ||
description: Using arrays with Wing | ||
keywords: [Wing language, example] | ||
--- | ||
|
||
Structs are loosely modeled after typed JSON literals in JavaScript. | ||
|
||
```js playground example title="main.w" | ||
let main = () => { | ||
|
||
let a = MutArray<num>[1, 2, 3]; | ||
|
||
log("{a[0]}, {a[1]}, {a[2]}"); | ||
|
||
a[2] = 4; | ||
|
||
log("mutated value: {a[2]}"); | ||
log("len: {a.length}"); | ||
|
||
let data = MutArray<num>[1, 2, 3]; | ||
let twoD = MutArray<MutArray<num>>[data]; | ||
|
||
for array in twoD { | ||
for item in array { | ||
log(item * 10); | ||
} | ||
} | ||
|
||
} | ||
|
||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
wing it | ||
|
||
1, 2, 3 | ||
mutated value: 4 | ||
len: 3 | ||
10 | ||
20 | ||
30 | ||
``` |