Skip to main content

Questions tagged [pure-function]

A pure function is one that always evaluates to the same thing given the same arguments, and cannot change or depend on any external state.

11 votes
4 answers
1k views

Is it OK for a function to both do-something and return-something? I try to avoid it for the most part, but there are situations where trying to avoid it would lead to worse/less clean code. Ex: if ( ...
Newline's user avatar
  • 221
1 vote
5 answers
941 views

According to Origin of "a method should return a value or have side-effects, but not both", a method should either return a value or have side-effect, but not both. However, I often see some ...
wcminipgasker2023's user avatar
18 votes
5 answers
6k views

By definition, a pure function is deterministic + no side effect. Is there any example for a function which has no side effects, but is non-deterministic? I.e., a function without side effects, but ...
Helin Wang's user avatar
1 vote
2 answers
851 views

What's the difference between writing OO code that depends on internal state and writing a pure function that expects an argument that is a data structure of a specific type (and thus has internal ...
Andrew's user avatar
  • 119
2 votes
1 answer
444 views

The design pattern known as "functional core, imperative shell" is about separating side-effects from pure calculations, where business logic is supposed to be pure and then coordinated by ...
Olle Härstedt's user avatar
1 vote
3 answers
453 views

I have been using c# and trying to learn FP. In context of FP I often hear that usage of basic assignment or return statements are not considered composable, hence their usage is not advised in FP ...
rahulaga-msft's user avatar
5 votes
5 answers
631 views

OOP makes state reads and writes implicit. For instance, in Python: class Foo: def bar(self): # This method may read and/or write any number of self.attributes. # There is no way ...
Dun Peal's user avatar
  • 159
11 votes
2 answers
2k views

I am reading and hearing that people (also on this site) routinely praise the functional programming paradigm, emphasising how good it is to have everything immutable. Notably, people propose this ...
gaazkam's user avatar
  • 4,529

15 30 50 per page