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
7 votes
2 answers
2k views

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 ...
sgp667's user avatar
  • 205
2 votes
1 answer
155 views

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 ...
Zazaeil's user avatar
  • 345
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
5 votes
1 answer
898 views

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 avoided,...
Cedric Reichenbach's user avatar
3 votes
1 answer
433 views

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 ...
schrödingcöder's user avatar
6 votes
3 answers
420 views

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 ...
schrödingcöder's user avatar
5 votes
1 answer
1k views

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....
Mohsen's user avatar
  • 209
4 votes
4 answers
503 views

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() ...
Jules's user avatar
  • 17.9k
1 vote
1 answer
1k views

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 ...
Ram's user avatar
  • 129
10 votes
1 answer
817 views

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

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 ...
alfonsodev's user avatar
1 vote
0 answers
87 views

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 ...
Vicky's user avatar
  • 399
1 vote
2 answers
921 views

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 ...
Vicky's user avatar
  • 399
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
2 votes
3 answers
969 views

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 ...
Vicky's user avatar
  • 399
5 votes
2 answers
772 views

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 ...
Chris Wohlert's user avatar
0 votes
1 answer
543 views

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 ...
deamon's user avatar
  • 886
-2 votes
2 answers
2k views

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 ...
Alex Gordon's user avatar
2 votes
2 answers
797 views

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 ...
Ucenna's user avatar
  • 1,312
7 votes
1 answer
5k views

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'...
Max's user avatar
  • 186
3 votes
5 answers
562 views

Playing with some 3d game stuff in my spare time in C++. C++ doesn't really lend itself well to fast, simple functional programming, and games where there is a lot of necessarily shared state don't ...
JohnB's user avatar
  • 1,252
3 votes
1 answer
257 views

When trying to turn a class with mutable state into an immutable one I am regularly having a hard time choosing between two alternatives: I can 1) either extract the state into another (immutable) ...
lex82's user avatar
  • 161
0 votes
1 answer
225 views

I just debugged a problem which proved to be that "and" evaluated both arguments before checking whether either was false. That's fine, not all languages handle x = (will_return_true() || loop_forever(...
Jon Chesterfield's user avatar
0 votes
2 answers
2k views

I am creating a multiple wrappers/layers API in Java that go like this public class Layer1<T extends Layer1> public class Layer2<T extends Layer2> extends Layer1<Layer2> public ...
Leon's user avatar
  • 207
44 votes
2 answers
11k views

Most functional languages use linked lists as their primary immutable data structure. Why lists, and not e.g. trees? Trees can also reuse paths, and even model lists.
Drathier's user avatar
  • 2,883
2 votes
4 answers
344 views

Aesthetically and mathematically a map(f, X) function seems great: in just two arguments it tells what is going to happen: we are going to use function f to transform each element from X to create a ...
A.L. Verminburger's user avatar
3 votes
2 answers
309 views

I am designing a library to wrap an API with Clojure. The API requires user credentials to authenticate user related calls. My first approach was to have functions that do each task the API can do: (...
Moon Cheesez's user avatar
12 votes
1 answer
577 views

The intuition of an optional type like Maybe Int is that either there is no Int (thus, there's Nothing there) or that there is some Int; there is something there. It makes sense to me that we call the ...
vijrox's user avatar
  • 276
1 vote
2 answers
452 views

I am currently reading Why Functional Programming Matters by John Hughes. In the "Gluing Functions Together" section, after having explained that (foldr f a) is a function that replaces all ...
nich's user avatar
  • 27
1 vote
1 answer
127 views

Below are oversimplified examples, but I wonder which route to take what is the best practice when designing API, the simple or the more complex and robust which is better? This looks good and goes ...
Jas's user avatar
  • 507
0 votes
3 answers
253 views

This is not (supposed to be) an opinion question, but it is a newbie question, so if there is just a resource I haven't found that I need to read, point me there :) I am in the design stages of a ...
Apollo's user avatar
  • 111
13 votes
2 answers
3k views

Pure functions are known to facilitate parellelizing. What is it about functional programming that makes it inherently adapted to parallel execution? Are compilers such as Javac smart enough to ...
Naveen's user avatar
  • 139
35 votes
5 answers
6k views

In many years of OO programming I've understood what discriminated unions are, but I never really missed them. I've recently been doing some functional programming in C# and now I find I keep wishing ...
Andy's user avatar
  • 687
17 votes
4 answers
3k views

How do I construct a system that has all of the following: Using pure functions with immutable objects. Only pass into a function data that the function it needs, no more (i.e. no big application ...
Daisha Lynn's user avatar
12 votes
1 answer
13k views

I'm going through this series. The author mentions that since state is maintained in object oriented programming, it is harder to write unit tests. He also says that since functional programming doesn'...
user avatar
2 votes
2 answers
546 views

I wonder if somebody tried creating a language where you can write mutations in a straightforward imperative style, and the compiler transforms the changes automatically to pure, Redux-style actions. ...
jdm's user avatar
  • 632
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
1 vote
3 answers
3k views

It seems the general consensus for unit testing classes is to test your object through its public interface only. So if you wanted to test the removeElement method on a LinkedList class you'd need to ...
user avatar
1 vote
1 answer
428 views

I'm working on a Scala project that uses DynamoDB for persistence, and does this by modelling the records as case classes. This is becoming increasingly more relational, which means we have classes ...
Matt's user avatar
  • 121
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
12 votes
2 answers
3k views

I see the benefits of making objects in my program immutable. When I am really deeply thinking about a good design for my application I often naturally arrive at many of my objects being immutable. It ...
lishaak's user avatar
  • 467
0 votes
1 answer
227 views

I was reading Memoization with recursion which tells how for a recursively defined function fun we can do memoization by: -- Memoization memoize f = (map f [0 ..] !!) -- Base cases g f 0 = 0 g f 1 = ...
RE60K's user avatar
  • 267
2 votes
2 answers
439 views

This is a question regarding how Multiple Dispatch works. Suppose that we have a type hierarchy like this: Drawable -> Shape -> Polygon -> Rectangle And there are three functions (This is ...
Mahdi's user avatar
  • 189
11 votes
6 answers
4k views

Reading through a scathing article on the downsides of OOP in favour of some other paradigm I've run into an example that I can't find too much fault with. I want to be open to the author's ...
Danny Yaroslavski's user avatar
7 votes
3 answers
1k views

Note: Still learning Haskell, not reached Monoids, studying Applicative Functors. I saw this implementation and I am not entirely clear on it: instance Applicative ((->) r) where pure x = (\...
RE60K's user avatar
  • 267
4 votes
1 answer
784 views

Following uses JavaScript code but F# is tagged for input from functional programmers. I understand that in functional programming we shouldn't mutate the state or incoming parameters but I'm ...
Devyiweid's user avatar
6 votes
1 answer
2k views

The functional interfaces in java.util.function cover the vast majority of common strategies one might want to apply, but it's also possible to define your own @FunctionalInterface instead. In cases ...
dimo414's user avatar
  • 403
19 votes
3 answers
3k views

I keep reading stories from developers who state that once they are able to get the FP programs written in languages like Haskell, Ocaml, Elm and even Rust, to compile without errors, they are pretty ...
vfclists's user avatar
  • 299
0 votes
1 answer
636 views

In many ways C# supports functional programming, but there is a (shrinking) list of features commonly found in statically-typed functional languages that are missing, such as tail recursion, partial ...
JamesFaix's user avatar
  • 272
3 votes
2 answers
257 views

In functional programming languages, such as Scala, data types and structures, are really important. I am in two minds about the use of type-defs in helping with the readability of the code ...
Maths noob's user avatar

1 2 3
4
5
15