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
0
votes
0answers
5 views

Project Euler 1 using functional programming in JS

So I am once again beating a dead horse, this time by trying to dip my toes into functional programming in javascript. I followed the following advice no self-respecting functional programmer would ...
0
votes
1answer
57 views

Simplifying and optimising function logic

I asked the same question on StackOverflow but was told to instead ask here since it was better suited. I have a function that I implemented. It is doing a lot of heavy lifting. I would like to ...
-1
votes
0answers
43 views

What would adding a state accumulator to my simple framework solve/add?

I've created a simple node modules that allows displaying a matrix of characters in the terminal, as well as capturing keypresses. The purpose of the tool is to make simple games like snake, space ...
3
votes
2answers
79 views

Python – return list (or not?) of prime numbers between two numbers

I'm trying to learn how to write code well in Python. I've been tinkering with a function that will return a list of all prime numbers between the two parameters. This is the best I could come up with ...
2
votes
1answer
37 views

map multiple functions to a single input

map is a builtin function that takes one function func and one or more iterables, and maps the function to each element in the ...
3
votes
2answers
80 views

Haskell Function to get the List representation of an Integral

This is a simple practice problem. The task is to write a function getLR that receives an Integral, ...
4
votes
1answer
59 views

Add result-logging to any function

I'm writing a simple function to transform functions by logging the result before returning it. The function as written by me: ...
1
vote
2answers
85 views

Scala Parentheses Balancing in Functional Programming

I was working on the problem to check if the parenthesis are balanced using Scala. Examples: balance("(Hello (my) name is (StackOverflow))") -> ...
10
votes
4answers
1k views
2
votes
0answers
70 views

Deserialize a binary breadth-first in functional programming

A while back, I answered this question on Stack Overflow that involved deserializing a binary tree breadth-first using functional programming (the question itself isn't relevant). I'd like to make ...
1
vote
1answer
34 views

Using Functional programming to untangle deeply nested loops (Kotlin)

Problem statement for better understanding: Let's say we assign a unique number to each alphabet, a=1, b=2, c=3...z=26 then find the frequency of the sum of each ...
1
vote
0answers
37 views

Count number of days within each date range in a list of date ranges

Happily picked up Haskell a couple days back and working on the following use case. Given a list of JSON objects with date fields and a start date, I want to create a list of weeks (here a tuple of ...
2
votes
2answers
106 views

Streaming substrings of a string

Given a (long) string src, generate substrings (up to) len characters long on demand by iterating over ...
2
votes
1answer
74 views

Dose tracker with daily and weekly totals

This is an old script I made a while ago. What it does It tracks your dose of whatever you want tracked (cigarettes, salt, etc), outputs the total for each day, and the full week. What I’m looking for ...
2
votes
1answer
94 views

Find if a dataset of words contains any words containing all vowels by using exactly 5 calls to str_detect

Take the words dataset from stringr. An R4DS exercise challenges the reader to check if there are any words in that dataset that ...
3
votes
2answers
44 views
3
votes
1answer
62 views

Print each word of a sentence in a new line

this is my first F# program, very simple concept but took me a few minutes to get it. I'm new to functional programming so I'd appreciate if you could have a look ...
1
vote
1answer
61 views

Format multiple dates to look good in text, using functional approach

I had a piece of code that solved really simple problem - it formated two dates to look better on a webpage. It looked like this: ...
3
votes
1answer
36 views

Finding the difference between the estimated value and the true value in a reward task

I have this function called error, which estimates value based on previous value and rewards in trials. The difference between the estimated value and true value is then calculated, giving the error. ...
-1
votes
1answer
46 views

Factorise numbers

I've started learning Clojure a few days ago and I wrote this code that factorises numbers. How do I make it better? Is there any way to avoid doing it with a loop? Is that how I am supposed to code ...
2
votes
3answers
62 views

Is My Function to Find Triplets in Scala running in O(N^2)

Given the classical problem to find triplets that sum to zero in an array. Is my Scala implementation correct and executed in O(N^2)? If yes, why? Can someone make a running time analysis. What other ...
0
votes
0answers
38 views

Dominos [Python] CLI Game

Most concerned with improving efficiency and eliminating redundancy than anything else. a lot of Dominos rules have not been implemented yet. Any form of feedback is appreciated. ...
7
votes
1answer
154 views

A beginner's brainfuck interpreter in Haskell

I am rather new to haskell, and could use some feedback on my code and the decisions I had to make. In my previous project, I made a JSON parser, but relied heavily on guidance from a university ...
0
votes
2answers
50 views

Functional Programming Style in Javascript Picking a Random Item from an Array

I'm trying to understand the Functional Programming Paradigm (or style) implemented with Javascript. There are a few things I have difficulties with. The naming conventions, and dependency injections. ...
1
vote
1answer
29 views

“filter” function in Scheme

I know this is a bit elementary, but I am highly uncomfortable writing Scheme code, and I want to make sure that what I'm doing is good practice. I know mutation is frowned upon in Scheme. I have no ...
1
vote
1answer
25 views

Retrieving first non-private ip for local system in elixir

I've recently started learning elixir, and the following is my attempt at fetching the local IP address of the system. It can definitely be improved further, but as this would be my first ever project ...
1
vote
1answer
141 views

Tic Tac Toe (Haskell)

I implemented tic-tac-toe in Haskell. I'm trying to incorporate suggestions from my last question (which mostly revolved around algorithmic logic) while trying something new - IO logic. What kind of ...
4
votes
2answers
200 views

Connect-Four winner-checking algorithm

I'm trying to practice some functional techniques. I haven't worked much in Haskell, so any language-specific tips would be very appreciated, but what I care for even more are general tips towards my ...
2
votes
1answer
200 views

A Stateless Immutable Event-Driven DDD Pattern in Kotlin

I've been interested in making fully repeatable, reproducible game states. This led me into the world of DDD, and specifically, the concept of Aggregates + Event Sourcing (although that's not ...
4
votes
3answers
361 views

Split function using C and dynamic memory allocation

I have programmed a function to split strings, and it gives the expected output. I am looking forward to write better code and I was told here is a good place to start. Here's my program: ...
0
votes
0answers
47 views

Efficiently calculate value of Pascal's Triangle using memoization and recursion(updated)

Follow up to Efficiently calculate value of Pascal's Triangle using memoization and recursion Based on feedback given by jvwh in the answers ...
3
votes
1answer
61 views

Efficiently calculate value of Pascal's Triangle using memoization and recursion

So reading about functional programming, applications to dynamic programming, and learning Scala. I figured I would try it out with a popular example, Pascal's Triangle, tests against known values ...
1
vote
1answer
53 views

Abstracting device IO / glue logic in a CPU emulator

In my Motorola 6809 CPU emulator (written in C++14) I'm working on an abstraction to represent the wiring between emulated devices, such as the ports on a 6522 VIA, or the interrupt lines connecting a ...
3
votes
2answers
105 views

Scraping Premier League results

I have a code that scrapes list of URL and appends dataframe as below: ...
0
votes
0answers
32 views

Typescript from Class to functional programming

I have a following abstract class Listener which encapsulates boiler plate code for a client. I can then have multiple listener for various events. As a self ...
5
votes
1answer
66 views

Two player random number guessing game

I've created a two-player number guessing game in Haskell. My main objective was to practice dealing with "state" in a purely functional language (such as player scores, whose turn it is, ...
3
votes
0answers
74 views

Dynamic text rendering from form data, Express proxy server API requests, and validation in React

I've created a Node.js/Express application that accepts personal data in a form on the front end with React (name, address, etc). It's purpose is to take a user's name, address, and some other info ...
0
votes
0answers
35 views

Optimize Yahoo Finance Code for Analysis

I am trying to analyze a number of companies using financial data I gathered from Yahoo Finance. I am also using the yfinance API to get some more details about the company using functions. Since I am ...
7
votes
3answers
183 views

JavaScript OOD: 2048

I wrote a 2048 game in JavaScript with an object-oriented paradigm. The game board is presented with a two-dimensional array and each tile holds an integer. Here is the implementation: ...
0
votes
0answers
24 views

Python Stack Datastructure

I attempted to implement a stack based on functional programming. Specifically, the idea is to allow structural sharing to reduce space usage. To do structural sharing, I added a unique key for the ...
2
votes
0answers
72 views

Partial Function composability in Haskell

Below is my solution for the CTFP chapter 4 challenges which essentially involves composing partial functions (that don't have defined outputs for all possible inputs i.e. returning a Maybe). The ...
2
votes
0answers
29 views

Testing a javascript function that performs side effects

Application context I am working on a game I call "Apes and Snakes". So far the code only allows players to connect to a host using a room code and WebRTC. Players and the host send messages ...
1
vote
1answer
61 views

“Sequence full of colors” challenge on HackerRank

This is the challenge: You are given a sequence of N balls in 4 colors: red, green, yellow and blue. The sequence is full of colors if and only if all of the ...
1
vote
1answer
45 views

Processing CSV files with filtering

I have 4 CSV files that i need to process (filter out Part segment and then merge them) but the problem is that they do not fit in my memory. So I decided to: [open - filter - write out] each one of ...
0
votes
1answer
74 views

JS create array by comparing 2 dictionaries

I have 2 dictionaries that I have to compare, if an element of one dictionary exists in the other dictionary, then add the element to an array but only one time... here the working code ...
2
votes
0answers
62 views

Making std::optional a monad via SFINAE

To practice with SFINAE, template meta programming, functional programming and monads in C++, I decided to try writing a skinny version of the two functions (monadic binding and return) that make <...
1
vote
0answers
103 views

Dplyr friendly function for computing moving average

Background The function computes moving arrange and offers some other minor widgets like possibility to return data frame in original order or automatically derive variable name for the moving average....
3
votes
2answers
469 views
5
votes
2answers
87 views

sum of multiples by 3 or 5 using ranges

This program calculates the sum of all integers in the range \$[1, 1000)\$ which are multiples of either 3 or 5 or both. Inspired by x86-64 Assembly - Sum of multiples of 3 or 5 the other day, and ...
2
votes
1answer
203 views

Alternatives for checking if something is not None in Python [closed]

I recently bumped into dry-python/returns, which seems like a very useful project. In the project description, the authors describe a snippet which can be written with their ...

1
2 3 4 5
20