20. let-else statements
As of 1.65, it is possible to use let statement with a refutable pattern.
| |
As of 1.65, it is possible to use let statement with a refutable pattern.
| |
As of 1.65, it is possible to label plain block expression and terminate that block early.
| |
Use flatten to iterate over only Some values if you have a collection of Options.
| |
Try to avoid matching Option or Result.
Use if let instead.
| |
Iterator adapter similar to fold (see previous bite) - holds some internal state and produces new iterator.
Note that Option is yielded from the closure.
| |
Use position to find position of an element in iterator. Returns None if the element does not exist.
| |
Similar to map but if allows to drop an item.
| |
Iterator consumer. Allows the accumulated value to be arbitrary type. Note the different types.
| |
Use enumerate to convert iterator over (usize,item) pairs.
| |
Useful when index of item is needed.
Fuse is an iterator that yields None forever after the underlying iterator yields None once. USage:
| |
Why is it useful? see example in this bite.
Sometimes an underlying iterator may or may yield Some(T) again after None was returned.
fuse ensures that after a None is returned for the first time, it always returns None.
Example from the rust documentation:
| |