mirror of
https://github.com/darkicewolf50/RustBrock.git
synced 2025-06-15 04:54:17 -06:00
31 lines
1.6 KiB
Markdown
31 lines
1.6 KiB
Markdown
# Functional Language Features: Iterators and Closures
|
|
Rust's design has taken inspiration from many exisitng languages and techniques
|
|
|
|
One significant influence is *functional programming*
|
|
|
|
Programming in a functional style often include using functions as values by passing them in args, returning them form other unfcitons, assigning them to varaibles for later execution and so forth.
|
|
|
|
This chapter/section won't debate the issue of what functional programming is or isn't.
|
|
|
|
It will discuss some features of Rust that are similar to features in many languages often referred to as functional
|
|
|
|
It will cover:
|
|
- [*Closures*](./Closures.md) - a function-like construct you can store in a variable
|
|
- [*Iterators*](./Iterators.md) - a way of processing a series of elements
|
|
- How to use colsure and iterators to [improve the I/O project (minigrep)](./Improving%20The%20IO%20Project.md)
|
|
- [The preformance of closures and iterators](./The%20Performance%20Closures%20and%20Iterators.md) (Spoiler alert: they are faster than you might think!)
|
|
|
|
We have already covered some other Rust freatures, such as pattern matchin and enums, that are also influenced by the functional style.
|
|
|
|
Mastering closures and iterators is an improtant part of wiritng idiomatic, fast Rust code.
|
|
|
|
|
|
## Summary
|
|
|
|
Closures and iterators are Rust features inspired by functional programming language ideas.
|
|
|
|
They contribute to the capability to express high-level ideas at low-level preformance.
|
|
|
|
The implementations of closures and iterators are such that runtime performance is not affected.
|
|
|
|
This is part of Rust's goal to strive to provide zero-cost abstractions. |