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
0answers
34 views

Sort ascending/descending functionally

I've been trying to get into functional programming with javascript and have tried to make some experiments with currying and function composition. What I've played with so far is a sorter function ...
3
votes
1answer
1k views

Binary search tree in C++, and display, search and delete functions

I feel ready to show you my work on creating BST in C++ using double linked list and 3 more functions for manipulating the tree. There is also one more function checking if the tree is real or not. ...
1
vote
1answer
363 views

Graph implementation in C++ using adjacency list

there is my final code for implementing a Graph in C++ using adjacency list and Object-oriented. I got some help from StackOverflow and it was really helpful, but now I would ask about some advice for ...
2
votes
1answer
114 views

String compression algorithm using functional JavaScript

I've written an algo to compress a string eg. aabcbbba to a2bcb3a I'm pretty new to functional programming, I feel it's easier to debug and learn from functional code if you're good at it already, ...
2
votes
0answers
48 views

Monadic implementation of asynchronous tasks (hidden overhead of threads)

So, I've been reading about monads and I wanted to see if I could implement a system for asynchronous computation in a monadic way. I came up with two solutions: The first one spawns a thread for ...
1
vote
1answer
132 views

Python implementation of Quicksort using list comprehensions

I wrote an implementation of quicksort that I think is pythonic. I based it off of this common Haskell implementation: ...
1
vote
1answer
113 views

FizzBuzz with Lambda Expressions in Java

I wanted to create a FizzBuzz in Java that is supposed to be open for extension. So the initial problem is the good old, if divisible by 3 print fizz, if divisible by 5 print buzz, if divisible by ...
1
vote
1answer
177 views

C++ heap CPS: Continuation Passing Style with Recursion

I am willing to see how to write readable and efficient continuations on the heap in c++. I am not quite satisfied. The following is just an exercise: it is coded for fun. I post the code here ...
7
votes
1answer
73 views

Monadic list for a more functional approach to C#

I am learning about monadic structures and have created a sort of monad list that implements the map and binding "operators" (or technically methods) in C#. I understand that Linq already exists and ...
4
votes
1answer
89 views

Implementing parser combinators in a functional manner

I am just starting on my journey of learning clojure (I have just read to the end of chapter 3 in clojure for the brave and true). So for practice, I wrote some parser combinator functions. I am quite ...
2
votes
0answers
98 views

Lexer function to handle the '/' character

I'm writing a toy compiler, which is in a very early stage of development. The lexer contains the following block of code: ...
9
votes
4answers
3k views

Functional approach to splitting list into sub lists

Here is my functional approach to split a list into sub lists, each having non-decreasing numbers, so the input \$[1; 2; 3; 2; 4; 1; 5;]\$ computes to \$[[1; 2; 3]; [2; 4]; [1; 5]]\$ The code ...
1
vote
2answers
59 views

Project Euler - multiples of numbers

I'm trying to learn functional programming and Scala, following through Project Euler problems. I'm solving get the sum of multiples x & y in a list. So for a list ...
1
vote
1answer
29 views

Creating the design matrices for a canonical correlation analysis

I have this code to generate symmetric matrices for testing how the design of the canonical correlation analysis I am performing works out. This is a extension of this solution Each row of the matrix ...
11
votes
1answer
114 views

Counting times a file was committed to Git

A long time ago I implemented some code to walk the git commit graph. I recently updated the accompanying analytics part of the code base to follow file moves/renames in order to get a more accurate ...
4
votes
1answer
123 views

F# Idiomatic Log4Net Wrapper

I put together a log4net wrapper that more closely resembles F#-idiomatic logging functions. The basic idea is that there's a Log module that defines a set of 8 ...
0
votes
1answer
231 views

JDBC wrapper in a functional manner

I implemented a simple Java JDBC wrapper in Kotlin with Arrow functional library. ...
3
votes
2answers
55 views

Utility functions for processing tweets or texts

I have 4 functions that process texts or tweepy.models.Status object (this object stores text information, author information, retweets & likes information of a ...
3
votes
0answers
252 views

Time distribution of Twitter data

The tweepy.models.Status class creates a 'tweet' object, it has attribute .created_at which is the posting time of the tweet in ...
1
vote
1answer
111 views

Models for analysing Twitter data (*which based on tweepy package)

I have three modules here models.py, functionals.py, and adjustment.py. These three may be ...
6
votes
1answer
133 views

Calculating relay operating times, according to IEC 60255

The script below is used to determine relay operating times, as defined in the standard IEC 60255. The equation and relevant information can be found here. ...
3
votes
1answer
98 views

Quicksort in JavaScript, using nested functions

I come from Java/Swift environment. So, I'm used to show the user of my code only "what is necessary". For JavaScript I use Visual Code. When I try to use the Intellisense feature, it shows all my ...
1
vote
1answer
109 views

Generic function for loading a function from a DLL library

I am trying to write a generic function for loading a function from a DLL library. I am in no way an expert on DLLs, that is why I ask. We have discussed it first in my Stack Overflow question to ...
3
votes
1answer
144 views

Decorate instance method with (arbitrary) meta data in python

Requirements What I need: attach meta information to methods, such that it is 'easy' to retrieve all such methods for a given class instance methods can still be called 'in a normal way', e.g. ...
1
vote
1answer
122 views

JavaScript debounce function

I built one JavaScript debounce function. I need a JavaScript expert's opinion if this is the correct way to do it, and if not, then what the flaw is in this current function. ...
1
vote
4answers
162 views

Hackerrank Day 9: Recursion

Write a factorial function that takes a positive integer, N as a parameter and prints the result of N! (N factorial). Note: If you fail to use recursion or fail to name your recursive function ...
2
votes
0answers
95 views

A simple tokenizer in Erlang

I'm trying to learn Functional Programming and I picked Erlang because I will have to use it eventually. In the meantime, I'm trying to build a simple lexer to stumble upon problems and solve them ...
3
votes
1answer
688 views

JS calculator module using functional programming

All of the code is self-explanatory and pretty much complete. What the code does: Calculates using onscreen numerics and operators Validates any erroneous operations, such as 4 ** 8 or *9 Good ...
4
votes
0answers
65 views

Functional implementation of the Maybe Monad in JS [closed]

A while ago, I really wanted to have the Maybe Monad in my JS projects. I ended up trying to use Promises as a stand-in solution (using Promise.resolve as my unit, ...
4
votes
0answers
59 views

Hierarchy (Family Tree) Domain Model

I'm wanting to model a family tree in the F# type system. The basic requirements: A family tree is made up of family members A ...
1
vote
1answer
808 views

Numbers as Strings Multiplication Function in Swift

I was solving a problem 20, Factorial Digit Sum, on Project Euler. Factorial Digits Sum \$n!\$ means \$n \cdot (n − 1) \cdot \ldots \cdot 3 \cdot 2 \cdot 1\$ For example, \$10! = 10 \cdot ...
-2
votes
1answer
52 views

7 pass file erasure [closed]

I am an aspiring C++ programmer and I have been programming for a few years off and on but I don't have much usable knowledge. Right now I am working on filesystem safety so I decided to write an ...
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 ...
18
votes
2answers
6k views

Replacing Python Classes with Modules [closed]

I try to avoid using classes in Python as much as possible; if I don't plan on building on it, I don't build it in the first place. It helps me avoid Java-like classes like ...
4
votes
1answer
432 views

Functional Html builder

This is my third attempt to create a easy to use html builder because I wasn't really satisfied with the first one that wasn't extendable at all and even the one using dynamics wasn't much better. It ...
1
vote
3answers
77 views

Picking from a list of individuals based on their fitness values

I have this method that takes a list of my individuals (class has public field fitnessValue). I sum all fitnessValue and then ...
3
votes
1answer
34 views

Setting the position of a navigation highlight

How can I make my function better and favor functional programming style? On this single-page site I have a fixed navigation list. Each item in the list has a transparent background and I have a <...
2
votes
0answers
56 views

Business Rule DSL for Values in Domain-Driven Design

Following the patterns from the book Domain Modeling Made Functional, I am implementing a single-case union for the simple values in my domain model instead of using primitives. The union cases have ...
3
votes
4answers
106 views

Simplify form validation with function

In jQuery, I have been reluctant to create a better form validation, and I feel the time has come for me to do so. With that said, I have been using this particular type of form validation, and I ...
2
votes
1answer
81 views

Sorting texts by similarity in Clojure

This is my first attempt with a lisp language. I'd like your review to address the following points, already listed in order of relevance: Is my code making good use of standard library? Is my code ...
7
votes
0answers
94 views

Agent-based Immutable Map

I am in the process of removing the last few pieces of mutable state from an F#-based distributed system. Some of the remaining mutable state is a ...
7
votes
1answer
227 views

F# Either computation expression with while loop

I want to implement an Either computation expression in F#. The computation executes a function inside a while loop, and this function's return type is ...
10
votes
4answers
3k views

Apply a function to each element of a tuple (“map” a tuple)

C++ doesn't (yet) have a 'map' higher-order function, certainly not one which applies to a compile-time sequence of values like a tuple. We have std::transform, and ...
5
votes
1answer
234 views

Collecting YouTube links from a page

I wrote code for my needs (i.e. collecting YouTube links from a page) and it is simple, but now I just want to know what can I do just to make it a better and properly written one. For example, I ...
10
votes
0answers
674 views

Realtime concurrent Haskell MIDI buffer

Problem Background MIDI is a serial representation of control signals to a sound generator. Typically, a noteOn message initiates the attack phase of a sound at a given pitch. The note will ...
3
votes
3answers
168 views

Stopping an infinite stream with collection state

I took up a somewhat interesting challenge when I answered this question. The task is to collect the first occurrences of different types of animals from an infinite stream until you've caught them ...
3
votes
0answers
173 views

Refactored calls to an api using Ramda.js

This is the original code for accessing a service endpoint that returns information about a product. The exported methods of this module each take a single param of "id" and returns a Promise. I've ...
3
votes
1answer
86 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 ...
4
votes
0answers
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). ...
5
votes
1answer
118 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 ...