Questions tagged [functional-programming]
Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the programme state. In this style of programming, side effects and mutable data are deprecated and usually strictly isolated.
746 questions
1
vote
1
answer
222
views
How should domain models be designed — rich domain models with encapsulated logic vs. anemic models with separate service/util layers?
I'm learning Domain-Driven Design (DDD) and studying different architecture patterns, and I’ve come across two seemingly conflicting design philosophies around domain modeling.
1. Rich Domain Model ...
4
votes
3
answers
314
views
The applicability of functional core - imperative shell to a cli program which contains a wrapper around a binary
Not long ago while I was exploring for solutions to test without mocks I've found out about the functional core, imperative shell architecture. It sounds great, I also think that it would play nicely ...
4
votes
5
answers
499
views
Anemic Models vs. Rich Models: When to Use?
I'm working on an application and have encountered two different approaches for organizing business logic. There's a general consensus that application rules should be handled in higher layers, so I ...
3
votes
3
answers
353
views
How to "pass through" data in a functional programming pipeline so that it's accessible later on in the pipeline
I am trying to refactor some JavaScript code to use functional programming principles.
I have some functions that I want to use in a series of maps.
const transformedData = rawData
.map(...
4
votes
2
answers
446
views
How to handle file I/O in a for loop?
(this question is written using javascript for examples)
Say I have a bunch of files that I need to access sequentially:
1.json
2.json
3.json
4.json
...
Say I want to transform the data in all of ...
2
votes
1
answer
332
views
Did the term "decorator" originate with OOP design patterns?
The Decorator pattern allows behaviour to be dynamically added to an existing object, effectively "decorating" it with new behaviour. While the pattern as formalised and named seems to have ...
2
votes
1
answer
155
views
OO vs FP: What is a good approach to understanding if heavy wrapper classes should be used?
Consider a processing system which ingests objects from an external source and performs extensive processing. One example could be objects detected by a computer vision system which are then fed into ...
6
votes
2
answers
1k
views
Object immutability and persistence
While I was learning functional programming I have encounterd two for me very similar terms: immutability and persistence. Also I have read simular questions from stackoverflow, but I am still ...
-1
votes
1
answer
136
views
When is the application of Kotlin infix functions appropriate? [closed]
The Kotlin language brings the simplification of function calls to the natural language. This article shows a nice example:
Function:
fun of(suit: Suit) = Card(this, suit)
val card = Rank.QUEEN.of(...
1
vote
3
answers
2k
views
Are "Distributed Enums" an Anti-pattern in non-OOP like they seem to be considered in OOP?
I have recently read about the so-called "distributed enum anti-pattern." In particular, as it relates to using enums in conditional statements. (The idea is apparently that if you were to ...
0
votes
2
answers
546
views
How to Represent Functional Boolean
.NET Boolean type usually makes if else pair all over the code.
Functional Boolean should be more like Either type. Ideally represented as Either<Unit, Unit>.
However, my issues with Either type ...
7
votes
1
answer
536
views
Can functional programming languages have deadlock conditions?
I am reading through "Clean Architecture: A Craftsman's Guide to Software Structure and Design" and it says that:
All race conditions, deadlock conditions, and concurrent update problems are ...
18
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 ...
5
votes
2
answers
508
views
Is it normal for names in functional programming to be extremely terse?
I am working on a compilers assignment in OCaml, and the following is an example of the pre-written code in said assignment:
(* Build a CFG and collection of global variable definitions from a stream *...
2
votes
2
answers
390
views
Modularity vs pure functions
I often come across this dilemma in my own code and wondered if there is a term for this and if there is a single solution to it. Let me illustrate it with a pseudocode example of making a table from ...
1
vote
2
answers
517
views
In what language does a method not return a value and a function does?
I don't know from where I got this but in my head a function returns a value and a method does not.
I know that with OOP a method is a function related to a class. But I am trying to remember where I ...
4
votes
2
answers
1k
views
How to organize a chain of functions that share parameters, functional programming
When trying to follow a functional programming paradigm, I often find myself in a situation where I have a chain of functions that I would want to combine/compose somehow, but they all also take in a ...
0
votes
2
answers
504
views
How to model transactions in a client-side functional DDD?
I'm new to DDD and I would like to clarify some concepts. I'm thinking about DDD in the client-side.
The first one is regarding transactions:
My understanding is that transactions are a responsibility ...
1
vote
2
answers
221
views
Should I add functionality by adding a new method to a class - or should I "register" the new functionality into a data structure?
I have one large class that computes ~50 different metrics (each metric has no side effects).
My code is similar to this:
class ReportingMetrics:
def __init__(self, data:pd.DataFrame, config:dict)...
0
votes
1
answer
1k
views
How to test a function with several conditional nested side effects
In Python, consider a function like the following:
def main(*args):
value1 = pure_function1(*args)
if condition(value1):
value = side_effect1(value1)
if value:
...
0
votes
2
answers
151
views
How to convert vehicle schedule time window calculation algorithm to FP
I am working on an algorithm that optimizes utilitization of a vehicle. What I have is a list of paths the vehicle is planned to take and between which times (time windows) it has to be at a certain ...
1
vote
2
answers
265
views
Connecting classes by passing method references
I am trying to find a good way of allowing two objects that are separated by a intermediate object to communicate while keeping the architecture loosely coupled. A solution I have developed is to pass ...
1
vote
3
answers
145
views
How to model a time-distributed process in functional programming style?
I'm searching for any formal/generic approach to modeling a process distributed in time with functional programming. Here is an example.
Let's implement a very simple notification service. It accepts ...
-1
votes
1
answer
108
views
Design suggestions for my simple data-analysis program
I need to create a program with the purpose of cross-referencing personal info from a spreadsheet(s), to check for conflicts of interest between clients of 3 different law firms. All of this client ...
9
votes
2
answers
5k
views
Database access with functional programming
I'm interested in becoming more familiar with functional programming as a paradigm, so I'm trying to introduce a more functional style to some of my projects. I'm struggling to understand how to ...