Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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 ...

0
votes
0answers
58 views

What's the benefit of separating specialised data from behaviour in an algorithm?

Functional programming strongly suggests to separate data from behaviours (functions). However, I can't see the benefit of this for an algorithm's implementation intrinsically tied with particular ...
4
votes
2answers
195 views

Function that returns non parameter functions

I found a function in c# like this: private Dictionary<string, Func<string>> ObtenerExtraCfgCampo(MsgDefCamp camp) { var extra = new Dictionary<string, Func<string>&...
3
votes
1answer
46 views

REPL-based Workflow and Unit Testing

As a developer who has primarily been doing functional programming in F# for the last several years, I'm very attached to my REPL and use it run my code as I go, testing and refining each function as ...
1
vote
3answers
150 views

In Haskell, is it a “violation” of functional programming to interact with something that was not a function parameter?

I'm sure this must have been asked before, but I can't find anywhere that actually answers my question, so apologies if I have simply overlooked this. I am currently learning Haskell, and loving the ...
0
votes
1answer
103 views

In what other locations besides infinite streams and infinite lists is memoized lazyness useful?

Haskell is one of the few non-strict languages out there. In his paper Why Functional Programming Matters, John Hughes uses (memoized) lazy evaluation (as well as higher-order functions) to implement ...
3
votes
3answers
356 views

In functional programming, what it means “Order of evaluation does not matter” when function is pure?

In context of pure functions in FP, apart from several benefits mentioned like easy to reason about, testability it also says "order of evaluation does not matter" since output remains same for given ...
0
votes
0answers
131 views

How do functional programming advocates use a framework like React or Angular?

I read this blog post recently: The Two Pillars of JavaScript Part 1: How to Escape the 7th Circle of Hell, which is essentially a criticism of object oriented programming, and advocacy for funtional ...
1
vote
3answers
96 views

Is it allowed to throw a runtime exception from a java.util.Predicate

The java.util.Predicate interface contains the test(...) method, whose JavaDoc description states that it [evaluates] this predicate on the given argument and that it [returns] true if the input ...
0
votes
1answer
61 views

What is the correct granularity for events in the context of designing a rule-based decision system?

Introduction We need to design a system that, given a set of events that are happening in the source application, reacts to them and if some conditions have been met, actions can be triggered. Users ...
0
votes
0answers
23 views

Should I use “Map” or “Select” for new functor-like operators in C#?

I'm designing a type in C# that will be used as an algebraic type in a functional style, but is not a collection type and does not implement IEnumerable. If this type is a Functor, should I name its ...
2
votes
1answer
166 views

Naming conventions for pure functions

Are there 'conventions' / best practices on naming pure functions? For example: adding numbers: add or sum? calculating the square root: calcSqrt or sqrt? reversing a list: reverse or reversed? ...
1
vote
2answers
112 views

How can an iterative algorithm be controlled dynamically?

Suppose we need an iterative algorithm for mathematical optimisation. Each iteration takes a long and random time. After each iteration, a stopping condition is checked for the iterate x, based on ...
0
votes
1answer
117 views

Is the usage of flip function a smell for bad design?

Everything is in the title, is the usage of flip function a smell for bad design ? I'm coming from a JavaScript universe and used to work with lodash/fp or ramda. Recently, I've written some stuff ...
1
vote
2answers
222 views

Patterns for tracking state in recursive Haskell code

A frequent pattern in my Haskell code is element-wise recursion for transformation of a list with some carried state generated using the data in the list. Usually, this looks something like this: ...
3
votes
1answer
200 views

Are design principles of functional programming languages and current hardware (register-machines) contrary?

Functional languages seek to minimize accidental state (computationally-convenient but logically unnecessary data dependencies) by endorsing the most granularly modular, mathematically unambiguous ...
0
votes
1answer
119 views

for-loops vs x.Times(…) extension methods

Using C# as an example, extensions on IEnumerable to allow code like collection.Each(i => i.DoStuff) rather than a foreach loop are generally frowned upon, mainly because they don't follow LINQ ...
3
votes
2answers
342 views

In which programming paradigm can't code reuse be (easily) achieved?

In a video about software architecture that I'm watching, it's stated that the main program/subroutine architectural style promotes modularity and function reuse Code reuse is one of the main ...
3
votes
2answers
245 views

What is control abstraction in the context of functional programming?

I understand concept data abstraction as it is relevant to OO programming. However on contrary it seems Function Programming promotes or makes use of concept control abstraction. I tried searching ...
4
votes
3answers
274 views

Optimal Immutable Data Structure for Highly Dynamic Particle System

Trying to see if immutability is a good fit for highly dynamic objects like game entities (that constantly are moving around and changing) or particle systems, each which might have thousands or ...
9
votes
6answers
3k views

what can go wrong in context of functional programming if my object is mutable?

I can see the benefits of mutable vs immutable objects like immutable objects take away lot of hard to troubleshoot issues in multi threaded programming due to shared and writeable state. On the ...
7
votes
2answers
510 views

Do functional programming languages disallow side effects?

According to wikipedia, Functional programing languages, that are Declarative, they disallow side effects. Declarative programming in general, attempts to minimize or eliminate side effects. Also, ...
1
vote
0answers
104 views

Understanding transducers, why this is not a transducer

I'm currently learning functional programming and trying to learn a new concept : transducers. I'm actually getting the point of theory, like it's an advanced map/reduce that aims to provide better ...
4
votes
2answers
405 views

This functional programming example and what it means

I've been reading Out of the Tar Pit by Ben Moseley and Peter Marks and in section 5.2.3 they discuss state in functional languages compared to procedural languages. The procedural example is as ...
6
votes
3answers
1k views

Sample code to explain Banana Monkey Jungle problem by Joe Armstrong [closed]

In the book Coders at work Joe Armstrong stated that: I think the lack of reusability comes in object oriented languages, not in functional languages. Because the problem with object oriented ...
3
votes
2answers
419 views

Microservices with OOP and Functional Programming [closed]

After reading and using different concepts(right or wrong) questions related to modularity have appeared. I want to implement the microservice architecture in my projects the right way. As from ...
2
votes
1answer
58 views

Rendering and holding state changes in a web app with functional programming

Let's say you have a tic-tac-toe app. There's the game state which can be represented by an array of size 9. There's your "reducer" computes new state from old state and player actions. Then there's ...
6
votes
3answers
546 views

Sum Types vs Polymorphism

This past year I took the leap and learned a functional programming language (F#) and one of the more interesting things that I've found is how it affects the way I design OO software. The two things ...
1
vote
2answers
105 views

Comparing approaches of mapping data objects

Update: I added some diagrams to help understanding I had a discussion with a colleague about two different approaches in mapping data objects. I'd like to get your opinion on pros and cons between ...
0
votes
3answers
571 views

DDD: Event handlers and aggregates in functional programming

When implementing a DDD driven system (based on event sourcing) using a functional programming language (Clojure), should one separate event handler functions from aggregate functions? In my naive ...
2
votes
2answers
195 views

Functional programming: does using a generic make a function impure?

public static Func<string, Task<T>> MyMethod<T>( UserCredentials credentials, Func<string, string, string, Task<T>> func ) => async (value) ...
7
votes
2answers
813 views

Functional Programming best practices

I don't have a particular coding problem on hand this is just an excercise to improve my thought process. Few months back I started learning about functional programming( mostly in R) and I fell in ...
2
votes
1answer
95 views

Dynamic *dll substitution?

I got an architectural problem here. Let say there is an IShell. It mainly responsible to map user's commands (represented as a linux-like strings) to an appropriate IExecutable's. Those ...
42
votes
8answers
11k views

Return considered harmful? Can code be functional without it?

OK, so the title is a little clickbaity but seriously I've been on a tell, don't ask kick for a while. I like how it encourages methods to be used as messages in true object-oriented fashion. But this ...
4
votes
1answer
133 views

Is using Option#get really a bad idea here?

I'm working on a Scala project and Wartremover shows an error about Option#get usage in my code: Option#get is disabled - use Option#fold instead While I do understand how get should often be ...
2
votes
0answers
111 views

Dependencies between functions-only modules: hardcoding vs alternatives

In switching from a procedural background to "FP in the small, OO in the large" I'm grappling with the following problem. Suppose there're modules, each only containing numerical math functions ...
5
votes
3answers
234 views

Can referential transparency be assumed when dealing with floating-point arithmetic?

A pure function is assumed to produce the same outputs given the same inputs. Suppose an (otherwise) side-effects free function computes with floating-point numbers. Due to numerical error, these ...
4
votes
1answer
270 views

Should function composition and piping be tested?

Unit testing requires writing tests first then code, on the other hand in F# (and most of the functional languages) some codes are extremely short as follows: let f = getNames >> Observable....
3
votes
4answers
300 views

Why are functional-style chained map operations considered hard to read?

In the comments to an answer of another question, I proposed the following Java code as a better way of writing a more procedural-style variant of the same operation: employeeService.getEmployee() ...
1
vote
1answer
369 views

Does dependency injection fly in the face of functional programming?

I have the following pure function (f2 and f3 are pure too): class X { def f1(arg: Type1): Type2 = { val x = f2(arg) val y = f3(x) y } def f2... def f3... } Now, I would like ...
8
votes
1answer
369 views

Why most anonymous functions can't be JIT compiled and will never be optimized?

I just read https://techfindings.one/archives/2652 about functional programming and came accross this: anonymous functions can often not be JIT compiled and will never be optimized Can someone ...
1
vote
1answer
101 views

What does it mean “state complects value and time”?

I'm rewatching Rich Hickey great talk "Simple Made Easy" And around min 35:40 when talking about state, mentions that State complects value and time, but I'm not sure I'm understanding this well. Is ...
1
vote
0answers
73 views

How Functional Programming addresses concurrent increment/decrement operations invoked by different users? [duplicate]

Using Functional language, How can 2 different parties achieve the result of increment/decrement operations concurrently? For the below scenario, Let's say, I've 2 quantities in stock and 2 users in ...
0
votes
2answers
336 views

How Functional Programming addresses concurrent increment/decrement operations invoked by different users?

Using Functional language, How can 2 different parties achieve the result of increment/decrement operations concurrently? For the below scenario, Let's say, I've 2 quantities in stock and 2 users in ...
35
votes
6answers
6k views

What are the functional equivalents of imperative break statements and other loop checks?

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(...
2
votes
3answers
512 views

Can functional programming used for solving problems which require randomness?

This older question tells us that in functional programming "true" randomness cannot be achieved since in FP functions are pure/idempotent and return the same value irrespective of number of ...
5
votes
2answers
476 views

Has any language enforced Command–query separation?

As described here, a function can be said to be a query when it returns a value, and a command when it modifies a value. It also states that a function should not be both. That a query should not be ...
0
votes
1answer
157 views

java.util.function.Function as an interface for an mutable object

I have an interface with only a single method that could be replaced by java.util.function.Function from the JDK: interface DataModel { boolean apply(Map<String, Integer> input); } The ...
-2
votes
2answers
253 views

What does it mean to “wrap” a stored procedure?

My manager has asked me to "just wrap the stored procedure". The requirements are to create a microservice that will do the following: Accept parameters from the user. Pass those parameters to the ...
1
vote
2answers
351 views

What's the proper way to think about state monads?

I've been using a functional approach in my programming of late. I know that mutability and state changes are big no nos within the paradigm. I now find myself working with databases and other data ...
3
votes
1answer
1k views

Is there a better term for “functional method chaining”?

I'm writing a C# style guide for my team and I'm trying to describe the benefits of side-effect-free functional-style methods. I want to include online references to back up the suggestions, but I can'...