What Are Dependencies for Pure Functions?
Asked by
braided rug project
I'm delving into L2 coding principles, and I'm a bit stumped by a question asking to identify dependencies or needs for pure functions. As I understand it, pure functions shouldn't rely on anything external, so I'm unclear about what they mean. Can anyone give me some direction or insight?
Answers
Pure functions are all about having no side effects. They take some input and provide output without altering any external stateโlike global variables or files. They consistently return the same result for the same input every time. That's the essence of pure functions!
Reply to this answer
They might be getting at higher-order functions, which are functions that can take other functions as arguments. This means you can pass pure functions as dependencies to other functions.
braided rug project: Thanks! I'll definitely check out higher-order functions now.
Reply to this answer
It seems like they might be referring to how pure functions can call other pure functions. As long as each function involved is pure, then the overall function remains pure. Pure functions are really useful when you want to avoid changing data, like in parallel programming. Maybe that's the angle they were hinting at?
braided rug project: The course is an L2 certificate in understanding code design principles, basically a beginner's course. I thought I understood it all, but this one question about identifying dependencies for pure functions has been throwing me off. The only dependency I can think of is maybe using libraries to avoid side effects. Any additional insights would be great!
Reply to this answer
Add your answer
Answers are reviewed before publication.
braided rug project: Yep, I understand that! I'm trying to connect that idea to the question about dependencies, but the mention of higher-order functions might be the key.