An Introduction to Functors in JavaScript: The Basics in 9 Minutes with Examples

  Рет қаралды 10,198

Ijemma Onwuzulike

Ijemma Onwuzulike

Күн бұрын

A functor is a data structure that can be mapped over using a custom mapping interface. In order words, a functor asks as a wrapper around data which can expose that internal data with that mapping interface. The newly transformed data after mapping gets placed back into a new functor.
This process allows for some interesting composition, specifically function composition since we can chain functions to one another.
Functors are a central topic in functional programming. If you don't know much about functional programming, I made two other videos that touch on topics within the paradigm.
🎬 Subscribe to the channel! - / @ijemmaonwuzulike
Higher-Order Functions: • JavaScript Higher-Orde...
Pure Functions: • JavaScript Pure Functi...
Timestamps:
0:00 Intro
0:59 What Are Functors? Arrays as Functors
2:28 Functor Laws
2:38 Identity Law
3:14 Composition Law
5:50 Debugging with Function Composition
6:28 Promises as Functors
8:00 Build Your Own Functor
9:13 Make Your Functor Iterable
== Let's Connect ==
🐦 Twitter - / ijemmaohno
== Who I Am ==
I'm Ijemma, a frontend software engineer currently working in New York City. I make videos on all things JavaScript and, more broadly, frontend web development.
#javascript #webdevelopment #softwareengineer

Пікірлер: 66
@hansschenker
@hansschenker 5 ай бұрын
Congratulations for the clear and easy going explanation! So far the best functor explanation on YT.
@Kirshach
@Kirshach 2 жыл бұрын
Why on earth does this video have so little views, that was a great explanation!
@FernandoBasso
@FernandoBasso Ай бұрын
If I find the devs who didn't watch or +1 this video, they'll have hell to pay. Leave it to me.
@licriss
@licriss 3 жыл бұрын
So good to finally find an accurate explanation with concrete yet simple examples, thanks!!
@IjemmaOnwuzulike
@IjemmaOnwuzulike 3 жыл бұрын
glad you enjoyed it!
@NillKitty
@NillKitty 2 жыл бұрын
This video has extreme value in that it demonstrates scary FP concepts without using FP syntax. It's extremely easy to see what a "functor" is when you can see it in a language most people already understand. Great job and super high production quality skills; wish my tech videos looked this good. What do you use your graphics and how long does it take to put a video like this together?
@IjemmaOnwuzulike
@IjemmaOnwuzulike Жыл бұрын
Thank you! I'm glad the video was helpful, it takes me a week to write the script, record, and edit the video - i used after effects for the animation and final cut for the editing
@greenhorn7189
@greenhorn7189 2 ай бұрын
Great explains for begineers. Keep doing with live Example. Thank you a lot
@QRSTUVWXYZ123ify
@QRSTUVWXYZ123ify 3 жыл бұрын
Okay this is fun. I had a look at Wikipedia article *functor* and was afraid to then watch this video. But having enjoyed and benefitted from other videos you've shared, I worked through this. Pretty sure that I can get this by watching a few more times and writing code following along, grokking all the steps by repeating till the ah~ha arrives. You've done a great job making this approachable. Thank you!
@IjemmaOnwuzulike
@IjemmaOnwuzulike 3 жыл бұрын
ayye love to hear it, let me know if there's a point in the video you want me to diver deeper into✨
@bullettime2808
@bullettime2808 8 ай бұрын
I'm glad I found your channel it's a goldmine
@SuperChukwudalu
@SuperChukwudalu 6 ай бұрын
Best Functor video. Really simple.
@celiacasanovas4164
@celiacasanovas4164 7 ай бұрын
This video is invaluable. Thank you for taking your time to explain FP concepts derived from category theory in a demistified, practical and clear way.
@antoniozeajr.4702
@antoniozeajr.4702 Жыл бұрын
Best explanation after two days searching
@superchillh3o
@superchillh3o 3 жыл бұрын
Very similar to Brian Lonsdorf content, thank you so much for creating this, clear, concise, and practical!
@IjemmaOnwuzulike
@IjemmaOnwuzulike 3 жыл бұрын
thank you so much, I'm glad you enjoyed it!
@elatedbento
@elatedbento 8 ай бұрын
Excellent, precious video. Would you be so kind to do one about Monads? Please do one on monads. We desperately need one! Thanks 😃
@femiabolaji1809
@femiabolaji1809 5 ай бұрын
Coming back to this video to say it is amazing.
@scfoxcode
@scfoxcode 2 жыл бұрын
Really nice explanation. I've played around with Haskell and Elm, but never really got the whole Functor, Applicative, Monad business. Having another crack at it and this video is great
@andypsolomon
@andypsolomon Жыл бұрын
This was great. The best explanation of Functors I've ever heard.
@Faruk-zt5iw
@Faruk-zt5iw 7 ай бұрын
This is the by far the best video on functors.
@SuperQuwertz
@SuperQuwertz Жыл бұрын
Yo I want a series on fp-ts from you The video was great and easy to understand
@janduna4100
@janduna4100 2 жыл бұрын
Amazing content, so clearly conveyed with irrelevance omitted. Love it!
@klebergermano3356
@klebergermano3356 Жыл бұрын
The best video that I found about Functors with a great and concise explanation, thank you
@benjaminstorrier
@benjaminstorrier 6 ай бұрын
I actually understand now. Brilliant :) ❤
@damickillah
@damickillah 8 ай бұрын
You simply and absolutely should have more subscribers, due to this video alone. However, I skimmed through some of your other videos and your videos are immaculately produced and presented. I love to see it! Props & respect!🥰 SUBSCRIBED!!!!!
@EduardoLarios95
@EduardoLarios95 Жыл бұрын
This video was amazing, you totally made the topic more understandable for someone with C#/TS experience wanting to jump to some more functional concepts. Subscribed :)
@ayushcodes
@ayushcodes 8 ай бұрын
this is a very great explanation, thank you!!!
@balanced-living
@balanced-living 7 ай бұрын
Amazing video ❤, like your style of explanation
@andriilukianenko8106
@andriilukianenko8106 2 жыл бұрын
Hi, Ijemma! Thanks for the content, it's earned my Like. I'd like to add a bit to the 'nestedNumbers' vs 'chainedNumbers': indeed, reading chained map() calls is easier and we can plug in trace/tap() for debugging, and certainly looks better than e(g(f(x))). Luckily, FP gives us one more cool feature - compose(). h = compose(e, g, f) . -> map(h)
@BrunooS15
@BrunooS15 Жыл бұрын
Thanks so much for this video!
@williamb.2031
@williamb.2031 2 жыл бұрын
Fantastic video! :) thanks!
@edmundekott9463
@edmundekott9463 3 жыл бұрын
Thanks so much for this, it was super helpful
@IjemmaOnwuzulike
@IjemmaOnwuzulike 3 жыл бұрын
Glad it was helpful!
@rashidakhan77
@rashidakhan77 3 жыл бұрын
Very nice lesson!
@lateAutumn314
@lateAutumn314 8 ай бұрын
Damn, super interesting tutorial!
@hugodsa89
@hugodsa89 3 жыл бұрын
Awesome content really love it ! ❤️
@rasmusl2067
@rasmusl2067 7 ай бұрын
Great content!
@definty
@definty 2 жыл бұрын
Your channles so usefull and to the point. I love it! Thx for the content. BTW your missing a closeing parenthesis on the example at 3.28
@khaled.noordin
@khaled.noordin Жыл бұрын
Nice topics. Thanks mam
@paularah8877
@paularah8877 3 жыл бұрын
love it!
@zemaumm
@zemaumm Жыл бұрын
This video is SO good
@justinhj1
@justinhj1 Жыл бұрын
I really enjoyed this video for the content but also the production style. What tool do you use for the animated on-screen content if you don't mind me asking?
@rorycawley
@rorycawley 2 жыл бұрын
Nice content!
@processorbot8761
@processorbot8761 3 жыл бұрын
damn great video
@SuperQuwertz
@SuperQuwertz Жыл бұрын
Also the other concepts of fp please, like Monads etc. Especially in the context of Typescript
@ehza
@ehza Жыл бұрын
this is so cool
@whatthefunction9140
@whatthefunction9140 6 ай бұрын
Functors are funky
@anhi399
@anhi399 8 ай бұрын
I too wanna say howdy to Don, Ramy, and Chadwick--Ijemma knows what's up
@elatedbento
@elatedbento 8 ай бұрын
Quick question: if I map to a different type, such as going from an array of strings to an array of ints, is it still a functor? If I do ["John", "Mary", "Kate"].map(name => name.length), thus changing the inner type, is it still a functor or a different kind of functor?
@madlep
@madlep 7 ай бұрын
Yes. Still a functor. Functors are “structure preserving”, so an array functor has to map to another array functor. And it’s totally fine and used often to change the inner type. What it CAN’T do is return a different type of functor - like a promise, or an option, or a result etc (well, there’s nothing stopping it doing that, but it wouldn’t be a correct functor implementation, and it would be considered a bug)
@elatedbento
@elatedbento 7 ай бұрын
​@@madlepthank you so much for taking the time to explain. I really appreciate it! ❤
@meht8
@meht8 3 жыл бұрын
You awesome
@CarmelleCodes
@CarmelleCodes 3 жыл бұрын
these animations!! yes!!!!
@IjemmaOnwuzulike
@IjemmaOnwuzulike 3 жыл бұрын
ahhh tysm 😭✨
@kaungsithu7377
@kaungsithu7377 Жыл бұрын
more videos about applicative functor
@jongeduard
@jongeduard 8 ай бұрын
This is really funny. This explanation of a Functor is really somewhat different from what I have seen from a C++ tutorial. To me it looks like a specific version of it, not the whole story. In that tutorial a functor was explained as an object that behaves like a function. It did this by directly implementing the function call operator, so that it could literally be called as if it where a real function. And ok, I know JS does not have operator overloading, so then it that map method and that then method are ways to replace that. But this is all not the issue. In that C++ explanation they where NOT talking about that whole identity rule, just about composition. They did not require that the created function should return a new data structure or a new functor, but the generated function was just returning a single value like an integer for example. Was that a wrong explanation? I would say, that identity thing is more important for Monads, which are basically very related, but which indeed require both a wrapped type as imput as well as that they return the that wrapped type (arrays or lists are a good example, but the Option and Result types in the Rust language are also great examples of monads). I am really interested in anyones reply on this, learn me more.
@Lambdaphile
@Lambdaphile Жыл бұрын
wtf, insta sub!
@quickfingers5982
@quickfingers5982 3 жыл бұрын
what is functor identity and what are the use cases?
@IjemmaOnwuzulike
@IjemmaOnwuzulike 3 жыл бұрын
Functor identity is one of the laws that an object must follow in order to be considered a functor. So a quick way to tell if an object is a functor is to see if it doesn't change in shape or value after its mapping interface has been called on it. A mapping interface would be the strap "map" function or the promise "then" function
@quickfingers5982
@quickfingers5982 3 жыл бұрын
@@IjemmaOnwuzulike thank you very much! are we saying that we only implement identity so it's satisfied a functor? in a real world we don't use it?
@IjemmaOnwuzulike
@IjemmaOnwuzulike 3 жыл бұрын
It's more like a characteristic of an object that needs to be present in order to be considered a functor. It's like how for a car to be considered a car it needs four wheels, a steering wheel, an engine, etc. There are properties (or satisfied laws) that an object must have to be a functor. This topic me a while to get used to let me know if you have more questions!
@quickfingers5982
@quickfingers5982 3 жыл бұрын
@@IjemmaOnwuzulike this is all good. Thank you! appreciate it.
@parkerbordeaux7388
@parkerbordeaux7388 7 ай бұрын
Calling this a functor is the silliest thing I’ve ever heard in my life
@jewulo
@jewulo 3 жыл бұрын
Why are you calling a container data structure a functor. This just seems like a ruse for FP people to sound like they are smarter than everyone else. IMHO.
@IjemmaOnwuzulike
@IjemmaOnwuzulike 3 жыл бұрын
tbh people who use the term casually in everyday technical discussions might be showing off, but there's value knowing vocabulary associated with common data structures
What is a Monad? - Computerphile
21:50
Computerphile
Рет қаралды 590 М.
Higher-order functions - Part 1 of Functional Programming in JavaScript
10:49
Разбудила маму🙀@KOTVITSKY TG:👉🏼great_hustle
00:11
МишАня
Рет қаралды 3,9 МЛН
Follow @karina-kola please 🙏🥺
00:21
Andrey Grechka
Рет қаралды 24 МЛН
An Intuitive Introduction to Monads in Under 10 Minutes
7:33
shelljump
Рет қаралды 77 М.
What the Functor? | Functors in Scala | Rock the JVM
24:43
Rock the JVM
Рет қаралды 11 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Haskell: Monads. A 5-minute introduction
5:19
Stephen Edwards
Рет қаралды 47 М.
Easy Ways to Loop Over Objects in JavaScript
11:21
dcode
Рет қаралды 7 М.
A Sensible Introduction to Category Theory
26:20
Oliver Lugg
Рет қаралды 417 М.
Object Oriented Programming vs Functional Programming
18:55
Continuous Delivery
Рет қаралды 744 М.
Apple Pencil Nasıl Yapılır?🤯
0:13
Safak Novruz
Рет қаралды 956 М.
Индуктивность и дроссель.
1:00
Hi Dev! – Электроника
Рет қаралды 1,5 МЛН
Полный обзор iPad Pro M4 - хвалю!
26:27
Rozetked
Рет қаралды 170 М.
Apple, как вас уделал Тюменский бренд CaseGuru? Конец удивил #caseguru #кейсгуру #наушники
0:54
CaseGuru / Наушники / Пылесосы / Смарт-часы /
Рет қаралды 4,2 МЛН