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
1 answer
119 views

Haskell: implementing Read for a custom dynamic value type

I'm using Haskell to interpret a dynamically-typed language. I have a sum type called Value which can represent some basic objects: ...
user avatar
  • 143
1 vote
0 answers
20 views

Suggestions for improvement for generic array and map functions in Go 1.18

Yesterday I build some generic functions for the new official Golang 1.18 release. What do you think about it and what could be added and improved? ...
user avatar
0 votes
0 answers
13 views

Re-write the aggregation function in scala-based functional style [closed]

I am new to scala and is currently taking a course on scala programming. As part of one of my assignment, I have written the following code to combine customer data with their respective accounts data....
user avatar
0 votes
0 answers
43 views

Stream Partitioner

Discussion I've been trying to increase my knowledge of Java Streams and for practice, I devised up the requirement of partitioning a Stream of values into a ...
user avatar
  • 1,768
3 votes
0 answers
97 views

GeekTrust: Traffic problem - functional programming

First attempt to write functional programming, been following OO paradigm all through my programming journey Please review the code and let me know if any comments and violations of functional ...
user avatar
2 votes
2 answers
71 views

A Union Data Type

Introduction I'm trying to get familiar with functional programming by implementing some functional concepts. One of these concepts that I've attempted to implement below is a ...
user avatar
  • 1,768
5 votes
1 answer
56 views

Validate Finnish IBANs

I am currently studying an online course in Haskell and there are no "model examples" of the assignments after finishing them. I'm slowly getting the hang of this, but I'd like some feedback ...
user avatar
  • 87
-1 votes
1 answer
63 views

Refactoring this code into OOP & less functional programming

I got feedback from an interview test where they wanted me to prove that I've got a grasp of OOP php programming. This file especially I got feedback on that it's more functional than it is Object-...
user avatar
  • 11
1 vote
1 answer
28 views

functor chaining function for c++20

How might chain_apply() be improved? ...
user avatar
  • 1,344
3 votes
0 answers
143 views

Command line wordle

I am seeking a review of my command line wordle game. Having only recently started exploring functional programming, I expect that there will be no shortage of areas to improve. This is my first ...
user avatar
3 votes
2 answers
186 views

Download entire localStorage as file

I would like to download the entire contents from localStorage to a json file (in a "clear" formatting). I've tried this and it works perfectly. However, ...
user avatar
0 votes
0 answers
79 views

Project Euler 1, 2 and 3: Functional Programming style using F#

After doing about 50 Project Euler problems in my "native" language (C#) I decided to redo some of the problems I did many years ago in F#, as it's a language I always want to give a go. ...
user avatar
2 votes
0 answers
11 views

Ocaml add index to every item of a collection

I want to add a unique ID to every element in a collection (before output it as a JSON object). A collection can be any set of items, as long as it has a map method ...
user avatar
  • 973
4 votes
1 answer
128 views

Functools extension library

I wrote a utility library inspired by functools that adds some common operations on functions I frequently use in my projects. As usual I'd appreciate any feed back....
user avatar
0 votes
0 answers
16 views

make an array of cells from formula like in excel with javascript?

I'm working on stylesheet in Excel, and I've made this function of makeCells is there a better way of doing it. I've tried regex to get two cells ...
user avatar
3 votes
1 answer
86 views

Efficiently calculating perfect powers in Haskell

I'm trying to calculate perfect powers to solve this code wars challenge: https://www.codewars.com/kata/55f4e56315a375c1ed000159/haskell The number 81 has a special property, a certain power of the ...
user avatar
3 votes
0 answers
154 views

Advent of Code 2021, Day 3 in Haskell

This is a working solution to today's Advent of Code puzzle, written in Haskell. However, I feel like this solution is not optimal. ...
user avatar
  • 131
2 votes
2 answers
241 views

Improving the Conway's Game of Life Code With Functions in Python

This query is a part of Conway’s game of life. Currently, this program takes about 70 lines of code in Python to return the functionality of the game, which can be simplified to fewer lines of code ...
user avatar
  • 37
0 votes
2 answers
70 views

Processing list of users- filtering out from refused list

The code below takes a list of users and displays two lists Refused users Admitted users Sample output: Refuse: Phil, Lola. Admit: Chris, Anne, Colin, Terri, Sam, Kay, Bruce. Any feedback is ...
user avatar
  • 602
1 vote
0 answers
30 views

Relational join of two datasets

Front Matter I'm learning Scala and have not gotten used to functional programming and the language. I'm hoping a review of my naively implemented code can help me bridge my object-oriented ways to ...
user avatar
  • 111
2 votes
3 answers
141 views

Finds Keywords in Log Files

This is my first project in C and I wanted a more experienced person's insight on how I made the whole program. Just looking for feedback it works how I want it to. The Github is here. Thank you so ...
user avatar
  • 21
1 vote
0 answers
43 views

Higher-order function to do throttling, written two ways

I have used below method for throttling which is a Higher Order Function (HOF), but find some difficulties to choose which one is better way to write it. Below are both methods. return of the ...
user avatar
  • 141
0 votes
0 answers
55 views

Multiple flatMap style: Nested or sequential?

This question applies to any language with flatMap -- e.g. functional languages -- but I'll use an example in JavaScript. I'm working my way through Functional Programming in JavaScript, which is a ...
user avatar
  • 101
2 votes
0 answers
67 views

Download and parse XML data from a URL every minute with F#

The purpose This code is intended to achieve the following goals:- Create a hard coded list of lifts, this is pretty static and I add some extra info so I'm ok with this being in the code but I may ...
user avatar
0 votes
0 answers
75 views

Gilded Rose with pure functions in C#

Gave myself the challenge of solving the Gilded Rose with pure functions in C#. All one-line lambdas, all static, all the time. The original kata assumed the code would mutate the given array-- I've ...
user avatar
  • 216
2 votes
1 answer
54 views

Garden simulator [closed]

I tried to write the program so that it runs without error but I want to improve the program so that it follows the Single Responsibility Principle. What changes can I make to improve this program? I ...
user avatar
  • 21
4 votes
1 answer
331 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 ...
user avatar
  • 207
4 votes
1 answer
365 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 ...
user avatar
  • 207
0 votes
0 answers
44 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 ...
user avatar
1 vote
3 answers
71 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 (...
user avatar
  • 123
3 votes
2 answers
97 views

Split string at given positions

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

TypeScript generic higher-order function returned function returned type

I have a higher-order function to create another function given a regular expression: ...
user avatar
5 votes
1 answer
95 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 ...
user avatar
0 votes
0 answers
27 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 ...
user avatar
-2 votes
2 answers
99 views

Getting items that have more than one entry in the array with optimized code

...
user avatar
  • 123
2 votes
2 answers
282 views

piping a std::tuple into a function

This is a mythical beast we discussed in a previous question: ...
user avatar
  • 1,344
3 votes
1 answer
74 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 ...
user avatar
0 votes
1 answer
51 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 (...
user avatar
2 votes
1 answer
59 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: ...
user avatar
2 votes
1 answer
57 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 ...
user avatar
-1 votes
1 answer
75 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 ...
user avatar
3 votes
2 answers
227 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 ...
user avatar
2 votes
1 answer
62 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 ...
user avatar
3 votes
2 answers
147 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, ...
user avatar
4 votes
1 answer
61 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: ...
user avatar
  • 203
2 votes
2 answers
501 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))") -> ...
user avatar
  • 207
11 votes
4 answers
2k views

Restructuring JSON to create a new JSON where properties are grouped according to similar values

I have a JSON structure in the following example format: ...
user avatar
2 votes
0 answers
80 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 ...
user avatar
  • 499
2 votes
1 answer
104 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 ...
user avatar
  • 153
1 vote
0 answers
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 ...
user avatar

1
2 3 4 5
21