Questions tagged [functional-programming]

Use this tag for programs where "functional" style is important - likely making use of function composition and without side-effects. NOT simply because your code contains functions!

Filter by
Sorted by
Tagged with
0 votes
1 answer
71 views

Move timestamp to the next Monday 10:01 AM

I've been battling ChatGPT for hours now and can't get satisfied with this simple algorithm in TypeScript. These two (hopefully correct) TypeScript+ReactNative solutions should move the timestamp ...
Slazer's user avatar
  • 101
4 votes
2 answers
130 views

Print the three most occurring chars in Java using streams

The three characters that occurs most in a given string should be printed by using streams/lambdas (functional programming). The order of characters that occur equally often should be preserved. My ...
Tobias Grothe's user avatar
3 votes
1 answer
83 views

Sequentially find the indexes of an element into a collection

Util class to find into a collection the indexes of a given element with multiple occurrences from the first index or relative to a given index. ...
user avatar
3 votes
4 answers
1k views

Merging sorted integer arrays (without duplicates)

I have written a Python function called merge_arrays which takes two lists and returns the new list merge without duplicate. The function works as expected, but my ...
XM01 - stands with Palestine's user avatar
1 vote
1 answer
84 views

Simple Curry function

This is a interview practice question from BFE.dev. Currying is a useful technique used in JavaScript applications. Please implement a curry() function, which ...
Christopher Fimbel's user avatar
1 vote
0 answers
43 views

Functional style dependency injection to make business logic unit-testable

My project is a blogging app, which is a recruitment assignment. It is now finished and working. Following function handles updating a comment votes, very similar as on StackExchange sites, preventing ...
jirkamat's user avatar
  • 111
1 vote
2 answers
52 views

Imrove performance when updating DataFrame rows based on complex criteria

My question got rejected the last time so I am trying a better approach to getting a solution: ...
PyNoob's user avatar
  • 21
5 votes
1 answer
121 views

Partial Function Application in JavaScript

I'm trying to make a partial function from any function. Here is a working example: ...
Miroslav Popov's user avatar
1 vote
1 answer
50 views

Click temporization on user interface elements

Implementation to accommodate different behaviours based on the frequency a user interface element is clicked. It supports number of clicks and number of clicks in a time frame. ...
user275176's user avatar
2 votes
1 answer
99 views

Recursive Factorial Calculation in JavaScript

...
XM01 - stands with Palestine's user avatar
3 votes
1 answer
68 views

Dyalog APL dyadic operator deriving ambivalent function to pair two function results

I'm writing a small utility operator which applies two functions to an argument pair and strands the results. The pair can either be given as two arguments or as a single argument with two elements. ...
Adám's user avatar
  • 656
1 vote
0 answers
57 views

LeetCode 399 Evaluate Division using Scala

In order to gain familiarity with Scala I am trying to solve the following problem https://leetcode.com/problems/evaluate-division/description/ You are given an array of variable pairs equations and ...
ThePunisher's user avatar
1 vote
2 answers
173 views

Removing Elements from an Array Based on a Second Array

I've written a function that takes two arrays of integers as input and removes all the elements in the first array that are also present in the second array. I would like to share my code with you and ...
XM01 - stands with Palestine's user avatar
0 votes
1 answer
45 views

Optimizing the Dig Pow function

I have written a Python function to solve the Dig Pow problem, where the goal is to find a number k such that the sum of each digit of n raised to a specific and ...
XM01 - stands with Palestine's user avatar
6 votes
5 answers
1k views

Optimizing a function to find the closest multiple of 10

I have written a Python function called closest_multiple_10() which takes an integer as input and returns the closest multiple of 10. The function works as expected,...
XM01 - stands with Palestine's user avatar
1 vote
0 answers
53 views

Binary tree zipper with basic operations

I am looking for a review of my Binary Tree Zipper implementation on Ocaml. These are the defined operations: get (gets the substructure, or the trees after the focus element) bempty creates an empty ...
V_head's user avatar
  • 525
0 votes
1 answer
36 views

Creating functions in a hierarchy where they get the same arguments

When I write code, I tend to follow functional paradigms often. The main thing I try to do is use values returned from functions. What I notice though, is I end up having a sort of function argument ...
Vinn's user avatar
  • 119
2 votes
0 answers
39 views

Lazy evaluation vs strict one applied to fib

I have this OCaml problem: Recall the polymorphic type lazy seen in class, the function delay which transforms a ...
V_head's user avatar
  • 525
5 votes
1 answer
874 views

Monad object in C++

Have I defined a Monad object for C++? Below is a class called var which I created years ago to implement a lambda calculus like interpreter in C++. The class ...
StormCrow's user avatar
  • 369
4 votes
7 answers
261 views

Breaking a string expression in operator and operands

Requesting for a code review for a scala implementation. Problem Given an expression string made of numbers and operators +,-,/,* , break it in a list of Integer or ...
vikrant's user avatar
  • 385
4 votes
2 answers
141 views

Abundant number implementation

I have implementted a simple JavaScript function to find the list of abundant numbers and print them on the screen. an abundant number is a number for which the sum of its proper divisors is greater ...
Toby Harnish's user avatar
1 vote
1 answer
65 views

Transform an array into object and set index for an unique key in javascript

I have a method that merges keys and indexes from an array into an object. I'm stuck with ways to compress this method, and I don't know what I can do to make it simpler. Goal get an array of objects ...
wittgenstein's user avatar
1 vote
0 answers
56 views

A Haskell-style "maybe" type in Python, version 2

I have decided on a preferred solution to my question A maybe type in Python. Which implementation is best?, and have expanded it to be more ergonomic. I have implemented a host of utility functions (...
schuelermine's user avatar
1 vote
1 answer
43 views

Reactjs Component Reusability

I am working on a project in react. Where most of the data on different tabs have a table. So I design the "TableItems" component and passed the data according to the component. Right now ...
Hamid Shah's user avatar
-2 votes
1 answer
923 views

Create a function with two parameters: a list and a string, where the string has the following values [closed]

I tried so many things to do this task. I have no idea why doesn't it work. Please help! ...
user's user avatar
  • 1
1 vote
1 answer
72 views

Meta Collatz Sequence

Context Chapter 6 of Learn You A Haskell contains a function called chain, which outputs the Collatz sequence of a given input. (In short, it takes a natural number....
Jessica's user avatar
  • 818
1 vote
2 answers
194 views

Simplify a function which performs manipulation of data in Javascript

Upon suggestion in the original question within Stack Overflow, I'm bringing my question here. We have created a function that will convert the data into the desired format, but it has a lot of code ...
SDK's user avatar
  • 113
1 vote
1 answer
50 views

Random ladder for public-key encryption

...
Pierre Abbat's user avatar
2 votes
1 answer
109 views

Project Euler 11 Haskell - Largest product in a grid

Intro I have been learning haskell and functional programming using random Project Euler problems. Currently, I have solved Problem 11. What is the greatest product of four adjacent numbers in the ...
Naitik Mundra's user avatar
3 votes
2 answers
488 views

MP3 Playlist Class in Python

Background Info I am an intermediate level Python programmer. This is my implementation of a MP3 Playlist class challenge that was hosted on 101 Computing.Net. The ...
Seraph776's user avatar
  • 191
2 votes
1 answer
165 views

Commented Parser Combinators in Lisp-style C

I've attempted to remedy the issues outlined in the answer to my previous question. I've added several hundred blank lines to better illustrate the grouping of functions and generally make things look ...
luser droog's user avatar
  • 2,008
2 votes
1 answer
140 views

Parser Combinators in C redux

A few more rewrites down the line from my previous question, this is the C version 11 based on the PostScript prototype version 12. The PostScript version is shorter, but it's some crazy ass ...
luser droog's user avatar
  • 2,008
1 vote
0 answers
49 views

Reusable and testable JavaScript code for URL fragment-based tab navigation logic

Foreword As a personal project, I've been creating a SPA blog (available here), which features 4 tabs (Thoughts, Projects, Readings, and CV), each accessible via one of four radio buttons, and several ...
Enlico's user avatar
  • 547
1 vote
2 answers
80 views

UPDATE on Newspaper Bill Calculator CLI with Python (1 of 3, Core)

Code is posted after explanation. Due to the size of the project, this is being posted in three separate posts. This also ensures each post is more focused. Post 2 of 3, CLI: UPDATE 1 on Newspaper ...
eccentricOrange's user avatar
1 vote
0 answers
48 views

Testing whether one interval overlaps other intervals

I recently started to learn functional programming and wan't to know If I'm doing things right. I use @effect-ts/core lib as well as ...
Roman Mahotskyi's user avatar
1 vote
1 answer
569 views

Functional Fibonacci in OCaml

I'm very new to OCaml, and as an exercise I decided to implement the nth Fibonacci algorithm (return a specific Fibonacci number, given an index) in different ways, using what I've learned so far. I ...
NPN328's user avatar
  • 751
2 votes
1 answer
101 views

Newspaper Bill Calculator CLI with Python (1 of 3, Core)

Code is posted after explanation. Due to the size of the project, this is being posted in three separate posts. This also ensures each post is more focused. Post 2 of 3, CLI: Newspaper Bill ...
eccentricOrange's user avatar
1 vote
1 answer
110 views

Convert from get response to array of type

I would like to know if this is the best/most efficient/industry standard way of converting from the http response to an array of typed values: Type class: ...
Matt W's user avatar
  • 157
0 votes
1 answer
233 views

Fizzbuzz Solution - complexity, readability, performance, lines, obfuscation... - .sort()

The fizzbuzz challenge presents a lot of interesting questions for 'intermediate' programmers like myself. I have found that I don't actually know where to draw the line with, complex (hard to read ...
Dat Boi's user avatar
  • 111
4 votes
1 answer
650 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: ...
pxeger's user avatar
  • 143
1 vote
1 answer
274 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? ...
Erik Bent's user avatar
2 votes
1 answer
111 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 ...
Jae Bradley's user avatar
  • 1,845
4 votes
0 answers
211 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 ...
HariHaravelan's user avatar
2 votes
2 answers
312 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 ...
Jae Bradley's user avatar
  • 1,845
5 votes
1 answer
298 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 ...
Apelli's user avatar
  • 87
-1 votes
1 answer
227 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-...
Metwesh's user avatar
  • 11
2 votes
1 answer
218 views

functor chaining function for c++20

How might chain_apply() be improved? ...
user1095108's user avatar
  • 1,414
3 votes
0 answers
250 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 ...
Adam Hodgson's user avatar
4 votes
2 answers
2k 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, ...
Gibberish's user avatar
  • 109
4 votes
0 answers
51 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 ...
RUser4512's user avatar
  • 1,033

1
2 3 4 5
20