this post was submitted on 21 Dec 2023
96 points (92.9% liked)
Programming
17333 readers
318 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
It took me a long time to really grok iterative methods like this, but once it clicks, you will absolutely know and feel like you have unlocked a new super power.
It starts with completely understanding that you are just passing functions as arguments, and those functions are being invoked, in a loop, for each item in the collection. Once you have that concept internalized, you should then learn the difference between filter, map, reduce, etc. The general difference boils down to: 1. How the iterator function changes the value being iterated over (most don’t) 2. What does the iterator function itself return (i.e. map itself, not the function passed into map. map and filter both return a new list, reduce returns the data structure being reduced into)
I would skip trying to understand reduce at first, though it’s the method you can implement all other such iterative functions with. The derivations like map and filter are just easier to start with.
And again, seriously, it took me like 2 years to completely internalize all of this, even after CS classes.