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.
742
questions
0
votes
2
answers
162
views
How to filter "locally and remotely" in functional programming
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 ...
3
votes
3
answers
223
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(...
5
votes
3
answers
531
views
Are "pipelines" in functional programming bad for time complexity?
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 ...
4
votes
2
answers
364
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 ...
0
votes
1
answer
145
views
(functional programming) What do you call a function that abstracts away a group of function calls?
(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 ...
2
votes
1
answer
204
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 ...
0
votes
1
answer
517
views
How could I apply the strategy pattern to a react component? [closed]
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 ...
2
votes
1
answer
129
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 ...
1
vote
2
answers
294
views
Why did TC39 name JavaScript's array predicate functions `some` and `every` instead of `any` and `all`?
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 ...
6
votes
2
answers
718
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
vote
3
answers
321
views
Scala Option vs. conditional branches
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 ...
-1
votes
1
answer
90
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(...
-2
votes
1
answer
687
views
Should I use function-based exports/imports or classes?
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 ...
1
vote
3
answers
1k
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 ...
1
vote
1
answer
206
views
Are there any drawbacks to partial application?
Consider the following Typescript code:
function exampleAction(target: Target, options: ExampleActionOptions) {
// ...
}
export function getExampleAction(options: ExampleActionOptions) {
return (...