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
227 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
261 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
3 votes
6 answers
609 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
3 answers
320 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
79 votes
10 answers
17k views

How does a functional programming language, such as Elm, achieve "No runtime exceptions"? Coming from an OOP background, runtime exceptions have been part of whatever framework that is based ...
Fireburn's user avatar
  • 889
137 votes
5 answers
38k views

I'm a Sr. front-end dev, coding in Babel ES6. Part of our app makes an API call, and based on the data model we get back from the API call, certain forms need to be filled out. Those forms are ...
Brian Boyko's user avatar
  • 1,075
50 votes
9 answers
14k views

OK, so the title is a little clickbaity but seriously I've been on a tell, don't ask (TDA) kick for a while. I like how it encourages methods to be used as messages in true object-oriented fashion. ...
candied_orange's user avatar
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
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
187 votes
15 answers
90k views

I just learned about currying, and while I think I understand the concept, I'm not seeing any big advantage in using it. As a trivial example I use a function that adds two values (written in ML). ...
Mad Scientist's user avatar
64 votes
10 answers
31k views

After reading many posts explaining closures here I'm still missing a key concept: Why write a closure? What specific task would a programmer be performing that might be best served by a closure? ...
Bendrix's user avatar
  • 769
4 votes
5 answers
507 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
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
38 votes
7 answers
9k views

Encapsulation In object-oriented programming (OOP), encapsulation refers to the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an ...
Christopher Trotter's user avatar
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
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
118 votes
3 answers
116k views

In Java 8's java.util.function package, we have: Function: Takes one argument, produces one result. Consumer: Takes one argument, produces nothing. Supplier: Takes no argument, produces one result. .....
superbob's user avatar
  • 1,352
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
112 votes
3 answers
16k views

I've been doing some functional JavaScript. I had thought that Tail-Call Optimization had been implemented, but as it turns out I was wrong. Thus, I've had to teach myself Trampolining. After a bit of ...
Ucenna's user avatar
  • 1,312
16 votes
10 answers
7k views

I think the answer to the first part of my question is, "yes" -- no point in making objects immutable in a single-threaded application (or I guess in a multi-threaded application if that ...
releseabe's user avatar
  • 539
55 votes
11 answers
12k views

I have heard a lot of times when other developers use that phrase to "advertise" some patterns or developing best practices. Most of the time this phrase is used when you are talking about benefits of ...
Fabio's user avatar
  • 3,176
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
81 votes
14 answers
37k views

I feel that side effects are a natural phenomenon. But it is something like taboo in functional languages. What are the reasons? My question is specific to functional programming style. Not all ...
Gulshan's user avatar
  • 9,542
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
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
30 votes
18 answers
6k views

I am writing a program to simulate the activity of ants in a grid (PDF). The ant can move around, pick up things and drop things. The problem is while the action of the ants and the positions of each ...
71 votes
12 answers
9k views

I watched Stuart Sierra's talk "Thinking In Data" and took one of the ideas from it as a design principle in this game I'm making. The difference is he's working in Clojure and I'm working in ...
Daniel Kaplan's user avatar
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
58 votes
4 answers
13k views

I've been messing around with functional programming languages for a few years, and I keep encountering this phrase. For example, it is a chapter of "The Little Schemer, which certainly predates ...
Eric Wilson's user avatar
  • 12.1k
37 votes
7 answers
9k views

Let's say, I've the below logic. How to write that in Functional Programming? public int doSomeCalc(int[] array) { int answer = 0; if(array!=null) { for(...
Vicky's user avatar
  • 399
48 votes
7 answers
28k views

Say we have a normal pure function such as function add(a, b) { return a + b } And then we alter it such that it has a side effect function add(a, b) { writeToDatabase(Math.random()) return a +...
m0meni's user avatar
  • 803
40 votes
4 answers
14k views

I have seen that in imperative paradigms f(x)+f(x) might not be the same as: 2*f(x) But in a functional paradigm it should be the same. I have tried to implement both cases in Python and Scheme, ...
asgard's user avatar
  • 667
10 votes
4 answers
2k views

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 ...
Maletor's user avatar
  • 209
23 votes
11 answers
8k views

Using generators and lambda, we can do functional programming with Python. You can also achieve the same thing with Ruby. So the question is: why do we need specific functional programming languages ...
Joshua Partogi'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
65 votes
12 answers
21k views

During my four years at university we have been using much functional programming in several functional programming languages. But I have also used much object oriented programming to, and in fact I ...
Jonas's user avatar
  • 14.9k
24 votes
4 answers
13k views

I often find myself writing functions that look like this because they allow me to easily mock data access, and still provide a signature that accepts parameters to determine what data to access. ...
NightWatchman's user avatar
1 vote
1 answer
863 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
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
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
59 votes
12 answers
12k views

What language, in your opinion, allows the average programmer to output features with the least amount of hard-to-find bugs? This is of course, a very broad question, and I'm interested in very broad ...
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
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
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
19 votes
5 answers
8k views

On many articles, describing the benefits of functional programming, I have seen functional programming languages, such as Haskell, ML, Scala or Clojure, referred to as "declarative languages" ...
ALXGTV's user avatar
  • 1,555
10 votes
5 answers
9k views

Let's say, for example, that I have a function makeFoo that makes another function foo: function makeFoo(string) { return () => string } const foo = makeFoo('bar'); I know that makeFoo is a ...
Splox's user avatar
  • 209
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
88 votes
6 answers
62k views

OO programming literature is full of design patterns. Most books on object oriented programming dedicate a chapter or two to design patterns like factories and decorators. So what are the equivalent ...
user avatar
-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
63 votes
4 answers
23k views

What are combinators? I'm looking for: a practical explanation examples of how they are used examples of how combinators improve the quality/generality of code I'm not looking for: explanations of ...
user avatar

1
2 3 4 5
15