DEV Community

Discussion on: What is an idempotent function?

Collapse
 
cappe987 profile image
Casper

It took me a while to understand what you meant by f(f(x)) = f(x) because your example doesn't show that. For the formula to hold a function must return the same type as the input, while your example modifies the map without returning anything.

A better example of that is the absolute value function abs. Because abs(abs(x)) = abs(x). But that is not to say this is the only useful case, your example is definitely useful.

For the future, I can recommend to also explain why it's useful, why we would want idempotence in our code.

This post made me remember an old podcast episode I listened to a long time ago. I can recommend it if you want to learn a bit of the "why" of idempotence.
lispcast.com/what-is-idempotence/

Collapse
 
hzoltan profile image
hzoltan

Thanks for the constructive feedback Casper! Also major thanks for sharing Eric's podcast, it really helped me understand the big picture! I hope you don't mind but I edited the post according to your feedback. Thanks a lot and have a great day!