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
4
votes
1answer
261 views

Is there a better way to apply a filter over an Either right value?

Suppose you have an IO (Either String (String, [Int])) and you want to filter the [Int]. Let's say we want to use the following ...
4
votes
1answer
59 views

Reading a CSV file using Haskell

I'm reading a CSV using Haskell. I'm not sure if this is the appropriate way to do it. This is what I'm doing: Read rows from a CSV -> return lazy byte string Parse the headers and rows from the ...
0
votes
0answers
25 views

Typescript Maybe functor

I have been trying to implement a version of the Maybe functor in Typescript. I'm looking for feedback on whether I can improve the type safety of my implementation. I'm not particularly happy that ...
1
vote
2answers
38 views

Word frequency finder

Challenge: find the top three most frequently used words in a string. Only imports from the base package are allowed (source: codewars) I'm looking for feedback on (...
3
votes
2answers
79 views

Split string at given positions

Given a vector <Vec<usize>> of indices indicating where to split a string as follows: ...
1
vote
0answers
20 views

TypeScript generic higher-order function returned function returned type

I have a higher-order function to create another function given a regular expression: ...
2
votes
0answers
48 views

Small combinator parsing library in Haskell

I recently wrote code to parse lambda expressions written in a lisp like format, using a small hand-rolled parsing library. The goal This code was written as a part of this code-golf challenge not as ...
0
votes
0answers
25 views

Refactor Javascript filter that handles click and changing together dropdown filters

I'm looking to rework and make it easier to read this handleFilterChange function This is helper being used in the function ...
0
votes
0answers
29 views

Formatting and displaying the current time in the console every second [closed]

I have been reading the book Learning React: Modern Patterns for Developing React Apps. In Chapter 3, it gets into details about functional programming in JavaScript. At the end of this chapter, we ...
2
votes
2answers
249 views

piping a std::tuple into a function

This is a mythical beast we discussed in a previous question: ...
3
votes
1answer
67 views

garbage string remover with array or object input

This is the second time I am writing any practical JavaScript so it is pretty likely that I have messed something up. I am beginner, so just need a piece of advice before sharing the code: Do I need ...
0
votes
1answer
36 views

Cardinal to ordinal numbers in F# code reuse

I've been experimenting with the F# Bolero environment to learn F# a bit and I was trying to get the hang of pattern matching by generating ordinal numbers (1st, 2nd, 3rd, ...) from cardinal numbers (...
2
votes
1answer
48 views

F# simple monoalphabetic cipher code implementation

I am a new F# programmer, and a student in a security class. As part of my notes, I wrote a small implementation of a monoalphabetic cipher as follows: ...
2
votes
1answer
54 views

Project Euler 1 using functional programming in JS

So I am once again beating a dead horse, by solving the first Project Euler problem: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these ...
-1
votes
1answer
71 views

Simplifying and optimising function logic [closed]

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 ...
3
votes
2answers
106 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
39 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
86 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
60 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
123 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
71 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 ...
2
votes
1answer
42 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
39 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 ...
3
votes
2answers
116 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
75 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
96 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
66 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
37 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
48 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
64 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
52 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
161 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
54 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
30 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
28 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
145 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
205 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
245 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
428 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
49 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
79 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
106 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
67 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
75 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 ...

1
2 3 4 5
20