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!
1,018 questions
0
votes
0
answers
44
views
Spring 7 RouterFunctions and BeanRegistrarDsl med Kotlin
I am looking for a good way to structure my Kotlin code using Spring Boot 4 and Spring 7. The new features I am using are:
Reflectionless dependency injection via ...
4
votes
1
answer
138
views
Higher-kinded types in Rust
Also posted on Reddit.
As a small personal exercise, I'm trying to implement a notion of higher-kinded types in Rust using type-level defunctionalisation based on the "Lightweight higher-kinded ...
5
votes
1
answer
145
views
C# railway oriented programming with async support
In my application there are many business workflows. Most of them are quite simple and can be put in one function. A few of them however are very complex and have many business validations, require ...
2
votes
0
answers
107
views
std::ranges compile time (and run time) RFC 4648 compliant Base16 conversions in C++23 (improved 2)
This increment
This obsoletes a former version, after taking a great review into account:
The encoding now preserves sized_range and ...
4
votes
2
answers
386
views
Compile time (and run time) RFC 4648 compliant Base16 conversions as range adaptors in C++23
This obsoletes a former version and is obsoleted by an improved version.
The following code is an implementation of, in ambition, RFC 4648 compliant Base16 conversions as range adaptors in C++23. It ...
5
votes
3
answers
307
views
HackerRank, Haskell simple "compression" algorithm
The question asked is very straight-forward and is simple enough to solve. What I am looking for is that hopefully I can get some understanding for using the constructs and built-ins of the Haskell ...
3
votes
1
answer
437
views
Event sourcing javascript implementation
An event source built around an observer design pattern implementation…
...
8
votes
1
answer
145
views
Haskell 2-player TicTacToe terminal game
I want to get better at functional programming so I started with this simple 2-player TicTacToe game. Next I want to add a simple min-max algorithm to make it a 1-player game, but before that I'd like ...
3
votes
1
answer
131
views
In Java, replace for loop with condition with lambdas [closed]
I want to replace a for loop with a break/return condition inside with a lambda.
I think I have a good replacement, but I want ...
4
votes
3
answers
265
views
Get the contents of a table cell for all selected rows
I have a table of user info. When you click the button, I want to get the email address from each selected row, output into a comma-separated string.
I got it to work with the following code, but I'm ...
3
votes
2
answers
182
views
Extending callable signature with std::optional in context of function composition (make_skippable)
(Please note: the post about the compose implementation announced below is now available.)
This is about decorating callables by making their argument and return value to be a ...
5
votes
1
answer
142
views
Locate and multiply numbers in a 2D grid (Advent of Code 2023 Day 3, Part 2)
I am using the Advent of Code 2023 to study functional programming and the ranges library in C++. This code is for the second part of Day 3 and is the best solution using FB I've created. I'd ...
2
votes
1
answer
127
views
Move timestamp to the next Monday 10:01 AM [closed]
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 ...
2
votes
1
answer
124
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.
...
2
votes
1
answer
139
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 ...
5
votes
1
answer
165
views
Partial Function Application in JavaScript
I'm trying to make a partial function from any function.
Here is a working example:
...
3
votes
1
answer
167
views
1
vote
2
answers
668
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 ...
7
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,...
0
votes
1
answer
80
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 ...
5
votes
1
answer
952
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 ...
4
votes
2
answers
214
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 ...
3
votes
0
answers
88
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 (...
-2
votes
1
answer
1k
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!
...
1
vote
2
answers
234
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 ...