RustBrock/Iterators and Closures.md
darkicewolf50 f3ec0d98cc
Some checks failed
Test Gitea Actions / first (push) Successful in 12s
Test Gitea Actions / check-code (push) Failing after 21s
Test Gitea Actions / test (push) Has been skipped
Test Gitea Actions / documentation-check (push) Has been skipped
finsihed ch14.1 and more than halfway through ch14.2
2025-02-25 17:02:50 -07:00

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.