Griffin SC HW 08 - TheEvergreenStateCollege/upper-division-cs-23-24 GitHub Wiki
Closures
anonymous functions you can save in a variable or pass as an argument to other functions
what is an anonymous function? I'm assuming it is a function without a name?
closures vs functions:
- closures often don't require you to specify the type of parameters or return values
- closures are usually made for a specific situation instead of any arbitrary scenario
providing types for top level functions gives clarity, so why isn't this important for closures? Is it because of their specificity?
the program does not compile because s is moved by add_suffix, so when it is called it's invalid
The output is "Hello" because the function prints s before calling the add_suffix function
f is called multiple times, so fnonce won't work
I'm not sure why this is, but they say pipeline takes an immutable reference to self, therefore FnMut can't be called within pipeline, I'm assuming because it is mutable
Iterators
example: let v1 = vec![1, 2, 3];
let v1_iter = v1.iter();
for val in v1_iter {
println!("Got: {}", val);
}
.next() returns the next item and if there isn't one then it returns none, so the while loop works fine because