mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 21:29:18 +00:00
Closures as a separate exercises appeared to be missing, so I added some. Have placed them in the watch order after functions, which seemed reasonable.
17 lines
833 B
Markdown
17 lines
833 B
Markdown
# Closures
|
|
|
|
Closures are a common programming concept found in many languages, but are primarily
|
|
associated with 'functional' programming styles. Closure are anonymous functions
|
|
(i.e. unlike regular functions, they don't have a name) that may access some variables
|
|
from their enclosing scope (they 'close' over their scope, capturing variables).
|
|
|
|
Closures are often used as arguments to higher order functions (functions which
|
|
take other functions as parameters), e.g. map(), filter(), reduce() et al on iterators,
|
|
but aren't restricted to these cases.
|
|
|
|
Rust's ownership model means that we might have to do something extra when declaring
|
|
closures which other languages don't require.
|
|
|
|
## Further information
|
|
|
|
- [Closures: Anonymous Functions that Can Capture Their Environment](https://doc.rust-lang.org/book/ch13-01-closures.html) |