-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Iterators #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Iterators #395
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
af95273
Adding information on closures and iterators
AdamCDunlap 5b2bf6d
Minor grammar fix
ajdunlap f1d7eea
Updating text wrapping
AdamCDunlap 0cdc0dd
Clarifications/typos
AdamCDunlap eaa6b80
Fix spelling errors
AdamCDunlap fcf95cd
word wrap and tweak a bit
steveklabnik e0db513
First draft of the iterators chapter
steveklabnik 09dd956
Edits to the intro and Closures section
carols10cents 118124d
Fix spelling, grammar, and other small stuff
carols10cents a37a6bd
Add another spelling and ignoring
carols10cents 117f3d8
More edits
carols10cents e3a1744
Clarify what happens when iteration is done
carols10cents fa861f7
Add more words to the dictionary
carols10cents 851bd9f
Break into sections
carols10cents 528c2c9
Fix typos
carols10cents f033a6f
Fixing steve nits
carols10cents 231932a
Move (pun intended) closure env capture/borrowing/etc to concurrency
carols10cents 1a60421
Ignore this test now
carols10cents File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,21 @@ | ||
| # Functional Language features in Rust - Iterators and Closures | ||
|
|
||
| ## Closures | ||
|
|
||
| ### What is a closure | ||
|
|
||
| How are they diff from fns | ||
|
|
||
| ### `Fn` traits | ||
|
|
||
| ## Iterators | ||
|
|
||
| ### Iterator & for loop | ||
|
|
||
| .into_iter() | ||
|
|
||
| ### Iterators are Lazy | ||
|
|
||
| Difference between adapter and consumer - another iterator or consuming? | ||
|
|
||
| ### Implementing the Iterator trait | ||
|
|
||
| Talk about using Associated Types here, foreshadow to advanced type systems | ||
| chapter about why this is a different thing than normal | ||
|
|
||
| ## ??? How does this improve the I/O project from Chapter 12 | ||
|
|
||
| Does this get woven into the above sections? | ||
|
|
||
| ## Summary: Performance | ||
|
|
||
| ### Iterators compile down to ASM == for loop | ||
|
|
||
| Most complicated chain of iterator functions that compile down to the same ASM as a for loop | ||
|
|
||
| ### Representation: Closures are a Struct | ||
|
|
||
| Closures don't have any further performance penalty over regular fn calls | ||
|
|
||
| Rust's design has taken inspiration from a lot of previous work. One of Rust's | ||
| influences is functional programming, where functions are values that can be | ||
| used as arguments or return values to other functions, assigned to variables, | ||
| and so forth. We're going to sidestep the issue of what, exactly, function | ||
| programming is or is not, and instead show off some features of Rust that | ||
| are similar to features in many languages referred to as functional. | ||
|
|
||
| More specifically, we're going to cover: | ||
|
|
||
| * *Closures*, a function-like construct you can store in a variable. | ||
| * *Iterators*, a way of processing series of elements. | ||
| * How to use these features to improve upon the project from the last chapter. | ||
| * The performance of these features. Spoiler alert: they're faster than you | ||
| might think! | ||
|
|
||
| This is not a complete list of Rust's influence from the functional style: | ||
| pattern matching, enums, and many other features are too. But mastering | ||
| closures and iterators are an important part of writing idiomatic, fast Rust | ||
| code. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functional