Rust: Iterators

  Рет қаралды 15,505

The Dev Method

The Dev Method

Күн бұрын

Пікірлер: 36
@BogdanSerban
@BogdanSerban 2 ай бұрын
I like your tutorials, straight to the point yet easy to follow 👍
@williamdroz6890
@williamdroz6890 Жыл бұрын
Iterators are also cool because you can use them with Rayon and get parallelism for free.
@FandangoJepZ
@FandangoJepZ Жыл бұрын
But keep in mind that this will in many, especially simpler cases, be incredibly slow
@hailuong9295
@hailuong9295 Жыл бұрын
@@FandangoJepZ i mean Parallelism always mean for doing bigger thing, where the cost for work outweight the cost for syncing context, alway choose right tool for right job
@pecet
@pecet Жыл бұрын
Just wanted to say that I'm enjoying your videos so far. When I'm tired after work writing Swift and Kotlin tests I watch Rust to regenerate.
@jpgiodevs
@jpgiodevs Жыл бұрын
Incredibly helpful videos! I hope this year bring's you the notoriety you deserve!
@snk-js
@snk-js Жыл бұрын
you loved this video, content so smoothly teached. congratz, big brain
@irlshrek
@irlshrek Жыл бұрын
Love it! I think videos on building intuition are super valuable
@meyou118
@meyou118 4 ай бұрын
ty - it appears the key to the error for collect is "...because all candidates have the same return type" - imho; the compiler should list them and thats why underscore can be used, the compiler already knew the type of the items. - anyway thx, i just learned something about rust
@MeesumQazalbash
@MeesumQazalbash 8 ай бұрын
What is your vs code theme? It is kind of cool. Also what extension do you use for the line on the left that makes a bar over a function and its body?
@MickAlpine
@MickAlpine Жыл бұрын
Excellent work, loving your Rust series! Quick question - what's your VSCode theme - it looks awesome!
@TheDevMethod
@TheDevMethod Жыл бұрын
This is the GitHub Dark theme
@farzadmf
@farzadmf Жыл бұрын
Very nice explanation, thank you!
@L0wPressure
@L0wPressure Жыл бұрын
Keep it up, awesome content :)
@AlexanderHyll
@AlexanderHyll Жыл бұрын
Small addition to the original loop. A while loop is not the idiomatic way to loop over the entire structure (like the iterator). You’re setting a variable in an outside scope that you need to track and that gets cleaned later in the program. You should just do: for i in 0..dark_side.len() { dark_side[i] } Now the iterator is often a better way to do it anyways with other added benefits. But it is not that template heavy to start with as the needlessly involved while loop. Love the vid though, great job!
@xenocampanoli815
@xenocampanoli815 9 ай бұрын
Thank you.
@宝强杨
@宝强杨 Жыл бұрын
Nice video, help me a lot, Thanks.
@jakubrembiasz8942
@jakubrembiasz8942 11 ай бұрын
Love this vid!
@raylopez99
@raylopez99 Жыл бұрын
As a beginner I had a hard time with the first example, not in compiling it, but in understanding it. So I reworked it as below. The key IMO is that the .collect method will collect the values on the RHS into a vector you can use. See below. // let v1: Vec = vec![1,2,3]; let X = v1.iter().map(|x|x+1).filter(|x|*x>2); //note dereference *x, to get value println!("{:?}", X); // Prints: Filter { iter: Map { iter: Iter([1, 2, 3]) } } let Y: Vec = X.collect(); println!("{:?}", Y); //prints: [3, 4] println!("------------Part Two ------------------"); let v2: Vec = vec![1,2,3]; let Q = v2.iter().map(|q| {q+1}); println!("{:?}", Q); // prints: Map { iter: Iter([1, 2, 3]) } let Y2: Vec = Q.collect(); println!("{:?}", Y2); // Prints: [2, 3, 4] //
@Notoriousjunior374
@Notoriousjunior374 Жыл бұрын
You can use Vec when collecting it
@kamertonaudiophileplayer847
@kamertonaudiophileplayer847 Жыл бұрын
I also use a bit iterators. It is funny, people become so used to with inferring, that even do not know types. Thank you.
@chouaibsam4381
@chouaibsam4381 Жыл бұрын
I still struggle with the deref concept
@TheDevMethod
@TheDevMethod Жыл бұрын
Let me know if this video helps kzbin.info/www/bejne/i3yzoXqXptBmn80
@greisboy425
@greisboy425 Жыл бұрын
let mut _a = 99; // x and y are both pointer, that's why x or y will return memory address not the int value. let x = &_a as *const i32; //pointer to x let y = &mut _a as *mut i32; //pointer to y // accessing or modifying pointer value is unsafe. unsafe { // y = 100; // this code will not change the value but will change the mem. addr instead // and since 100 is not a valid memory address, the program will crash. *y = 100; // this is the proper way to access the value, using dereference (with *) assert_eq!(100, *x); //another deref to x with *. // since both x and y have the same pointer (same memory address), so it will hold 100. }
@larrybird3729
@larrybird3729 Жыл бұрын
amazing!!!!
@736939
@736939 Жыл бұрын
15:05 Shit, this is something new😮
@shapedthought
@shapedthought Жыл бұрын
Can’t believe you didn’t say “turbo fish”!
@johnwilliams7999
@johnwilliams7999 Жыл бұрын
nice video!
@greisboy425
@greisboy425 Жыл бұрын
When you implement Iterator trait for struct Shoe, your struct (Shoes) magically become an iterator and you can call "into_iter() or iter()" method on your struct. Other iterator method such as "sum()" will also available. But if you try to compile it (with a call to "sum()"), rust compiler will be so unhappy (it won't compile) as it dont know how to total our custom type or struct. I have a question: How to override "sum()" function on Iterator trait, so we can return total or sum of one field in a struct, in your example to return the total size of all shoes...?. My current solution (that I use on one of my project) is to implement method (not a trait function but regular method using "impl MyStruct { pub fn total(&self) -> i32 { self.iter().map(|item|{item.size}).sum()}). But it would be nice if we can just use "mystruct.sum()" (using sum() function from Iterator).
@TheBlueye13
@TheBlueye13 7 ай бұрын
Have you tried implementing std::ops::add and Default for your struct? The only other thing that vomes to mind is fold(0, |x, obj| x + obj.size)
@IamAWESOME3980
@IamAWESOME3980 5 ай бұрын
Functional programming my man
@Anastasia-cv4ld
@Anastasia-cv4ld Жыл бұрын
What font are you using?
@TheDevMethod
@TheDevMethod Жыл бұрын
I either use Fira Mono or Plex Mono
@axorusmt7042
@axorusmt7042 Жыл бұрын
is this a reupload?
@axorusmt7042
@axorusmt7042 Жыл бұрын
don't mean to be rude, but i could have sworn i have seen this video before. maybe just deja vu?
@i007c
@i007c 7 ай бұрын
you look at your keyboard while typing 🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣
Rust: Store Data on the Heap with Box
10:02
The Dev Method
Рет қаралды 5 М.
Rust: Generics, Traits, Lifetimes
35:34
The Dev Method
Рет қаралды 48 М.
My Daughter's Dumplings Are Filled With Coins #funny #cute #comedy
00:18
Funny daughter's daily life
Рет қаралды 8 МЛН
Good teacher wows kids with practical examples #shorts
00:32
I migliori trucchetti di Fabiosa
Рет қаралды 4 МЛН
Minecraft Creeper Family is back! #minecraft #funny #memes
00:26
小天使和小丑太会演了!#小丑#天使#家庭#搞笑
00:25
家庭搞笑日记
Рет қаралды 37 МЛН
Understanding Rust Closures aka. Anonymous Functions 🦀 💻
30:22
Trevor Sullivan
Рет қаралды 14 М.
Rust's iterators are more interesting than they look
22:46
timClicks
Рет қаралды 9 М.
Rust: Closures
19:53
The Dev Method
Рет қаралды 17 М.
Rust: Weak References
19:40
The Dev Method
Рет қаралды 4 М.
Popular Rust Iterator Methods 🦀
54:54
Trevor Sullivan
Рет қаралды 7 М.
"The Life & Death of htmx" by Alexander Petros at Big Sky Dev Con 2024
23:01
Montana Programmers
Рет қаралды 61 М.
Rust Data Modelling Without Classes
11:25
No Boilerplate
Рет қаралды 174 М.
The Value of Source Code
17:46
Philomatics
Рет қаралды 52 М.
Arc instead of Vec? | Prime Reacts
37:18
ThePrimeTime
Рет қаралды 66 М.
My Daughter's Dumplings Are Filled With Coins #funny #cute #comedy
00:18
Funny daughter's daily life
Рет қаралды 8 МЛН