How do I ensure a pure function only calls pure functions in TypeScript / JavaScript?

527 Views Asked by At

I want to embrace functional programming, and ensure that my pure functions not change state.

How do I ensure that a function that I intend to be pure only calls other functions which are themselves pure?

I see two ways, which have issues:

  • Commenting - The IDE doesn't easily show comments of functions when calling them
  • Naming - This would make for ugly function names

I'm looking for a way to enforce purity, not just hint at it.

Is there a language feature which would allow a function to be marked as pure, and prevent a marked pure function calling functions unless they themselves are also marked as either pure or pure-but-don't-check-deeper?

0

There are 0 best solutions below