All Questions
Tagged with functional-programming pure-function
23 questions
17
votes
5
answers
6k
views
Is there a non-deterministic function without side effects?
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 ...
10
votes
4
answers
1k
views
Functional architecture with lots of I/O
I'm learning about "Functional Core, Imperative Shell" as espoused by Gary Bernhardt in his talk about "Boundaries". In reality, it seems like these ideas have been known for a ...
1
vote
3
answers
403
views
what it means when someone says - "statements/instructions are not composable"?
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 ...
10
votes
2
answers
858
views
Why are impure functions said to be non-composable?
I understand what pure functions are and when someone says pure functions are composable - I believe it means that the output of one function can be passed as an input to another function but same ...
5
votes
5
answers
597
views
Implicit reading/writing of state in OOP hurts readability, maintainability, and testability. Good way of mitigating this damage?
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 ...
-1
votes
1
answer
142
views
Why are ReactiveX Operators considered functional?
I'm struggling to understand how a ReactiveX operator can be considered functional.
Operators are implemented as functions, but but with the exception of simple operators like map and reduce many of ...
12
votes
4
answers
3k
views
Why usage of assignment operator or loops discouraged in functional programming?
If my function meets the two requirements listed below, I believe that the function Sum returns the summation of the items in a list, where item evaluates as true for a given condition. Doesn't this ...
4
votes
1
answer
3k
views
Naming conventions for pure functions
Are there 'conventions' / best practices on naming pure functions?
For example:
adding numbers: add or sum?
calculating the square root: calcSqrt or sqrt?
reversing a list: reverse or reversed?
...
4
votes
2
answers
755
views
This functional programming example and what it means
I've been reading Out of the Tar Pit by Ben Moseley and Peter Marks and in section 5.2.3 they discuss state in functional languages compared to procedural languages. The procedural example is as ...
1
vote
2
answers
251
views
Functional programming: does using a generic make a function impure?
public static Func<string, Task<T>> MyMethod<T>(
UserCredentials credentials,
Func<string, string, string, Task<T>> func
) =>
async (value) ...
8
votes
2
answers
2k
views
Are all deterministic functions free of side-effects (and vice versa)?
I'm reading about pure-functions in functional programming and am wondering, whether a function being deterministic implies that the function is also side-effect free? (and vice versa?)
28
votes
5
answers
4k
views
Does catching/throwing exceptions render an otherwise pure method impure?
The following code examples provide context to my question.
The Room class is initialized with a delegate. In the first implementation of the Room class, there are no guards against delegates that ...
4
votes
1
answer
234
views
Is anything gained by making dependencies explicit via function argument lists when implementing pure methods?
This question is followup to this question.
Is there any benefit in avoiding the 'this' operator when implementing pure methods? That is, are there any advantages to making all dependencies explicit ...
2
votes
2
answers
639
views
Simulated functional programming in C -- passing the entire program state as a function argument
I have a struct called State which holds all the variables for the program. Rather than being modified by functions directly, it is the value returned.
Here is some code:
#define USERNAME_LENGTH 20
#...
2
votes
1
answer
338
views
Pure functions and the outer scope [duplicate]
Excuse my ignorance, I come from the C family of languages but zero exposure to functional languages. I've read that pure functions only generate output based on a given input. Same input gives the ...