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
34
votes
6answers
8k views

Do you need to think about encapsulation if you can ensure immutability?

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 ...
5
votes
4answers
516 views

Functional programming - what to learn and who uses it

I'm a .Net developer and Angular who's been working with OO languages throughout my education and work history. Lately I've been thinking about spending some time with one of the functional ...
1
vote
1answer
104 views

Is designing a generic parameterized class with methods of it accepting higher order functions a functional technique that we can use in Java 8?

Recently I have asked this question: How do you rewrite the code which using generics and functionals in Java 8 and mixing oop and functional programming by using only object-oriented? on ...
0
votes
1answer
78 views

Does the visitor pattern prevent the need to modify existing code when adding new data types?

From what I understand, the visitor pattern is supposed to solve the expression problem (described here), where a program needs to support performing multiple operations on multiple types, ideally ...
3
votes
1answer
268 views

Is there a UML diagram for functional programming?

For modelling software implemented with the imperative or procedural programming paradigm we have Flowcharts, process diagrams, etc. For object oriented we have UML class diagrams, object diagrams, ...
3
votes
3answers
157 views

Precisely define “what to solve” and “how to solve” corollary in functional and imperative programming respectively

I am not sure if I ever clearly understood standard corollary "what to solve" and "how to solve" used to point out difference between functional (declarative) and imperative programming paradigm ...
-3
votes
2answers
78 views

How can we handle inserts/delete cases using Map like data structures in FP?

Let's say, that we keep track of students entering the auditorium using their IDs(Key) and their check-in time(Value) in a Map. We delete the entries once they move out of the auditorium. I want to ...
0
votes
2answers
161 views

Example of NOT associative (not composable) function

Bartosz Milewski, in his book "Category Theory for Programmers" says that: Composition is associative. If you have three morphisms, f, g, and h, that can be composed (that is, their objects match ...
5
votes
3answers
3k views

Significant difference between functional and procedural collection handling [closed]

I'm planning an empirical study on function passing - specifically lambdas aka anonymous functions aka arrow functions. Now, although functional or even object-oriented approaches are highly favored ...
1
vote
0answers
48 views

Do MV* architectural patterns apply not only to OO languages but also functional languages?

I am learning about MV* architectural patterns, thanks to the help from several answers here. I learned that they are used for designing the architectures of user interactive applications. I also ...
-2
votes
3answers
249 views

Do functions make Java a functional programming language? [closed]

I have been struggling to understand programming paradigms. OOP is a paradigm with sole aim of modeling complex (real-world) systems, and it got me thinking: is OOP the only programming paradigm ...
1
vote
3answers
257 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 ...
2
votes
3answers
91 views

How should I best structure my app when I want to sort a “parent” model by a property computed on another “child” model?

Question about OO-programming, functional programming, NoSQL, SQL databases, and software architecture Hi all, I am a intermediate-level self-taught programmer, and have been dying to get an answer ...
7
votes
2answers
456 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
5answers
398 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 ...
0
votes
1answer
123 views

Representing mathematical tree structures using software in a compact manner

In my work I frequently come across systems of interdependent equations. I have contrived a toy example as follows. The terminal values w, x, y and z are given: e(y) = A+B A(y) = x*log(y)+y^z B(y) =...
0
votes
1answer
85 views

What do you call the state reducer pattern used by redux?

Redux uses a state reducer pattern where essentially you create a pure function that looks like: function reducer (previousState, action) { //... return newState; } This looks similar to ...
-1
votes
1answer
80 views

Why is it called a functional component?

A quick google search shows that the question I have has not been asked directly, and so I ask it here. For what its worth, I am learning react, and I come from a C++ background, where as far as I ...
2
votes
1answer
123 views

What's the benefit of avoiding partial functions in Haskell?

AFAIK in Haskell it is heavily recommended to avoid partial functions; and if these seem unavoidable (eg head) then return a Maybe. At least, so the Haskell wiki says 1 2 What's the use of the ...
0
votes
3answers
155 views

How do you enforce rules for the members of a collection in a non-OOP way?

When everything seems to be a collection, how do you enforce rules for members of said collection without the use of an interface? As far as I am aware, in languages that don't fully support OOP ...
3
votes
0answers
180 views

How to avoid passing configuration across functions?

I am writing module that other people can use in their code. It's a calendar. I want to allow users to set locale parameter so that they have month names and other data in language of their choice. ...
1
vote
1answer
84 views

Structuring a pipe for function composition when an intermediate result is needed by later functions

I have a set of pure functions that can be composed almost trivially in a pipe as initialValue -> [f] -> [g] -> [h] -> ... -> [m] -> [n] -> [o] -> outputValue The problem I ...
0
votes
1answer
109 views

Is duplicating, deleting, pushing, and/or an object to/between lists a code smell?

I'm thinking about a structure like this. cardGame: players: - john: hand: - card: id: 1 suit: diamond ...
-1
votes
1answer
67 views

Which programming paradigm mixes well with reactive in java? [closed]

So I have the feeling that one can forget object oriented programming when reactive streams are in use, due to the lack of the async-await syntax (because with the call chaining, the state has to be ...
3
votes
0answers
80 views

What's the use of interfaces vs classes in typescript?

In the company in which I work, it is customary to model entities using Interfaces when developing with Typescript. To me, it seems much more effective to model entities with classes and then ...
2
votes
1answer
287 views

FP Free Monad vs OOP Dependency Injection

I've written my first moderately large project in functional style (in F#) and can see the advantages. The main challenge was to achieve the "Onion" architecture i.e. large and "smart" pure core / ...
1
vote
1answer
98 views

Python - Paradigm to compute different formulas with the same function

I have different equations to compute the same quantity. For example, val = my_func(a, b, c) but also val = my_func(x, y), where my_func represents the quantity I would like to compute: it could be ...
0
votes
0answers
26 views

Alternative to bind for command validation

I am new to functional programming and I can't find the way to improve this pattern. I want my commands body as simple as this: firstValidation <| command >>= secondValidation >>= ...
0
votes
1answer
57 views

F# function like reduce that return different type

I am new to functional programming and I can't find a function like reduce to build an AgreggateRoot given an EventStream: List.reduce ((aggregate, event) -> aggregate) eventList As I understand ...
2
votes
3answers
139 views

Is it preferable to “compose” monadic functions or “chain” them?

To the best of my understanding Monads were created to allow for composing functions with those that had potential side-effects - loosely speaking. For me composition implies code like so: f(g(h(x)))...
1
vote
2answers
176 views

What is the difference in the implementation of a monad in a purely functional language with respect in an imperative language?

For a long time, the use of these Monad structures has been restricted to a very small circle of languages, many of them purely functional (mainly due to problems related to the management of the IO). ...
-1
votes
1answer
96 views

Reactive programming language [closed]

I had been using react-js and really like its concept so I want to know if there is a programming language/framework that sort of works like it. For instance, I want to define: var A = something var ...
2
votes
1answer
85 views

Functional Approaches to Serializing Objects to Variable-length Byte Array Output

I have a large number of record types derived from a binary format specification. So far, I've already written a computation expression builder that let’s me read structures from the files easily: ...
1
vote
3answers
230 views

What is a good method/practice I can employ to keep identical code snippits in two places in sync? Also, help documenting functionals

If I could get some input on the design of this, I would be grateful as well. Note that I'm programming in python. There's a function F that takes lots of data, runs some analysis on it (taking ...
2
votes
2answers
390 views

Java 8 - When should I use java.util.Stream instead of java.util.Collection?

I started studying functional programming with JavaScript. After this, I started to study it with Java 8 (streams, lambdas and method reference) and I realised that I tend to use streams as much as ...
9
votes
5answers
627 views

Best Practice - Wrapping if around function call vs Adding early exit if guard in function

I know this can be very use-case specific, but I find myself wondering this far too often. Is there a generally preferred syntax. I'm not asking what is the best approach when in a function, I am ...
2
votes
2answers
131 views

Swappable state object or decoupling data and functions

I come from OOP pradigm and I also know a bit about functional programming and its advantages. Over time I came to like the separation of data and transformations that are applied to it using pure ...
2
votes
2answers
130 views

How should I call splitted functions? centralize them? or call it one next to one?

According to Is it OK to split long functions and methods into smaller ones even though they won't be called by anything else?, I should split long functions into smaller functions even if they ...
0
votes
3answers
240 views

Should a method decide whether to execute or not? [closed]

I couldn't find a question on SE but it has probably been asked elsewhere already (in case, please mark it). A method containing code to run just with specific external conditions can: decide ...
-1
votes
2answers
117 views

Are executable requirements the most advanced form of declarative code?

The more declarative code is, the less explicit technical details it contains and the closer it gets to requirements expressed in domain language. In the extreme case, there is no more difference ...
4
votes
2answers
203 views

Should I define more methods to update necessary UI only, or less methods but update some UI unnecessarily?

For example, suppose my input data and UI is not in 1 to 1 relationship: html: <script> aChanged=function(){ }; bChanged=function(){ }; cChanged=function(){ }; </script> a:<input id=...
4
votes
2answers
433 views

How does understanding category theory help a software engineer?

This question is related but doesn't directly answer my question. I can imagine that understanding category theory helps someone who is designing a programming language, apparently in particular ...
1
vote
1answer
126 views

best practice for data.table use in “formal” code

Consider a "large-ish" data set (~2-5M rows) that goes through multiple stages of cleaning/processing: library(dplyr) largedat %>% mutate( # overwrite v1 based on others v1 = somefunc(...
0
votes
4answers
126 views

Is there a mismatch between XSL and OOP? [closed]

context and background: I prefer OOP for the most part and find it, largely, more intuitive -- this is my bias. When I read that functional language x is better than OOP language y I think to myself:...
8
votes
2answers
1k views

A real-life example of using curry function? [closed]

I was struggled to find a real-life example of using curry function and get the benefit of using curry. When I google curry function I often see the example like let add = x => y => x + y; ...
1
vote
1answer
182 views

Functional programming — changing correlating elements during list mapping

Consider I have a list. I want to iterate over it and map it's elements -- but the mapping might also require to change others than the element I'm currently iterating over. Let's say I have a switch ...
7
votes
2answers
444 views

Encapsulating moving parts in OO vs Minimizing moving parts in FP

I am from OO background just started learning FP paradigm. Came across quote by Michael Feathers - "OO makes code understandable by encapsulating moving parts. FP makes code understandable by ...
1
vote
5answers
450 views

Software design pattern for class method that only should be called once

Say I have a TypeScript class: export class TypeCreator { entities: Set<Whatever> registerEntities(e: Set<Whatever>): Set<Whatever>{ return this.entities = e; } } if ...
-1
votes
1answer
90 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 ...
1
vote
1answer
677 views

C++ immutable struct

I would like to be able to implement immutable data in C++. In short, given a C++ object in which I would like to modify a member variable, instead of modifying that member in place I would like to ...

1 2 3 4 5 14