4 ms·
JS is really good at FP, but it doesn't have any real concept of function purity and isolating side effects. Rust has constant functions, for one: https://doc.
by ovyerus 2y ago
JS is really good at FP, but it doesn't have any real concept of function purity and isolating side effects.
Rust has constant functions, for one: https://doc.rust-lang.org/reference/const_eval.html https://doc.rust-lang.org/reference/const_eval.html
- akira2501 2y agoDoes rust actually have pure functions? Also, I'm suspicious of the claim that compile time evaluation makes the language functional.
- TwentyPosts 2y agoCalling them 'pure' may be incorrect depending on how high your standards are. Rust functions (which don't take mutable references) are incapable of modifying anything you pass into them, and any sort of global state is heavily discouraged. This is pretty good as far as "pure" goes, but of course, they can perform I/O. (Then again, without any side effects a program would do nothing at all behind heating up your CPU, so this seems like a fair trade-off.) What makes Rust functional are the patterns you can use in the language, though. A lot ot of maps, a lot of filters, a lot of iterators and algebgaic data types and pattern matching.