Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Sep 20, 2023
1 parent b1f9bbe commit e9638ab
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions docs/writeups/0009-closures.md
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]}"))
```

0 comments on commit e9638ab

Please sign in to comment.