Memoization is a fancy word for a function that uses cached results from previous invocations when it is invoked with the same input multiple times. It's just caching folks. Useful for speeding things up when you are otherwise doing the same thing multiple times.
Well remember though that you don't have to worry about cache invalidation because of stale data. Once cached you can store it for as long as you want.
You should do a whole series of tutorials in this exact format. Reminds me alot of how my cto helps me whenever i ask about something. Straight to the point, no fat, all meat and makes me fill in the gaps that flows by 👍
I'm used to memoization being explained with Fibonacci series, use the previous computation for the next one instead of doing the same work multiple times..
Returning functions confuses me so much. So, from what I get, you essentially return what in another language would be an object with member variables and a method? Something about this concept feels awkward to me. If I get it, you try to keep as much code as possible unchanged, while also adding caching, so uou beef up a function. That's what I understood. It's cool.
If you know OOP, consider how the Strategy pattern is just creating a dummy class to hold a method so you can pass the method around. Functions taking in functions as arguments are basically a generalisation of that. Except you don't have to bother creating a class just to pass a function around. And functions returning functions is similar to the OOP Factory pattern, just, again, with less fluff going on.
It’s basically a function pointer. When you called that returned function, the machine code jumps to where the variable points and executes from there.
It is a paramater of the function returned by memo(fn) function. So, in this case, it will be a parameter of complexFunction. To use this memo function we need to initialize new variable like that: let memoizedComplexFunction = memo(complexFunction). So xIn will be the parameter we pass to memoizedComplexFunction(). Correct me, if I'm wrong
@@m_nasyrif we’re passing complexFunction into memo, wouldn’t its parameters be just x? because x is the parameter of the callback passed into memo. which would be complexFunction. so I guess for anything to happen properly you would have to call it like memo(fn(x))(y) because memo returns a function which you can call and then pass in what i’m calling “y” there. that would be the xIn. but idfk why any of this is happening so
@@DekutardI mean, it was a quick and dirty explanation. He’s also using void as return for the passed in function, while complexFunction returns a value.
Memoization is a fancy word for a function that uses cached results from previous invocations when it is invoked with the same input multiple times.
It's just caching folks. Useful for speeding things up when you are otherwise doing the same thing multiple times.
well put
Yeah best explanation ive seen so far
Well remember though that you don't have to worry about cache invalidation because of stale data.
Once cached you can store it for as long as you want.
You should do a whole series of tutorials in this exact format. Reminds me alot of how my cto helps me whenever i ask about something. Straight to the point, no fat, all meat and makes me fill in the gaps that flows by 👍
Honestly this would be so helpful.
++
finding memo
Yep 👍 . Also it’s usually used with recursion algorithms to optimize tine and space. - Amy
There you -go- typescript!
Just finished reading Nyarlathotep as part of my journey through HPL's creations.
Time to learn again about memoization now, lol
I'm used to memoization being explained with Fibonacci series, use the previous computation for the next one instead of doing the same work multiple times..
I am now going to use this knowledge at my job, where i am developing React as a Java developer. Yes, I did learn React before learning JavaScript.
where did you get your degree?
--At Primeagen University (cool shades emote).
I know this isnt related to this video but does anyone know what software he uses to show his keypresses on screen?
Returning functions confuses me so much. So, from what I get, you essentially return what in another language would be an object with member variables and a method? Something about this concept feels awkward to me. If I get it, you try to keep as much code as possible unchanged, while also adding caching, so uou beef up a function. That's what I understood. It's cool.
If you know OOP, consider how the Strategy pattern is just creating a dummy class to hold a method so you can pass the method around. Functions taking in functions as arguments are basically a generalisation of that. Except you don't have to bother creating a class just to pass a function around.
And functions returning functions is similar to the OOP Factory pattern, just, again, with less fluff going on.
Functions are just objects in js
It’s basically a function pointer. When you called that returned function, the machine code jumps to where the variable points and executes from there.
isn't this just caching with extra steps?
What extra steps? Wrapping a function?
Should check Ruby
what the hell is xIn? i see nowhere it gets passed in.
That's the argument of the function that's returned.
It is a paramater of the function returned by memo(fn) function. So, in this case, it will be a parameter of complexFunction. To use this memo function we need to initialize new variable like that: let memoizedComplexFunction = memo(complexFunction). So xIn will be the parameter we pass to memoizedComplexFunction().
Correct me, if I'm wrong
@@zvezdanzvezdov1530I see that. but where would it ever get defined / passed in?
@@m_nasyrif we’re passing complexFunction into memo, wouldn’t its parameters be just x? because x is the parameter of the callback passed into memo. which would be complexFunction.
so I guess for anything to happen properly you would have to call it like memo(fn(x))(y)
because memo returns a function which you can call and then pass in what i’m calling “y” there. that would be the xIn. but idfk why any of this is happening so
@@DekutardI mean, it was a quick and dirty explanation. He’s also using void as return for the passed in function, while complexFunction returns a value.
Memoization is just memorization for nerds
YAY
I think you ment "a deterministic function" 😉
First..lessss go