All Questions
Tagged with lambda functional-programming
662
questions
0
votes
1
answer
66
views
Accumulator passing style in C++
I'm trying to emulate (in C++) the accumulator passing style that I learned in SICP (Structure and Interpretation of Computer Programs by Abelson/Sussman). They used Scheme for the their ...
1
vote
1
answer
59
views
C++ Lambdas Capture Only Primitives By Value
I'm writing a function that returns a partial function, where passing in only some parameters of a function returns a new function with some of the parameters filled in.
I currently have this setup:
...
1
vote
1
answer
51
views
Partition by column, order by another
I am simulating a SQL query with the following values:
rows = [(1, '2021/04', 'Shop 2', 341227.53), (2, '2021/05', 'Shop 2', 315447.24), (3, '2021/06', 'Shop 1', 1845662.35), (4, '2021/04', 'Shop 2', ...
-1
votes
2
answers
76
views
lambda function uses member variable and produces different results
I dont know why the code runs without errors. From what I learned, in functional programming, same input results in same output and function's internal state cannot be changed from outside. When I ...
0
votes
1
answer
63
views
Correct way to check for true value without exiting loop in Kotlin
I'm working on a application in Kotlin that needs to iterate over a range, calling a sub-function for each item. The function then returns a boolean indicating if any of the sub-function calls ...
2
votes
0
answers
101
views
'Segmentation Fault' occurred when Lambda Function in Python recurves over 1e5 times
def count_cond(condition):
return lambda x:(((lambda f:(lambda a:f(a(a)))(lambda a:f(lambda *w:a(a)(*w))))(lambda cc: lambda j,m: ((cc(j+1,m+1) if condition(x,m)==True else cc(j,m+1))) if m<=x ...
0
votes
1
answer
60
views
How to use an if statement in a Java stream to avoid a duplicate stream process
Here is my code from the Java MOOC.fi course where I am learning about streams. The code below works but the way I wrote it is quite amateur. I was thinking of somehow integrating an if statement in ...
1
vote
1
answer
58
views
How to customize hash function for pair<int,int> in unordered_set using lambda expression
int main(int argc, const char * argv[]) {
function<bool(vector<int>&,vector<int>&)> cmp=[](vector<int>&a,vector<int>&b)->bool{
return a[0]&...
0
votes
0
answers
45
views
Mapping wild card Function interface to a typed Function interface
I have a number of accessor methods that interrogate various objects and return a Function<Context, ?>, like such:
public static Function<ExmonMessageCtx, Optional<?>> reason() {
...
1
vote
3
answers
474
views
Are (let) and (lambda) equivalent in Common Lisp
I'm reading On Lisp by Paul Graham, trying to better understand the functional style of programming. In Chapter 3, he mentions that functional programs "work by returning values" rather than ...
2
votes
3
answers
335
views
Flattening a list of lists in racket
I'm working on an assignment in Racket (Intermediate Student with lambda) and I'm trying to make a helper function which flattens a list of lists. I'm not allowed to use recursion, nor can I use apply....
3
votes
2
answers
322
views
Does JavaScript allow replacing lambda with "method references"? If not, why not? [duplicate]
I jump between Java and Javascript a lot at work. I also write a lot of functional code, i.e. chains of lambdas.
One thing I like about Java is I can replace a lambda with a method reference. For ...
6
votes
3
answers
1k
views
Java Stream : How to filter conditionally?
I have the following stream statement with Java Stream and I filter records based on the typeId values as types.getIds().contains(x.getType().getId()):
return petRepository.findAll().stream()
...
-2
votes
1
answer
73
views
Lambda Expression simplification
Is \xy.xy the same as \x.x?
I have to simplify an expression as much as possible and I don’t understand if these are equivalent
0
votes
0
answers
28
views
C# Higher-order function to reverse the order of arguments [duplicate]
I am reading the book Functional Programming in C# by Enrico Buonanno (great book).
There is one example for swapping the order of arguments, namely:
static Func<T2, T1, R>
SwapArgs<T1, ...