reduce, filter, removeAll

  Рет қаралды 3,330

Stewart Lynch

Stewart Lynch

4 жыл бұрын

This is the second in a series of videos on higher order functions in Swift. In this video we look at reduce, filter and removeAll
Starter Playground:
www.createchsol.com/StarterPro...
Videos in this series
Part 1: map, compactMap, flatMap: • map, compactMap flatMap
Part 2: reduce, filter, removeAll: • reduce, filter, removeAll
Part 3: contains, forEach, sorted, • contains, forEach, sorted
Stewart Lynch's KZfaq Channel
/ stewartlynch
CreaTECH Solutions Website
www.createchsol.com
Stewart Lynch's GitHub
github.com/StewartLynch

Пікірлер: 32
@joeprince7509
@joeprince7509 3 жыл бұрын
Your style of teaching is hands-down one of the simplest and most straightforward that I have seen here on KZfaq. I absolutely love it, and will remember the functions and way to use them because of your approach. Thank you!
@StewartLynch
@StewartLynch 3 жыл бұрын
Thank you so much for those encouraging comments. I appreciate the feedback.
@atalayasa2772
@atalayasa2772 4 жыл бұрын
Even if I have knowledge these functions it was worth to watch thank you..
@StewartLynch
@StewartLynch 4 жыл бұрын
Thanks. I do these videos basically to confirm my knowledge. I always learn something new by making them. I even go back and watch them later myself as a reminder.
@siddharthkothari007
@siddharthkothari007 4 жыл бұрын
Very good narration with some easy to grasp examples.
@ayon3527
@ayon3527 4 жыл бұрын
always a refresher!!
@chrisrylie71
@chrisrylie71 4 жыл бұрын
Thank you Stewart for sharing your knowledge
@StewartLynch
@StewartLynch 4 жыл бұрын
Thanks for your kind words
@subhashr.p7643
@subhashr.p7643 2 жыл бұрын
Great video.. Learnt lot with this. Very helpful
@sakshipatil9537
@sakshipatil9537 2 жыл бұрын
🙌🙌
@taglass75
@taglass75 4 жыл бұрын
I have a very minor correction. The ‘?’ operator as used in your heavy weights reduce example is the ternary conditional operator, not the nil coalescing operator ‘??’. Great videos though. The presentation is easy to understand, and you are a good narrator.
@StewartLynch
@StewartLynch 4 жыл бұрын
Yah. I realized that afterwards. Hoping no one would catch that LOL. In later videos you will see that I catch use the right term. Thanks for the comment though. I wish one could edit KZfaq videos once posted.
@danielbyrne
@danielbyrne 3 жыл бұрын
Gold
@user-me3xd5he2d
@user-me3xd5he2d Жыл бұрын
Thank you for the video. I don't know why I have such trouble taking what I learn and knowing how to apply it to a real Xcode project, but I always do with playground stuff. I get errors like : Instance method 'appendInterpolation(_:formatter:)' requires that '[String]' inherit from 'NSObject'. I start creating them above body then think maybe second array goes in the body because they're an error with "self". I don't know if I call it with Text, and it becomes a landslide of confusion, do you have a video where these are used in real situations, I could refer too?
@kapilsardana5053
@kapilsardana5053 4 жыл бұрын
Hi Stewart, I have a question regarding sync,async dispatch queues. For example let s1 = DispatchQueue(label: "queuename") s1.sync { for i in 1...10 { print("a") } } let s2 = DispatchQueue(label: "queuename2") s2.async { for i in 1...10 { print("b") } } let c1 = DispatchQueue(label: "queuename3", attributes: .concurrent) c1.sync { for i in 1...10 { print("c") } let c2 = DispatchQueue(label: "queuename4", attributes: .concurrent) c2.async { for i in 1...10 { print("d") } } I want to know how this works, like which queue is blocked when we run serial queue with sync and async and same for concurrent queues. It would be really helpful if you can explain this, or give me some resources to read about this.
@StewartLynch
@StewartLynch 4 жыл бұрын
That would likely be a series of videos to answer. Perhaps this resource can be helpful. theswiftdev.com/ultimate-grand-central-dispatch-tutorial-in-swift/
@jankuna9479
@jankuna9479 Жыл бұрын
Hi Stewart, thanks for your work. 2:06 : why is and 1st parameter of of type Result and not Int? Thank you in advance.
@StewartLynch
@StewartLynch Жыл бұрын
It is an Int. as it has to match the return type which is an Int. the second parameter has to be a type that matches numbers type and it is an Int as well. So both are ints.
@jankuna9479
@jankuna9479 Жыл бұрын
@@StewartLynch I got that. But why is the reduce function in that way defined? func reduce( _ initialResult: Result, _ nextPartialResult: (Result, Self.Element) throws -> Result ) rethrows -> Result What is the thinking behind the type Result?
@StewartLynch
@StewartLynch Жыл бұрын
Result is just a generic. It could be T. The transformation can convert say an Int into a Double. For Example, we could have done this: let halfSum = numbers.reduce(0) { (halfSum, number) -> Double in halfSum + 0.5 * Double(number) } or this with shorthand $variables let halfSum2 = numbers.reduce(0) {$0 + 0.5 * Double($1)} It might seem misleading because it looks like 0 is an Int, but really it is a Double. This might make it a bit more clear. let halfSum = numbers.reduce(0.0) { (halfSum, number) -> Double in halfSum + 0.5 * Double(number) }
@jankuna9479
@jankuna9479 Жыл бұрын
@@StewartLynch Thank you, Stewart, for your explanation.
@gamblethedog
@gamblethedog 3 жыл бұрын
How about this one: let totalSalary = employee.map{ $0.salary }.reduce(0,+)
@dibjr
@dibjr Жыл бұрын
Stewart, is there something in Xcode that allows you to display the value of a variable inline in the playground, or is that a graphical display thing you are doing in your videos? (example at 13:25 in your video). if it is in Xcode, can you reveal the trick?
@dibjr
@dibjr Жыл бұрын
Oh, and another great video!
@StewartLynch
@StewartLynch Жыл бұрын
You can tap on the Show Result button that appears on the right hand side of the playground with the code is executed
@dibjr
@dibjr 11 ай бұрын
Thanks!@@StewartLynch
@anhhanry7167
@anhhanry7167 2 жыл бұрын
the filltered array returns only an array of single element ( that fits the condition ) , but what if we want to return an array of struct that contains the condition, i.e. if we want to filter the person ( a struct ) with age > 5 ( in the clip -> get and array of name returned ) : how do we get an array of the person ( a struct) returned ?
@StewartLynch
@StewartLynch 2 жыл бұрын
I cover that starting at 18:12. When you filter an array of objects based on one of the properties you get an array of those objects.
@anhhanry7167
@anhhanry7167 2 жыл бұрын
@@StewartLynch the video "reduce, filter, removeAll' is only 18:12 length, your reply indicates -> " ..starting at 18:12" ??
@StewartLynch
@StewartLynch 2 жыл бұрын
@@anhhanry7167 Oops. I should have said 12:58. I picked the end time. Sorrry
@anhhanry7167
@anhhanry7167 2 жыл бұрын
@@StewartLynch Oh yeah, hum why did I miss this (portion) ? Thanks, for you time and tutorial, glad I've found your channel. I'm about your age , and like you, I'm a self learner,... for awhile, I was struggling with Swift language, and map/compact/flatmap.. and Decoder ( to decode plist in the bundle into UItableView ) and finally I found your channel and 'Swiftful thinking' channel , of which the speaker has presented the explanation of Swift language in the most clear, simple manner to understand ( but I must admit Swiftful thinking explained Decodable protocol a bit better though ) . Keep up the good work for the community, greatly appreciated. 👏👍🏻🙏🏻
@StewartLynch
@StewartLynch 2 жыл бұрын
Everyone learns differently and what works for one does not necessarily work for others. I am glad you have found someone who speaks to you.
contains, forEach, sorted
18:06
Stewart Lynch
Рет қаралды 2,1 М.
map, compactMap flatMap
17:06
Stewart Lynch
Рет қаралды 8 М.
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 38 МЛН
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 50 МЛН
Best KFC Homemade For My Son #cooking #shorts
00:58
BANKII
Рет қаралды 73 МЛН
Xcode File Headers and Macros
22:28
Stewart Lynch
Рет қаралды 1,1 М.
Xcode Frameworks and Workspaces
19:20
Stewart Lynch
Рет қаралды 1,6 М.
Deep Dish Swift 2024 Talk - Stewart Lynch
39:10
Stewart Lynch
Рет қаралды 4 М.
Swift 3 Fun Algorithms: Recursive Search through Binary Tree
16:34
Lets Build That App
Рет қаралды 22 М.
Map in swift Higher order function Hindi tutorial
11:20
Code Cat
Рет қаралды 10 М.
How to use @FocusState in SwiftUI | Bootcamp #60
16:28
Swiftful Thinking
Рет қаралды 17 М.
3.  WeatherKit: Conditions Backgrounds and Other Cities
19:50
Stewart Lynch
Рет қаралды 339
Master Python from Beginner to Pro! E013 - All Python Operators
23:44
Vision Pro наконец-то доработали! Но не Apple!
0:40
ÉЖИ АКСЁНОВ
Рет қаралды 485 М.
Проверил, как вам?
0:58
Коннор
Рет қаралды 378 М.
Tag him😳💕 #miniphone #iphone #samsung #smartphone #fy
0:11
Pockify™
Рет қаралды 4,6 МЛН