Тёмный
No video :(

Programming Terms: First-Class Functions 

Corey Schafer
Подписаться 1,4 млн
Просмотров 283 тыс.
50% 1

In this programming terms video, we will be looking at the term "First-Class Function". First-class functions are extremely important to grasp because understanding them will help us understand more complicated terms such as: Closures, Higher-order functions, currying, and more. We will be looking at examples of first-class functions in both Python and JavaScript so that we can really understand the concept, regardless of programming language.
The code from this video can be found at:
github.com/Cor...
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com...
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer

Опубликовано:

 

22 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 481   
@kickbuttowsk2i
@kickbuttowsk2i 4 года назад
Rabbit hole: Classes > Decorators > Closures > First-Class Functions. Thank you Corey
@tahsintariq8757
@tahsintariq8757 4 года назад
For me it was Multiprocessing > Threading > Decorators > Closures > First-Class Functions. Great videos!!
@soupnoodles
@soupnoodles 3 года назад
this is exactly what happened rip
@HerambLonkar95
@HerambLonkar95 3 года назад
For me as well
@konyi449
@konyi449 3 года назад
@@tahsintariq8757 me too
@sundaymanali5854
@sundaymanali5854 3 года назад
yeah wtf lol
@darthvador3699
@darthvador3699 8 лет назад
*goes on tutorial for decorators* You: If you haven't seen my video on closures, you may want to check that out since I won't be spending a lot of time on them *goes on video for closures* You: if you haven't seen my video in first time functions you may want to check that out since I won't be spending to much time explaining that Damnit Corey... Nonetheless I love the videos, keep up the good work man.
@coreyms
@coreyms 8 лет назад
Haha, sorry about that. Decorators have a few prerequisites that kind've ended up in a chain of videos. Hope you found them useful. Also, I saw the question you wrote about your calculator app in another comment. I'll do my best to answer that one when I have the chance.
@berryblast3930
@berryblast3930 7 лет назад
same
@darrenandveronica
@darrenandveronica 7 лет назад
Hehe - I want 4 videos deep to get here also. Classes > decorators > closures > here. These are awesome videos by Corey. Each video explains everything awesome
@zbzb-ic1sr
@zbzb-ic1sr 7 лет назад
You're Darth Vader, you should know how to code.
@hailstress
@hailstress 7 лет назад
Same scenario over here.
@FamilyGuySweden
@FamilyGuySweden 5 лет назад
I ended up here because I was watching "Python OOP Tutorial 3: classmethods and staticmethods". Thats a chain invocation of tutorials :D:D:D
@Asterite
@Asterite 5 лет назад
haha same
@privetabdul
@privetabdul 4 года назад
lol same
@sudarshanjha6737
@sudarshanjha6737 4 года назад
🙃🙃
@preranajoshi8488
@preranajoshi8488 4 года назад
hahah same
@meghalbisht6768
@meghalbisht6768 3 года назад
same! xD
@ledosilverknight4619
@ledosilverknight4619 5 лет назад
Corey is a beast at teaching people how to code.
@kelleywooten1712
@kelleywooten1712 4 года назад
I find Your Tutorials outstanding in terms of ease of understanding. I am 62 years old and haven't touched a keyboard since dbase 3 and Lotus 1-2-3. You are making my learning experience with Python much easier. Thank you very much. Kelley Wooten
@sabbywins
@sabbywins Год назад
Woooooo Go Kelley!
@colemanj64
@colemanj64 7 лет назад
I've watched half a dozen videos on Python first class functions but only now, after watching this from Corey, do I understand it.
@akshgpt7
@akshgpt7 4 года назад
I've been working with Python for so long, but after watching Corey's videos, I realized how many basics I was missing out on! Thank you so much, you're just amazing!
@alperakbash
@alperakbash 5 лет назад
I have been using python for the last two years, but after watching some of your videos, I have decided to watch all the basic tutorials from your videos, again. Thank you ver much for giving us point of view.
@Deepak-yz5zl
@Deepak-yz5zl 2 года назад
Some tutorials never gets old! Such a great teacher
@classik305
@classik305 6 лет назад
you're a freak of nature, my guy. You just took me to that next Python level. THANK YOU!!
@dgbene1
@dgbene1 6 лет назад
I've made a few attempts at understanding decorators but you really broke it down very well and I got that "why did this ever seem so difficult?" moment. I apricate your pace and the practical examples. Thanks. You have another subscriber.
@melonelonm6074
@melonelonm6074 5 лет назад
In the decorator closure, I noticed that; log_hi = logger('Hi!) and log_hi(), do not need the function to work. So what is the purpose for the function ?
@eugen3775
@eugen3775 7 лет назад
Nice vid , one mention though, @5:13 in the video, in the for loop of javascript , I think the correct line is : result.push(func(arg_list[i])); this way you use the actual array items instead of generating one yourself with i value. Also this way you can let var i = 0 . Thanks
@thsdsyt
@thsdsyt 4 года назад
This guy really knows how to explain programming languages. Amazing!
@artihlec
@artihlec 7 лет назад
6:30 Corey, you a little bit messed up with your JS my_map function :). It behaves in this particular case as its python counterpart only because an array has values [1,2,3,4,5], try to change items in an array(list) and JS results will do not match with python results. It should look like this: function square(x) { return x * x; } function my_map(func, arg_list) { const result = []; for (var i = 0; i < arg_list.length; i++) { result.push(func(arg_list[i])) } return result; } var squares = my_map(square, [1,2,3,4,5]) console.log(squares) BTW. I've been watching you for a wile and today actually decided to subscribe. A good and useful channel, a good explanation.
@coreyms
@coreyms 6 лет назад
Sorry for the super late reply. Yes, that's right. Others have pointed this out as well. I should have caught that when I first ran the code with the 0 index and got the wrong result. Oops! Thanks for the correction!
@snoopyjc
@snoopyjc 5 лет назад
I was about to point out the same thing
@marflage
@marflage 4 года назад
Or you could use For...of, or For...each functions.
@Colstonewall
@Colstonewall 8 лет назад
Very nice. Well thought out examples for a topic that's rarely covered.
@PunjabiDuoVlogs
@PunjabiDuoVlogs 5 лет назад
I have never seen anything explained anywhere just like you did. THANK YOU. You are really the BEST teacher.
@princeofxane
@princeofxane 5 лет назад
I have read so many articles and was still clueless about this concept. I watched your video only for 10 minutes, something that i thought was so complicated, understood in a jiffy. You are awesome. Thank you so much.
@rishabhmishra2908
@rishabhmishra2908 2 года назад
finally found someone who got me crystal cleared with first class functions, closures and decorators...... good work Corey !
@iamviccckkk
@iamviccckkk Год назад
I know this is an older video but I just wanted to say how much your videos have helped me to learn Python! I've made my first ever little programme the other day and seeing it actually work and do stuff amazes me. You have made learning Python so much easier than other resources I've looked at. I haven't had the need to use first-class functionality, but your explanations and examples have made it make so much sense! Thank you so much :D
@andresvodopivec5950
@andresvodopivec5950 5 лет назад
After reading what the dictionaries say in so many words and very confusing, amazing Corey you did it in a single line very clear. This makes me think "you should be hired by dictionary entities to give definitions". Thanks for your help!
@masterbat8953
@masterbat8953 4 года назад
This is by far the best explanation one can find on youtube about the flow of execution, which is so important for anyone to understand really hard one grasp at first in python
@shashanknegi7861
@shashanknegi7861 3 года назад
I saw ur first video when i was not able to find a good tutorial on iterators and generators and now i refer to ur videos when i have to know anything bout the language... truly an amazing teacher
@oppaarif3975
@oppaarif3975 2 года назад
Your explanation is really simple and clear. I started to learn js fundamental and stumbled upon first class function concept. Got confused for couple of hours and after watching your explanation made me understand it clearly. Cheers.
@ManzoorHussain-gz1vk
@ManzoorHussain-gz1vk 2 года назад
I love the ways you teach. My words are not enough to explain how much I love your teaching style and high level content.
@aashayamballi
@aashayamballi 5 лет назад
Man! Corey you're really great at explaining things, my mind actually blown... Thank you so much!
@pythonicd1239
@pythonicd1239 3 года назад
I know I'm late but I have to say, THANK YOU!! I mean your videos are just perfect, your teaching is amazing, you explain everything so clearly, the quality of the audio and video is also just amazing! Best videos for learning python(and other programming languages) on RU-vid.
@mau_lopez
@mau_lopez 4 года назад
Excellent video. This is kind of abstract, but with this excellent explanation and simple examples that do not involve other complications but just illustrate the point at hand, everything is clear. I'm really enjoying this and the other Python tutorials from Corey Schafer. Thanks a lot!
@draosf
@draosf Год назад
Honestly, you should make a full Functional Programming course. I'm writing this comment and haven't even watched the whole video yet. Thank you so much.
@meatyout
@meatyout 5 лет назад
Thanks, Corey! Great tutorial as always. However, I think it's important to make it clear that the examples you're giving are just intended to illustrate the concepts of first-class/higher-order functions, etc., and that the same results can be achieved in a more simple and/or readable way: Examples 1 & 2: def exp_list(exp, lst): exped = [i ** exp for i in lst] return exped print(exp_list(2, [1, 2, 3, 4, 5])) # outputs [1, 4, 9, 16, 25] print(exp_list(3, [1, 2, 3, 4, 5])) # outputs [1, 8, 27, 64, 125] Example 4: def wrap_text(tag, txt): print(f"{txt}") wrap_text("h1", "This is a headline") # outputs This is a headline wrap_text("p", "This is a paragraph") # outputs This is a paragraph
@marting9771
@marting9771 2 года назад
I like your explanations and the clarity of your voice. Not to disparage other tutorials on here but most of the Hindi speakers are way hard to understand. Thank you for creating your channel!
@Descart330
@Descart330 Год назад
The more closures you add, to closures, it makes more sense as you're like, saving information to make a function be used for a specific purpose.
@adrianayon5513
@adrianayon5513 2 года назад
You did an amazing job explaining this, bravo my good sir!! A like and a sub right here all day!!
@temporary_variable
@temporary_variable 5 лет назад
Your explanation helps me internalize the topics , I mean they fall at the right place, they are meant to be with ease. Thanks a lot.
@cryptotv3013
@cryptotv3013 2 года назад
Awesome explanation video for both languages, I was struggling past one week on this topic watching more videos finally figured out all.
@ashwinsingh1325
@ashwinsingh1325 4 года назад
Was trying to learn python syntax for ML and this has really cleared things up! Don't know if you take suggestions but I write notes down for you videos and would love it if you could provide a textual overlay of what topic you're covering. Had to playback a few times to figure out when you switched from passing function example to the return function example.
@KhattyDT
@KhattyDT Год назад
Been watching a lot of tutorial videos but yours is the best! Simple and straight to the point! Thanks a lot.
@hubertcombomarketing2693
@hubertcombomarketing2693 4 года назад
You're amazing guy Corey. Thank You very much for Your work.
@coreyms
@coreyms 4 года назад
Thanks!
@joxa6119
@joxa6119 6 месяцев назад
The series is super helpful for a person like me that has no computer science background.
@millaw.1718
@millaw.1718 5 лет назад
Thanks a lot for the explanation! I was so confused with decorators, now it makes so much more sense to me :) You are just amazing!
@remedyiq8034
@remedyiq8034 Год назад
Best videos on youtube. The way you explain concepts are simply amazing
@bermetumarova4683
@bermetumarova4683 Год назад
Thanks, finally I understood what is first class functions.
@youcefguichi3132
@youcefguichi3132 Год назад
almost 2023 and still very helpful, thanks a lot for your tutourials
@bernoulli9047
@bernoulli9047 4 года назад
The wrap_text function example after 11:00 would look very nice and readable with python3's f-strings. Thanks for all your hard work, Corey! I really love your videos.
@abhilashkaluwala
@abhilashkaluwala 4 года назад
i was struggling to understand this concept, this is the BEST EXPLAINATION ON THE INTERNET.
@mahmoudreda1083
@mahmoudreda1083 3 года назад
classmethods and staticmethods >>> Decorators >>> Closures >>> First-Class Functions. Keep the GOOD work Sir!
@simonaugustocarroz4447
@simonaugustocarroz4447 3 года назад
Well explained and to the point, i cant believe this guy is real
@basu_104
@basu_104 Год назад
Brilliant step by step build up to higher order function usage. Thanks do much
@YeekyYeeky
@YeekyYeeky 2 года назад
when I face some difficulty in understanding python concept , I will first search to see if Corey have video about that topic , Thank you very much
@cutefunnyanimals5441
@cutefunnyanimals5441 Год назад
Crazy how sometimes when you read a book, or some instructions, the concept just doesn't stick because of the poor examples being used. This explanation made prefect sense and now I think I have grasped closures. This is the first video of yours I have watched. You have a new subscriber!
@dequationblog
@dequationblog 5 лет назад
Fast becoming a fan here, Mr. Schafer. A+ on the didactics and presentation.
@Glashome
@Glashome 4 года назад
great example for the utility of returning a function. Really helpful
@heshankumarasinghe3159
@heshankumarasinghe3159 3 года назад
This video helped. I have been trying to understand higher order functions and have seen a video on another channel and that video made me confused even more. This video really helped. Specially the fact that you used a semi real world example when explaining why would we ever want to return a function from a function helped me understand the importance of higher order functions more. Thank you.
@ChaosArtist
@ChaosArtist 3 года назад
Thanks for this explanation of First Class Functions and the examples provided. It also helped me understand the map function better.
@andresa249
@andresa249 7 лет назад
in 11:00...15:00 we could execute wrap_text subfunction also this way: html_tag('h1')('Test Headline') so in first brackets we have parameters for main function and in second brackets we have parameters for subfunction. Understanding that - it's much easier to understand what happends between 11:00...15:00 Corey, thank you for very good tutorials.
@AriaHarmony
@AriaHarmony 6 лет назад
Thank you so much! Your vids are super clear and useful!
@Achrononmaster
@Achrononmaster 5 лет назад
Another use case is to allow a user to select what type of algorithm they want to use for a solver. A generic solver wrapper can then be used to call the algorithm (function) option the user selects at runtime, without having to class everything. Also useful for profiling different functions which perform the same task.
@salman.1st
@salman.1st 7 лет назад
Oh man, I was trying to comprehend closures for a the last week, now thanks to you I understand!
@karsten600
@karsten600 5 лет назад
Made me understand first class functions, thank you Corey.
@meatyout
@meatyout 5 лет назад
+Corey Schafer Thanks very much for all your great tutorial, Corey! FYI, there's one mistake in your my_map() function example, using cube: it should read: cubes = my_map(cube, [1 ,2 ,3 ,4 ,5]), then print(cubes) instead of squares ---> print(squares). And you can but you don't "have to" move the cube function above with the square function. No big deal, just in case it confuses some people.
@glitchedgitz
@glitchedgitz 3 года назад
This guy is beast at explaning these complex logic. Thanks For Videos🔥🔥🔥
@nriezedichisom1676
@nriezedichisom1676 11 месяцев назад
Just beautiful. Almost like art. Thank you again Corey
@iautomatecloud9305
@iautomatecloud9305 7 лет назад
Hi Corey, thanks for your videos. It certainly helps me clarify concepts and I appreciate what you are contributing to the community. It all works as an explanation, however there are two errors in your JS code that impact the result. Below is version 1.1. I've added it here so other viewers can see a working example of cube and square would get the expected result. I don't think markdown works here, so hopefully other viewers will be able to understand the code in this format. ``` function cube(x){ return x * x * x; } function square(x){ return x * x; } function my_map(func, arg_list){ result = []; //for(var i = 1; i
@qtran101
@qtran101 5 лет назад
as a new python learner, excellent video +1 and subscribed!
@TheFallibleFiend
@TheFallibleFiend 6 лет назад
I especially appreciate your going through the python and javascript together.
@oadams8
@oadams8 4 года назад
You genius. I hope you like teaching because we all want more
@parmachine470
@parmachine470 2 года назад
Finally got it. no wonder so many courses drop the ball at closures, decorators, getters setters. Hard part is seeing the inner is accessed by a variable defined as the call of the outer.
@evergreen7673
@evergreen7673 3 года назад
Hi, I've started to learn with You this year. You do a lot for other people . In this not easy time develop skills, and learning is the one thing which so meaningfull (sorry for my english, I hope its clear :)it gives hope and enjoy:)The way You speak is perfect, also for people who don't speak english very well.
@markrity
@markrity 8 лет назад
It was nice and clear , but in my opinion there is no need in showing it in 2 languages , a specially so similar. Its just makes the video longer , stick up to Python coz' of its easy readability :) Good luck. Keep up with the good work. P.S. Make more of Programming Terms videos ))
@DoJoStan
@DoJoStan 5 лет назад
I actually found the side by side comparison of JavaScript and Python extremely useful. I'm learning Python right now but have used JavaScript for around 2 years and having Corey explain the concept in both languages makes learning the concept in Python alot easier.
@STFU665
@STFU665 2 года назад
Very well explained. Thank you very much. I know a lot of programming languages, but everytime i learn a new one i got the feeling, that the concepts are just "Pointers of C in more complicated". But maybe that's just me :D
@fabiodbr
@fabiodbr Год назад
I got here 6 years late... amazing videos
@tomaspinto3833
@tomaspinto3833 5 лет назад
Great, thank you very much! I've been using this without knowing the term, it's really helpful to see it on a easy to understand language like python, i saw this on class but the examples were done with a functional programming and for someone that has only been in procedural programming, it was really confusing
@mohammadalaaelghamry8010
@mohammadalaaelghamry8010 Год назад
This channel is a treasure. i so much appreciate you. You are awesome.
@JoshuaDHarvey
@JoshuaDHarvey 4 года назад
Great video, thanks Corey!
@DeTeK-Dennis
@DeTeK-Dennis 6 лет назад
Great videos Corey. True teacher by heart !!!
@nhwhn
@nhwhn 3 года назад
As I was reviewing python OOP, I found the Schaferian loop. the "Class & Static method" lesson led to "Decorators" which led to "Closures" and lastly to this "First-class". This will lead back to the first lesson. Till I die.
@cigdemylmaz1532
@cigdemylmaz1532 Месяц назад
I started with python beginners, tutorial #8 on Functions, then Classes.. in order to learn decorators I needed to learn closures.. I have to go back to beginners tutorial #9 at some point :D Thank you so much for amazing lectures...
@DeepMindstorm
@DeepMindstorm 7 лет назад
you're freaking awesome thanks
@gururajchadaga
@gururajchadaga 4 года назад
What a fantastic explanation
@gusirity
@gusirity 7 лет назад
Such a good teacher! You make things very clear in a very short time :)
@secretboxkevin
@secretboxkevin 4 года назад
Great teaching!!! Thanks!!
@WarrenMarshallBiz
@WarrenMarshallBiz 5 лет назад
Fantastic video and crystal clear explanation, thanks so much!
@aliyaqoob8779
@aliyaqoob8779 5 лет назад
Very lucid and the examples made it very clear. Subscribed!
@alberkulicka954
@alberkulicka954 Год назад
I felt extremely dumb after watching the video and still not getting the point, but then an idea came up in my head and made this example, where I finally understood. Might help you as well def custom_sum(first_num): def wrap(second_num): print(first_num+second_num) return wrap two_plus_something = custom_sum(2) two_plus_something(5) two_plus_something(10) two_plus_something(20) output: 7 12 22
@ShynggysZ
@ShynggysZ 4 года назад
Hey Corey, it would be great if you add these two videos (First-Class Functions, Closures ) into a Python playlist (after Function video). It would be perfect continue and flow in that playlist. You have the best Python tuts in youtube (I guess not only in youtube)
@ramasubramanianduraraj8013
@ramasubramanianduraraj8013 4 года назад
A very good example.
@SabbirAhmed-ym4yf
@SabbirAhmed-ym4yf 6 лет назад
I feel comfortable to think like that-> the upper function creates a template for the inner function which then works on variable over the template to produce output.
@SAlexandert8
@SAlexandert8 7 лет назад
WOAH Had no clue you could do that. I am now going to watch your 47 videos. Great Job!
@ayushgupta1881
@ayushgupta1881 2 года назад
It was really easy to understand the concept in the manner you taught. Thank you !
@alejandronieto576
@alejandronieto576 Год назад
Thank you very much Corey, very good explanation and examples!
@SeaTaj
@SeaTaj 2 года назад
You are a light in the dark. Thank you
@dzittin
@dzittin 4 года назад
Another good example of passing a function reference is the compare function as an argument in most (all?) sort functions. The compare done in a sort is data or result-order dependent and has too be supplied by the programmer.
@20dorko
@20dorko 6 лет назад
Thank you so much Corey, this is really great video. I've only seen this one from you but definitely I am going to check more of your Python videos. If others are also as good as this one, I will support you, you have my word :) . Thanks again.
@kneelesh48
@kneelesh48 3 года назад
Corey is a great teacher
@PrinceKumar-um8mw
@PrinceKumar-um8mw 7 лет назад
Very useful Tutorial Corey..Really liked your way of explaining the concepts..
@manjeetrohilla7414
@manjeetrohilla7414 3 года назад
this video solved many doubts, from map to first class function to closures and I just realised at 11:00 you can use lambda function instead of wrap_text
@scuti7073
@scuti7073 Год назад
first class functions you are can treat them as arguments, assign them to variables, and you can return them from other functions. higher order functions are functions that take these first class functions in and returns them. the wrapped function is returned by the enclosing function. f = square f = square() difference is that the parentheses executes the function.
@lepidoptera9337
@lepidoptera9337 Год назад
Yes, and they will also choke your debugger and make the generation of call trees impossible. Oh, wait, you don't know how to use a debugger and call trees. ;-)
@sebton1
@sebton1 Год назад
When I saw the example of closure with the h1 tag I just start laughing. Is that even possible? I can see the many applications of this, thank you man, for helping me understand this!!
@elevendarter112
@elevendarter112 Год назад
I've learnt about the Higher Order Functions today and when it wasn't clear I knew I had to check your channel what's your take on it. I'm so glad you mentioned it's sometimes complicated even for for you (at least to explain it...) I think I can go to bed without thinking I'm a complete idiot :-))) BTW, the example with the tags was the first example I've seen that kinda made a sense why would someone use it at all.
@lepidoptera9337
@lepidoptera9337 Год назад
They are rarely needed. The number of times you will write an algorithm in your life that will profit from them can be counted on one hand for an average programmer. I thought I needed them once... until I discovered that there was a much better way that didn't use them. ;-)
@user-ps5bc1hg1f
@user-ps5bc1hg1f 2 года назад
hello the best teacher in youtube "can you plyz make a video of the short cuts keybord like how to select and uncomment the code ...?"
@user-xc5xf8gp8n
@user-xc5xf8gp8n 4 года назад
summary: First class function is a function that behvaes like a first class citizen(or entity). That is, functions that behave like normal variables. That means that it can be an input and output for another function, and stored as an variable. Those functions that inputs and outputs another function is called a higher class function. If a function is passed in without a bracket, python just refers to the code, and does not execute(run) it. IN that form we can treat the function just like any other variables, and that is how it is possible to make it an input or output for another function.
Далее