-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1f9bbe
commit e9638ab
Showing
1 changed file
with
43 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,43 @@ | ||
# WU0009: Closures | ||
|
||
## Syntax | ||
|
||
```rust | ||
// look at previous writeup regarding switches? | ||
pattern := identifier | '(' pattern [ ',' pattern ]* ')' | ||
closure := pattern '->' expr | ||
``` | ||
|
||
## Tuples as argument lists | ||
|
||
## How to pass closures as arguments? | ||
## How should function arguments look like? | ||
|
||
```rust | ||
func map[T, U](value: Maybe[T], f: Func[(T), U]) -> Maybe[U] { | ||
switch value { | ||
Nothing => Nothing, | ||
inner: T => f(inner), | ||
} | ||
} | ||
``` | ||
|
||
## How to capture variables? | ||
|
||
### Issues? | ||
### design consideration? | ||
### generalize to functions | ||
|
||
## Code examples | ||
|
||
```rust | ||
where values = [1, 2, 3]; | ||
|
||
values | ||
.map(elt -> elt * 2) | ||
.zip() | ||
.for_each((i, elt) -> println("value at {i}: {elt}")) | ||
// or | ||
.for_each(tup -> println("value at {tup[0]}: {tup[1]}")) | ||
``` | ||
|