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

Advent of Code 2018 day 1 part 2: find the first aggregated number that occures twice

I am using the coding puzzels of https://adventofcode.com for improving my F# skills. Problem: Day 1 Part 2: Starting with frequency 0, a list of numbers should be added successive generating new ...
0
votes
1answer
84 views

find if one string is a valid anagram of another , in scala

Question is taken from leet code. Problem Given two strings s and t , write a function to determine if t is an anagram of s. Examples ...
2
votes
1answer
320 views

Longest Substring Without Repeating Characters in Scala

Question is taken from Leetcode and solution works for their test cases. I do see a scope of improvement and make it more functional (getting rid of vars and mutables data structures). Please suggest ...
1
vote
1answer
37 views

Stack Exchange API Reader

I've been working on some code to pull questions from the realtime feed on stackexchange.com and query more information about them from the API. It works, but I'd love some feedback on how I could ...
0
votes
1answer
80 views

Functional List in C++ [closed]

This is rather toy example of immutable datatype in C++. I've tried to follow functional languages like Scheme, Racket - making list as a cons cell: list is list or is empty. ...
2
votes
0answers
43 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
3k 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
619 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
358 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
49 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
285 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
165 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 ...
2
votes
1answer
104 views

Manipulating arrays to extract unique objects and count occurrences

The data describes cycling activities (key1) and chunks of them (key2). In total there are around 1,000 ...
1
vote
1answer
300 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
82 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 ...
2
votes
0answers
111 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: ...
1
vote
1answer
33 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 ...
1
vote
2answers
67 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 ...
11
votes
1answer
142 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 ...
5
votes
1answer
225 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 ...
3
votes
2answers
60 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
413 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 ...
3
votes
1answer
105 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
130 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 ...
0
votes
1answer
315 views

JDBC wrapper in a functional manner

I implemented a simple Java JDBC wrapper in Kotlin with Arrow functional library. ...
3
votes
1answer
151 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
174 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
320 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 ...
7
votes
1answer
155 views

Avoid incoming meteors

I'm visiting a functional programming course at my university which has a small project for examination. The language we are using is clojure and the contents of the lecture have mostly been about it'...
2
votes
0answers
124 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
2answers
65 views

Loading items for an eCommerce site

I am attempting to make an eCommerce site from scratch. Right now I have the following code that gets all the items from a Firebase Firestore database and then adds HTML into an items div element ...
4
votes
0answers
70 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
69 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
121 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 ...
1
vote
1answer
1k 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
53 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 ...
1
vote
3answers
80 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
35 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
70 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 ...
5
votes
2answers
118 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 ...
3
votes
4answers
118 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 ...
4
votes
1answer
131 views

Lock-free Immutable ConcurrentQueue

Similar to the code review I posted last week for an agent-based immutable replacement for ConcurrentDictionary, I have also created an agent-based immutable ...
7
votes
0answers
102 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 ...
2
votes
1answer
106 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 ...
12
votes
3answers
5k 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 ...
6
votes
1answer
222 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. ...
8
votes
1answer
341 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
0answers
995 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 ...
5
votes
1answer
302 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 ...
3
votes
0answers
211 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 ...

1
3 4
5
6 7
18