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.

Filter by
Sorted by
Tagged with
2
votes
1answer
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. ...
5
votes
2answers
296 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 ...
5
votes
2answers
192 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: <...
3
votes
3answers
274 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 ...
1
vote
0answers
91 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 ...
2
votes
0answers
132 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 ...
13
votes
1answer
341 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 ...
0
votes
1answer
375 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 ...
2
votes
1answer
142 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/...
0
votes
0answers
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/...
2
votes
1answer
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 ...
5
votes
1answer
81 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 ...
4
votes
1answer
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 ...
1
vote
1answer
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 ...
3
votes
0answers
40 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 ...
3
votes
0answers
94 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 ...
1
vote
1answer
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 ...
1
vote
1answer
98 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/...
2
votes
2answers
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 ...
1
vote
2answers
344 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, ...
1
vote
1answer
193 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 ...
1
vote
0answers
147 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 ...
2
votes
3answers
424 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 ...
2
votes
2answers
96 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: ...
2
votes
1answer
166 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. ...
2
votes
0answers
305 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 ...
8
votes
2answers
719 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 ...
3
votes
1answer
75 views

JavaScript moneyFormat() function

Using JSX syntax I wrote a function that takes either a float or an integer as a parameter and returns a formatted string. I'd like any feedback for refactoring the code. ...
4
votes
3answers
1k views

Sum of multiples of 3 or 5 using functional programming

I wanted to practice functional programming (fp) without using any library. So I took the 1st problem from project euler: If we list all the natural numbers below 10 that are multiples of 3 or 5, ...
3
votes
1answer
68 views

Multi-field sorting

A function to sort data on multiple fields. I welcome feedback. ...
8
votes
1answer
212 views

Cookie Clicker Switches

In Cookie Clicker there are Golden cookies, and Wrath Golden Cookies. Golden cookies are Clickable cookies that randomly appear, and when clicked they give Bonus cookies, or temporary boosts to ...
2
votes
1answer
145 views

Sorting elements in array with a certain condition

This is what I have: function get_create returns a link with new filtered/sorted properties: Code on screenshot ...
1
vote
0answers
169 views

WebSocket based API library in Julia

I made a very bare-bones API "library" in Julia which should abstract the interaction with the API. The API is fairly complex - it's based around 2 core layers an HTTPS/REST API for general ...
0
votes
2answers
73 views

JavaScript recursive zip function

Could the performance of this function be optimized (without making the code much longer)? The function zips two arrays into another. ...
5
votes
1answer
135 views

First all zero row of a matrix in C++

The problem of finding the first all zero row in a NxN matrix was featured in a letter to the CACM in 1974 by Frank Rubin who claimed it was a problem for which using a ...
4
votes
2answers
842 views

Wrath Cookie Switch for Auto Golden Cookie Clicker

Sometimes you feel like a wrath cookie and sometimes you don't. Here is a function that I created that will run on an interval, so all I have to do is set a boolean when I want to switch between ...
0
votes
1answer
136 views

Conway's Game of Life in JavaScript sprawling iterative function

I'm new to JS, React and functional programming and am trying to make the Game of Life in React. My cycle function looks like iterative sprawl but all my attempts to refactor have been equally bad. ...
1
vote
1answer
45 views

Implement 'Foldable' on NonEmpty

Given: data NonEmpty a = NonEmpty a (Array a) I completed the following exercise from PureScript by Example: Write a Foldable instance for NonEmpty. Hint: ...
6
votes
1answer
962 views

Function composition in Python3

I wanted to implement a version of rambda's compose function in python. I also implemented some examples to show its working. However, I would like the community's input on my code: These are the ...
1
vote
0answers
45 views

Creating and manipulating a map for a text based game F#

I have put my whole code so far below, but what I am most interested in is how best to implement the map and utilise it. Any tips on organising my code and keeping it clean would also be greatly ...
1
vote
1answer
296 views

Vert.x application quickstart

I have created this repository that implements this OAuth2 flow. I wanted to use Java and create a minimal implementation of this flow with these goals in mind: Develop unit and integration tests in ...
1
vote
2answers
117 views

Reducing array to average readings

Taking the payload below, I need to output the average of each reading. For example the readings for key 2 are 1, 4, 7. The average is (1+4+7)/3 = 4. The data is formatted in multi-dimensional ...
6
votes
1answer
2k views

“Mars Rover” challenge

I have written the solution of the Mars Rover problem in JavaScript, with a sort of functional approach. I would like to know how I can improve it and if there are any additional edge cases I missed ...
0
votes
1answer
5k views

Getting the grandparent directory of the current code [closed]

I have this example: from os.path import dirname, realpath dirname(dirname(dirname(realpath(__file__))) And the chained ...
1
vote
0answers
47 views

Code which buffers objects and schedules saving them from buffers, after applied some actions to it

Originally i have a function like this: ...
1
vote
1answer
276 views

Take a number and sum its digits raised to the consecutive powers

I am new to Scala have to solve this problem: If you have number "xy" should equal sum of consecutive powers of its digits xy = x^1 + y^2 For example, take the number 89 and you should ...
1
vote
0answers
51 views

Custom indexeddb modules while trying to maintain the functional paradigm as much as possible

I'm a Web Development student, and I just started learning indexeddb a little while ago. At present my teacher hasn't taught us Promises, and I'm not really sure he plans to. So, I took the initiative ...
3
votes
1answer
205 views

Sorting a list of phone numbers by teleconference provider and location

I'm looking to order an array of phone numbers with a primary sorting criteria of whether the teleconference provider is correct and a secondary criteria of whether the the location of the phone ...
5
votes
3answers
68 views

Aggregate summary counts for an array of error objects

I'm doing some refactoring of someone else's code, and just want a second opinion, because of course I think my work makes it better, but some validation (or correction) would be helpful. Starting ...
0
votes
3answers
298 views

Binary search algorithm in Clojure

I'm absolutely new to Clojure (started learning it yesterday). After I went through some tutorials and checked out the basics I implemented the following Binary search algorithm: ...