jayber f9a4ff3b82 feat: added closures exercises in closure directory
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.
2022-05-30 21:47:47 +01:00

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)