The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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.

95 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
15
votes
0answers
155 views

Timeoutable computations module

Defines a simple module for timeoutable computations, with the ability to return arbitrary intermediary results on timeout or the final value otherwise. It also allows default return values. The ...
10
votes
0answers
736 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 ...
7
votes
0answers
95 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
0answers
1k views

Flask view dependency injection

so, first of all, I've been into trying to have a simple dependency container as possible in python and with your help managed to get conceive https://github.com/dareenzo/tinydic, many thanks. Now, I ...
6
votes
0answers
75 views

Extending functions to tuples

Intro: Imagine you have defined addition on types A and B with function A add(A,A) and <...
6
votes
0answers
341 views

Kattis problem Amanda Lounges

I wrote this solution to Kattis problem Amanda Lounges in Scala. TL;DR: It's a graph theory problem where I read in a list of edges from stdin and try to compute the minimum number of nodes that ...
6
votes
0answers
325 views

A* Algorithm in F#

Inspired by this post I looked up A* on wikipedia and went on with my own implementation as seen below where I try to mimic the pseudocode on Wikipedia but in a recursive manner. I would like any ...
6
votes
1answer
230 views

Voting app in JavaScript using Ramda

I'm just learning functional programming in JavaScript using Ramda. I took this tutorial and implemented the server core.js component using Ramda. The idea is that we'll have a collection of ...
4
votes
0answers
64 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 ...
4
votes
0answers
50 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). ...
4
votes
0answers
58 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? ...
4
votes
0answers
84 views

Simple wrapper function grouping and summarising variable

Background I've wrote a trivial wrapper function summarising variable by group for dplyr. I would like to handle quosures more efficiently. In particular, I've a hunch that ...
4
votes
0answers
137 views

Extensible factory method for starting D3 charts

I'm working on refactoring some existing code to be a bit more extensible and am wanting to create a generic factory API for starting D3 charts. Currently, my factory looks like this: ...
4
votes
0answers
128 views

Refactored version of Okasaki's skew-binomial heaps in Standard ML

In his book, Purely Functional Data Structures, Chris Okasaki provides an implementation of skew-binomial heaps (p. 137). Unfortunately, the book isn't (legally) freely available anywhere, but his ...
3
votes
0answers
46 views

Node Based Code Flow Builder

Background In my development of a game engine, I realized the need to be able to construct processing units in a serializable way (code below does not show serialization, just the wiring). I broke ...
3
votes
0answers
91 views

Async in Railway Oriented Programming in F#

In F# the Railway Oriented Programming pattern can be implemented synchronously using the Result<'t,'terr> type as result value for functions, so they can be ...
3
votes
0answers
50 views

Generic Variable Elimination with multiple entry points

I have this algorithm, called Variable Elimination, which is used quite often in my code-base (library). It is an algorithm for factor graphs (a type of bipartite graphs), used to efficiently maximize ...
3
votes
0answers
70 views

Naive Implementation of A Least Recently Used (LRU) Cache Memoiser

I wrote code to (naively) perform lru memoisation. I tried to write it in a functional programming style, and so did not make use of any global variables. My Code ...
3
votes
1answer
128 views

React.js Nested Nav Bar

This was written for a coding challenge for a company I recently starting working for. I'm looking for any suggestions on how to clean up the code, as well as any issues anyone thinks may occur as it ...
3
votes
0answers
269 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
0answers
187 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
0answers
290 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? <...
3
votes
0answers
41 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 ...
3
votes
0answers
76 views

Functional Merge Sort in Python with only boolean variables to control fall off logic

Merge Sort I have just implemented this merge_sort, and this is also my first algorithm implemented in Python, I am totally open to feedback about how to better use python. I am using Arrays instead ...
3
votes
0answers
124 views

React.JS functional paradigm

I have some (minimal) experience with the functional programming paradigm and I'm new to React.js and reactive programming. I'm trying to get a flavour for the React.js philosophy and I keep seeing ...
3
votes
0answers
286 views

Two reimplementations of the Underscore _.reduce function

I am working on rewriting the underlying code for some Underscore.js functions. Re-writing the reduce function has been causing a lot of headaches. I have been able to re-write it two different ways, ...
3
votes
0answers
80 views

OAuth 1.0 signature using Ramda

I created an OAuth 1.0 signature generator using Ramda based on this. I'm just getting to grips with it, so was wondering if someone more familiar with Ramda and functional programming would give me ...
3
votes
0answers
82 views

Calculating a snowballing investment

I'm currently taking a JavaScript class. I'm fairly familiar with JavaScript and coding in general, so I decided to teach myself functional programming on the side. It's been great, my teacher's fine ...
3
votes
0answers
160 views

Functional Merge Sort

I just finished this Merge Sort in Clojure, structured according to ex. 22-26 of this workshop. The main question I have can be answered without spending time understanding the code: ...
3
votes
0answers
46 views

Reformatting a structured string like “a-b-c|A-B-C” into “a-A|b-B|c-C”

The code below was inspired by this post in Code Review. Here is how it was first intended by its author: I have the following code that converts a string that looks like : aaa-bbb|ccc-ddd|eee-...
3
votes
0answers
319 views

Functionally Typed I/O Streams

I thought up a function that provides types with InputStream and OutputStream: ...
3
votes
0answers
241 views

A solution to the AST Typing Problem

Expression trees are the bread and butter of functional programming but when it comes to adding additional information to an established tree it can be difficult to incorporate such changes without ...
3
votes
0answers
521 views

Parsing and producing sets of financial CSV files

I have this small Haskell script that I wrote some time ago to parse a set of financial CSV files to produce other CSV files. I've recently had a problem with large input files (around 300Mb) that I ...
2
votes
0answers
19 views

Reorder items in a map

I'm attempting to create a Module, I've called it Timeline, that resembles a drag n' drop list. Given a Timeline, someone could continually add items (I'm not including removing or updating Items here)...
2
votes
0answers
76 views

Kaleidoscope Effect App

I've written a simple app that draws with a kaleidoscope effect in javascript, could someone please review the code? I'm especially interested in functional practices and design patterns. ...
2
votes
0answers
54 views

A tiny library implementing the Elm Architecture in C++

Elm is a pure functional language for the front-end. It enforces an architecture that allows programs to stay pure in an event-based setting. This simple header-only library implements a variant of ...
2
votes
0answers
83 views

Determine whether there exists a one-to-one character mapping from one string to another

The task Determine whether there exists a one-to-one character mapping from one string s1 to another s2. For example, given s1 = abc and s2 = bcd, return true since we can map a to b, b to ...
2
votes
0answers
94 views

Sort a list using a reverse helper function

The task: Given a list, sort it using this method: reverse(lst, i, j), which reverses lst from ...
2
votes
0answers
32 views

Finding first duplicated value from “circular” list with a recursive function

Background This year I've taken on the challenge of Advent of Code. The second challenge of the first day is to calculate a frequency for a special device based on a series of numbers. Here's a quote ...
2
votes
0answers
36 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 ...
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 ...
2
votes
0answers
101 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: ...
2
votes
0answers
101 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 ...
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 ...
2
votes
0answers
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 ...
2
votes
0answers
94 views

Deep filter value using functional programming principles

deepFilter function uses a predicate to filter properties which may be nested deeply in the given ...
2
votes
0answers
133 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 ...
2
votes
0answers
324 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 ...
2
votes
0answers
86 views

React - Higher Order Component

My first go at a Higher Order Component in react. Aims to give a component the ability to call an url repeatedly with a given refresh interval. Seems to be working as I want. I'm not 100% confident ...