Skip to main content

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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
225 views

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 ...
Penchala Yegu's user avatar
2 votes
1 answer
260 views

I’m designing a backend in TypeScript (could also apply to JavaScript), and I’m wondering about the architectural approach. Is it better to stick to a single paradigm (e.g., fully object-oriented or ...
dok's user avatar
  • 313
4 votes
3 answers
318 views

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 ...
 sentientbottleofwine's user avatar
3 votes
6 answers
608 views

I'm currently drafting a Python coding standard for internal enterprise use, primarily targeting business applications that involve heavy data access, reporting, and transactional logic. In this ...
agolta's user avatar
  • 77
4 votes
5 answers
505 views

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 ...
Azuos's user avatar
  • 49
0 votes
3 answers
261 views

My example applies to reading and deleting files (I/O), but this is probably a common scenario (eg, keeping local and global state in sync in functional programming). I am reading in files from a ...
rpivovar's user avatar
  • 263
3 votes
3 answers
353 views

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(...
rpivovar's user avatar
  • 263
5 votes
3 answers
708 views

This question is not meant to be a critique of functional programming, but more hoping for resources and opinions. I am refactoring some historically messy code so that it follows functional ...
rpivovar's user avatar
  • 263
4 votes
2 answers
446 views

(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 ...
rpivovar's user avatar
  • 263
0 votes
1 answer
190 views

(this question is written from a functional javascript point of view) say you have some pure functions: function a (arg) { ... return result } function b (arg) { ... return result } function ...
rpivovar's user avatar
  • 263
2 votes
1 answer
333 views

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 ...
Iain Galloway's user avatar
1 vote
1 answer
862 views

For the following component, how would I extract the unit logic to allow for composition? In my actual app I am trying to reduce the amount of logic encoded in the component and I have decided that ...
Tyler Kasper's user avatar
2 votes
1 answer
157 views

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 ...
panlex's user avatar
  • 265
1 vote
2 answers
366 views

Python, Ruby, Rust, Haskell, Kotlin, C#, C++, Perl, MATLAB, SQL, and R all call their respective array predicate checking functions any and all. Is there any record of why JavaScript's designers ...
Alex Ryan's user avatar
  • 127
6 votes
2 answers
1k views

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 ...
DimitrijeCiric's user avatar
1 vote
3 answers
510 views

If I'm writing Scala functions and have to check for nulls in situations where I can't avoid it (say, working with Spark UDFs and some legacy Java types), is it better to turn things into Option or to ...
wrschneider's user avatar
  • 1,369
-1 votes
1 answer
136 views

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(...
Nikolas's user avatar
  • 613
-1 votes
1 answer
1k views

What would make more sense, to use functions for exports/imports: // globals/helpers.js exports.fnOne = () => {} // features/user.js const {fnOne} = require() Or class-based approach with static ...
WebrJohn's user avatar
1 vote
3 answers
2k views

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 ...
user1713450's user avatar
1 vote
1 answer
261 views

Consider the following Typescript code: function exampleAction(target: Target, options: ExampleActionOptions) { // ... } export function getExampleAction(options: ExampleActionOptions) { return (...
kaan_atakan's user avatar
0 votes
2 answers
548 views

.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 ...
TIKSN's user avatar
  • 109
-1 votes
1 answer
70 views

I am interested in robotics programming. HW control often involves calculating the derivative or integration of the signal. It seems quite inevitable to avoid local states for such calculation. (Since ...
chanwoo ahn's user avatar
7 votes
1 answer
540 views

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 ...
Quantum Guy 123's user avatar
-2 votes
1 answer
183 views

Which paradigm(between OOP and Functional) should be chosen for a given task ? What are the tradeoffs between these two styles ? In which case using Functional makes sense and vice versa,in which case ...
Dennis's user avatar
  • 25
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
0 votes
2 answers
405 views

I have thought of this for a while and I want to know what you think about this. This is more of a way to structure the code that might not be 100% object oriented and that is not the purpose. I would ...
Cowborg's user avatar
  • 109
5 votes
2 answers
510 views

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 *...
SRSR333's user avatar
  • 335
13 votes
8 answers
6k views

I'm recently learning the programming language, and I wonder how compilers work when the language itself does not allow recursion, like how the compiler or the runtime checkers makes sure that there ...
csxyyyyy's user avatar
  • 151
2 votes
2 answers
390 views

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 ...
deSKase's user avatar
  • 139
-2 votes
4 answers
274 views

Programming languages traditionally have blocks that specifically cater to controlling iteration. There is the simple while-loop: while (i < 3) {...}; Then there is the more complicated for-loop: ...
Steve's user avatar
  • 12.7k
1 vote
2 answers
517 views

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 ...
houimli manel's user avatar
1 vote
2 answers
676 views

I am working on a project that is structured in hexagonal architecture. It is a multi module gradle project where web layer is a separate module that depends on the domain module. Sample code related ...
sidgate's user avatar
  • 133
4 votes
2 answers
1k views

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 ...
Cordello's user avatar
  • 423
0 votes
2 answers
807 views

I am implementing if/else statement, by using function "inCase" to make it more readable: const size = 'small' const equals = str1 => str2 => str2 === str1 const inCase = (obj) => ...
Djordje Vuckovic's user avatar
0 votes
2 answers
504 views

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 ...
João Otero's user avatar
1 vote
1 answer
135 views

My question is regarding using private type in F#. Consider the case we have some application and we have some library. One may consider using units within the library, and making them private behind ...
Just_Alex's user avatar
  • 111
1 vote
2 answers
221 views

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)...
MYK's user avatar
  • 343
6 votes
1 answer
520 views

I'm writing a parser for a markup language in haskell, and a finite state machine fell out of my ideal API. I have code that looks a bit like this: Token = BoldWord String | Word String | ...
user avatar
1 vote
1 answer
1k views

In Python, consider a function like the following: def main(*args): value1 = pure_function1(*args) if condition(value1): value = side_effect1(value1) if value: ...
pob's user avatar
  • 119
4 votes
2 answers
331 views

I have implemented the cows and bulls game in C++. The code: #include <cstdio> #include <cstdlib> #include <ctime> struct DigitMatches { int matches_in_right_positions; int ...
sshd's user avatar
  • 51
0 votes
2 answers
152 views

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 ...
Blaž Mrak's user avatar
11 votes
6 answers
3k views

I am developing a utils data engineering package in python, and for the sake of reusability and readability, I chose the functional programming (FP) approach. Assume a key task of converting data from ...
maaniB's user avatar
  • 221
1 vote
2 answers
266 views

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 ...
dda2120's user avatar
  • 21
1 vote
0 answers
172 views

A customer of ours has a rather large (500+ LOC) service as central part of the project. Written in C# and consisting of rather clunky large imperative style functions, I was asked to improve the test ...
Anders Bernard's user avatar
1 vote
3 answers
145 views

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 ...
Anthony's user avatar
  • 149
1 vote
2 answers
1k views

In short, "functional core, imperative shell" can be summarized as: functional core implements logic; you unit test it. Your tests call real functions just like in production real functions ...
Coderino Javarino's user avatar
-1 votes
1 answer
108 views

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 ...
boog's user avatar
  • 99
-1 votes
1 answer
99 views

Given the following hypothetical programming language: Intended for practical programming A simply typed lambda calculus (STLC) All objects are functions, based on Church encodings I am aware that ...
Ari Fordsham's user avatar
9 votes
2 answers
5k views

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 ...
Hassan's user avatar
  • 345
31 votes
3 answers
6k views

I'm trying to understand whether the Haskell and C++ communities mean different things by the word "functor", or if there's some underlying concept that unifies the two meanings. My ...
Stephen Warren's user avatar

1
2 3 4 5
15