2 ms·
Real general question about function composition - when you're comfortable with it, how do you think it to yourself, or say it to yourself, like what's your sho
by tunesmith 11y ago
Real general question about function composition - when you're comfortable with it, how do you think it to yourself, or say it to yourself, like what's your shorthand mental model?
I was able to really intuitively get comfortable with unix piping a long time ago, so instead of:
take 5 . filter p . drop 3
I'd be thinking, ok, take a thing, drop the first three, grep (or whatever), now take the first five. It felt intuitive because each step solved a problem, and then I'd move forward into the future, and have to only think of one additional solution (head -5) assuming I did the previous steps right.
Meanwhile, take 5 . filter p . drop 3 is in the opposite order, from right to left.
Maybe I'm just saying that left association is easier to think about than right association. Don't you feel that weird recursive bump in your head, the increasing mental stack, when you are dealing with function composition and right association?
- klibertp 11y agoI like imagining functions as various pipes, the real world ones. Compose is that short pipe that connects two others. I imagine that the data comes from the right and needs to be output on the left of the function. I then can read such line (take 5 . filter p . drop 3) twice. Once following the order of creation (ie. we're laying our pipes first) and then the second time in reverse, following the data and function applications. That did the trick for me when I first learned about function composition coupled with (auto)currying.