# 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 program state. In this style of programming, side effects and mutable data are deprecated.

793 questions
84 views

### Solving Knight's Travails Problem without using vector for position

I'm trying to implement a solution to the The Odin Project - Project 2: Knight’s Travails in Clojure (Functional Programming) based on the solution posted by benjdelt. I would like to know your ...
47 views

### Time travelling through state history with persistent consequences

I am working on a game written in Kotlin that has a state management system similar to Redux. The state of the game is kept in a single place and is represented as immutable data classes (no logic). ...
114 views

### Combinatoric problem in Haskell

I am new to functional programming. Just now I solved my first "real world" task using Haskell and now I'm wondering whether I got it "right" and what can be improved. The problem arises from tensor ...
265 views

### Quadratic Equation Solver v2.0 in Javascript using Functional Programming

I have posted this in continuation to my earlier post Quadratic equation solver in JavaScript. Tried to improve on the shortcomings last time and also changed the logic. It is still not covering all ...
76 views

### Processing a list of pairs of items using promises and functional programming

I posted an answer on StackOverflow which I believed to be adherent to the principles of Functional Programming. However, I was told by the original asker that it was not 'functional' as my function ...
233 views

### Recursive solution for Longest Substring Without Repeating Characters written in Elixir

Here's my recursive implementation of a sliding window algorithm to find the longest substring of a given string without repeating characters. Is there a more idiomatic-Elixir way to write this? <...
87 views

### Transforming data from an API using Typescript and Lodash

As a front-end developer, I am given the following result from an API, an array of objects that looks like: ...
87 views

### Is It In Its Prime?

Just because I'm bored, I wrote yet another prime number generator. I think it's pretty clean, but I won't be surprised if someone finds something to comment on. ...
34 views

### Javascript RPC Call Handles Data and Returns DB Response

I have a service within a larger set of microservices that's handling a RPC call. My function mainly just parses through the request, uses the data to insert data into our MongoDB database, and then ...
73 views

### Extending functions to tuples

Intro: Imagine you have defined addition on types A and B with function A add(A,A) and <...
58 views

### Create a collection of functions tupled with a collection of parameters, and execute the collection in order in Scala

I am trying to create a collection of Unit functions that have any arity and type, and will execute them in order. This is the working implementation that I have: ...
205 views

### Check Is Anagram Scala HashMap based implementation

Here is the HashMap based implementation of the function checking whether two strings are anagrams: Example: ...
57 views

### Pure functional code for the sublists of a list

The code below gives me the list of sublists of a list. Code can still be improved to avoid the use of append, right? ...
170 views

### Lorentz Attractor visualization using functional programming

I have been working on this Lorenz Attractor visualization for the past day. I am currently also trying to change my coding style into a more functional programming one. I find it quite hard, to be ...
53 views

### Collecting a list of documents from a factory for an AngularJS controller

With this controller I'm injecting myFactory and using Array.push() to add the array ...
47 views

### Inspectors & Deconstruction on Unions in a list

I am still new to functional programming and found myself trying to filter and map a list of discriminating unions. I could be wrong, but it started to feel very unnatural to do this. I just couldn'...
42 views

### Storing facts for logical questions

I am writing a crude artificial intelligence program. I am happy with my program's ability to file away new word in ways that will allow logic to be done on them. Before I start expanding the logic ...
340 views

### Scala tic-tac-toe no mutable state

The following was an exercise for me to try to understand how state can be passed down the stack without immutability. I'm used to writing java code and this is just a way for me to understand. I've ...
89 views

### Deep filter value using functional programming principles

deepFilter function uses a predicate to filter properties which may be nested deeply in the given ...
25k views

### Passing a generic function as parameter

Ran into this idea and I'm curious if it's possible. I'm trying to make a single function that can test ALL of my sorting algorithms dynamically. I want to be able to pass the sorting function as a ...
208 views

### Equation parser + solver

Here is an equation parser that I just wrote. My focus was on readability and the prospect of adding new features in the future. Since I like a somewhat functional style, I also gave type annotations, ...
55 views

### Update the idx values if vals element match between consecutive rows

I want to update the numbers in idx field if there is any matching letter between the vals from two consecutive row. ...
293 views

### Implementation of Permutation Algorithm A from Topor, 1982

This is Algorithm A from Functional Programs for Generating Permutations (Topor, 1982). The author states that the algorithm was described in TAoCP Vol 1. We have implemented Algorithm A in F# as ...
191 views

### Porting functional programming code to Linq

I am very new to C# programming, so for practice I thought I would try to port a simple haskell function over to Linq. From learn you a haskell, there is the following implementation of powerset: <...
260 views

### Eloquent Javascript exercise: find average age from ancestors array per century

I solved an exercise from the book "Eloquent Javascript". I want to share with you guys the solution. The exercise is from chapter 5. Summing up, I have to find the average age from the ancestors ...
86 views

### Immutable Queue with Bulk-Enqueue

I recently needed a data structure with FIFO queue semantics that supported efficient bulk-insertion (often need to enqueue thousands of messages at once). I took a look at Purely Functional Data ...
131 views

### Advent of Code 2017 Day 6 (part 2) in Functional Programming (FP)

I wanted to practice functional programming (FP) without using any library but using vanilla JS only. So I took a problem from Advent of Code (the 2nd part of Day 6). You can only access the 2nd part ...
250 views

### Voting plugin for an IRC bot

MetaBrainz has an IRC channel called #metabrainz on which there's a bot called BrainzBot running. It provides utilities such as linking to JIRA issues or Github PRs ...
355 views

### Count the number of digits in an integer using F# and log10

This code counts the number of digits in an integer. let digitCount number = (int) (log10 ((float)number)) + 1; For instance, it tells us ...
141 views

### Advent of Code 2017 Day 6 (part 1) in Functional Programming (FP)

I wanted to practice functional programming (FP) without using any library but using vanilla JS only. So I took a problem from Advent of Code (the 1st part of Day 6): http://adventofcode.com/2017/day/...
53 views

### Advent of Code 2017 Day 5 (part 2) in Functional Programming (FP)

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took a problem from Advent of Code (the 2nd part of Day 5): https://adventofcode.com/2017/...
87 views

### Advent of Code 2017 Day 5 (part 1) in Functional Programming (FP)

I wanted to practice functional programming (FP) without using any library but using vanilla JS only. So I took a problem from Advent of Code (the 1st part of Day 5): An urgent interrupt arrives ...
78 views

### Advent Of Code 2017 Day 4 (part 2) in Functional Programming (FP)

I wanted to practice functional programming (FP) without using any library but using vanilla JavaScript only. So I took a problem from Advent of Code (the 2nd part of Day 4) You can only access the ...
73 views

### Advent Of Code 2017 Day 4 (part 1) in Functional Programming (FP)

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took a problem from Advent of Code (the 1st part of Day 4): A new system policy has been ...
39 views

### Assign value based on 100s of switch statement

In the following code I have potentially hundreds of possible cases. (This is just a small subset.) Is there some way to more effectively set state.dimensionQty ...
36 views

### Elixir SQL Query Returning Structs or Counts

I have a few raw queries which are similar to each other in that it is mostly duplicate code with the difference being that one returns structs and the other returns counts of how many there are. How ...
93 views

### Advent of Code 2017 Day 3 (part 1) in Functional Programming (FP)

I wanted to practice functional programming (FP) without using any library but using vanilla JS only. So I took a problem from Advent of Code. https://adventofcode.com/2017/day/3 You come across ...
87 views

### Advent of Code 2017 Day 2 (1) in Functional programming (FP)

I wanted to practice functional programming (FP) without using any library but using vanilla JS only. So I took a problem from Advent of Code - i.e. Day 2: Corruption Checksum (below is the 1st part ...
97 views

### Advent of code 2017 Day 2 (2) in Functional Programming (FP)

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took a problem from Advent of Code (the 2nd part of Day 2): https://adventofcode.com/2017/...
59 views

### Advent of code 2017 Day 1 (1) in Functional Programming

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took a problem from Advent of Code: https://adventofcode.com/2017/day/1 The captcha ...
283 views

### Project Euler 7: 10001 Prime in Functional Programming (FP)

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took a problem from Project Euler: By listing the first six prime numbers: 2, 3, 5, 7, 11, ...
190 views

### Project Euler 8: Largest product in a series in Functional Programming (FP)

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took a problem from Project Euler: The four adjacent digits in the 1000-digit number that ...
137 views

### F# Operation Framework (Railway-Oriented Programming + Task/Async/Lazy)

I recently published the initial version of what is effectively my first open-source software package, a Railway-Oriented Programming Framework for F# that encapsulates Tasks, Async Workflows, and ...
305 views

### Project Euler 6: Sum square difference in Functional Programming (FP)

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took a problem from Project Euler: The sum of the squares of the first ten natural numbers ...
93 views

### Project Euler 5: Smallest multiple in Functional Programming (fp)

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took the a problem from project euler: ...
157 views

### Project Euler 4: Largest palindrome product in Functional Programming

I wanted to practice functional programming (fp) without using any library but using vanilla JS only. So I took the 4th problem from project euler: A palindromic number reads the same both ways. ...
279 views

### nom Parser in Rust

I'm attempting to make a parser using nom in Rust. Nom implements parser combinators, so more complex parsers are built from simpler parsers. Because of this, I've started with a simple ID token ...
666 views

### Sum of Even Fibonacci numbers in functional programming

I want to solve this problem in functional programming (fp) way only. Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 ...