Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

15
votes
0answers
151 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
613 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
91 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
297 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 ...
5
votes
0answers
73 views

Extending functions to tuples

Intro: Imagine you have defined addition on types A and B with function A add(A,A) and <...
5
votes
0answers
297 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 ...
4
votes
0answers
17 views

Typescript monad for data being loaded

I have been struggling to make typescript happy about the types. I am pulling data from our backend API and I wanted to give context to the data. Basically it is a monad with 4 shapes: Initial (...
4
votes
0answers
65 views

Merge Intervals in JavaScript

This task is taken from Leetcode - Given a collection of intervals, merge all overlapping intervals. Example 1: ...
4
votes
0answers
54 views

Given a string containing just parentheses, determine if the input string is valid

The task is taken from leetcode Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: ...
4
votes
0answers
58 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
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). ...
4
votes
0answers
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? ...
4
votes
0answers
81 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
131 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
73 views

childrenCount function in old and functional styles

I'm trying to transition myself from my old coding-style (if-else, for.. in) to functional programming. I've tried to update the ...
4
votes
0answers
124 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
45 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
60 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
0answers
233 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
91 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 ...
3
votes
0answers
150 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
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? <...
3
votes
0answers
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 ...
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
119 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
270 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
78 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
150 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
235 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
504 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
57 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 ...
2
votes
0answers
68 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
31 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
33 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
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 ...
2
votes
0answers
94 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
86 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
55 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
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 ...
2
votes
0answers
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 ...
2
votes
0answers
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 ...
2
votes
0answers
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 ...
2
votes
0answers
75 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 ...
2
votes
0answers
154 views

Groovy Map/Reduce for Jenkins DSL

Jenkins DSL doesn't support collect and inject from what I can tell (I get missing method exceptions when I try), so I ...
2
votes
0answers
29 views

Test Driven Development in JS and Sinon Stub

I am going through some TDD and BDD tutorials which guide one through implementing a simple beverage-ordering system. While I think I understand the material, I am still wondering about some ...