Questions tagged [lambda]
DO NOT USE FOR THE AWS SERVICE (use [aws-lambda] for those questions!) Lambdas are anonymous functions or closures in programming languages such as Lisp, C#, C++, Lua, Python, Ruby, JavaScript, Java, Excel or Google sheets. (Also, lambda expression.)
lambda
30,325 questions
3
votes
0
answers
86
views
Why does a class inherited from lambda type lack conversion to function pointer in Visual C++?
If a lambda is capture-less, its closure type has conversion operator to function pointer. For example,
...
0
votes
0
answers
48
views
Entity Framework unable to translate IComparable cast of DateTime in OrderBy [closed]
In an effort to simplify some of my code, I tried using a switch expression to create a selector for sorting on an EF Core 10 query:
...
5
votes
1
answer
147
views
MSVC accepts lambda with deleted parameterized ctor while GCC and Clang rejects
I wrote the following program that is accepted by MSVC, but is rejected by both GCC and CLANG. What is the standard compliant behavior?
Live Demo
...
5
votes
1
answer
148
views
Lambda with deducing this parameter of unrelated type [duplicate]
A colleague of mine showed me a program with explicit object parameter in a lambda function. The program is accepted by two compilers, but produces a strange result:
...
1
vote
1
answer
128
views
Is there a difference between 'eval' and sourcing a temporary file?
These two examples accomplish the same thing:
# using eval
var=hello
eval "some_func() { echo $var; }"
some_func # "hello"
...
3
votes
1
answer
109
views
Accessing a lambda's parameter leads to "Assignment type mismatch: actual type is 'Unit', but 'String' was expected"
I'm trying to pass a click handler to a child function that sends a string back to the parent and updates a mutable value based on the string. I'm getting an error on the function:
Assignment type ...
0
votes
1
answer
74
views
Array FILTER/TRANSFORM lambda using index
Snowflake supports higher order functions like FILTER or TRANSFORM.
A lambda expression that defines the filter condition on each array element.
The lambda expression must have only one argument ...
4
votes
3
answers
351
views
Passing a local reference to a closure
Consider the code below:
for (T &t : some_vector_) {
futures.push_back(thread_pool.submit([&t] { t.do_something(); }));
}
On some iteration ...
Advice
0
votes
2
replies
85
views
Method-body equivalent of lambda expression
Following is a part of the execution sequence when a middleware gets configured in ASP.NET Core -
...
2
votes
3
answers
145
views
How to modify mulitple columns applying if else to multiple pandas dataframe columns
I have a dataFrame with columns Age, Salary and others, if I used:
df['Age'] = df['Age'].apply(lambda x : x+100 if x>30 else 0)
Then I can modify the Age column ...
0
votes
0
answers
97
views
Datadog APM traces not appearing for AWS Lambda with Node.js despite metrics working
Problem
I'm trying to set up Datadog APM tracing for my AWS Lambda functions (Node.js/TypeScript), but traces are not appearing in the Datadog APM UI. Custom metrics are being collected successfully, ...
1
vote
3
answers
153
views
Pass QString in Lambda Function
I want to pass a QString into a lambda slot-function to modify it further. Unfortunately the QString goes out of scope before ...
1
vote
1
answer
152
views
Why can't I return type byte in lambda expression in Arrays.setAll
I'm trying to implement a lambda function (for educational purposes) to initiate an array to append to the front of potentially encrypted data to save information like salt and initiation vector, ...
-1
votes
1
answer
55
views
Why are all versions of Lambda@Edge function being modified when I deploy the latest code?
I have a Lambda@Edge function which has 2 versions. Version 1 has non-functional code and version 2 has the latest operational code. What that function does is it fetches an object from an S3 bucket ...
0
votes
1
answer
59
views
Localstack returning error when trying to provision a dotnet8 lambda
I'm trying to provision a lambda on a free localstack instance. As such, I cannot build the lambda as an image and push it into localstack's ECR because ECR is a paid resource. So I'm taking the ...
1
vote
1
answer
58
views
Unexpected behavior when replacing arrow-kt partiallyN function with kotlin lambda
I'm working on updating some Kotlin code that depends on arrow-kt. As part of the migration process from arrow 1.2 to 2.x, I need to get rid of arrow partiallyN() ...
1
vote
1
answer
59
views
Prisma - Sorting by function applied on a column
I want to use a function in my orderBy clause. To my great surprise I can't find a way in the official documentation to do this without executing raw SQL in Prisma. ...
-1
votes
1
answer
128
views
Standard-conformant explicit capture-by-value in lambda expression?
I'm trying to caputure a variable by value into a lambda, and I want to point out the nature of the by-value capture explicitly, as it is essential for my code to work the way it is intended.
My code ...
15
votes
1
answer
1k
views
Why can a lambda passed as an argument be used in a constant expression?
Why does this code compile?
...
2
votes
2
answers
142
views
1
vote
2
answers
134
views
Does SONAR's cpp:S5213 rule imply that functions accepting lambdas must be implemented in the .h file?
SONAR's cpp:S5213 rule says that
Template parameters should be preferred to "std::function" when configuring behavior at compile time
We have tried implementing that by replacing ...
1
vote
0
answers
57
views
Mongodb not available for my AWS Lambda function
I have tried to import mongodb into my lambda function and I keep getting an error message when I attempt to test it. All the recommended resolutions I have seen assume I am working in an environment ...
0
votes
0
answers
37
views
AWS Lambda with pg Pool and RDS Proxy: "Connection terminated unexpectedly" when processing SQS messages
We are using pg Pool in our Lambda function.
Our connectDb function looks like this:
...
0
votes
0
answers
44
views
How do I display my BST using my preorder() and inorder() methods?
I'm doing a programming assignment for my class. One of my programs includes creating a BST with Python within a BST class, and I'm trying to display using preorder() and inorder() functions. My ...
3
votes
1
answer
144
views
Excel LAMBDA + spill
I've created this LAMBDA function and called it STR2ARR (note: yes, I know there are other functions in Excel that can do this, but I'm trying a concept that I want to use in a bigger LET/LAMBDA ...
-4
votes
3
answers
151
views
lambda functions as higher-order functions [closed]
I'm learning about higher-order functions, specifically lambda functions in Python. I understand lambda functions to an extent, but a little confused about this lambda higher-order function example.
...
3
votes
3
answers
162
views
Using Excel Lambda function to count numbers that meet a condition (in conjunction with groupby)
I am trying to write a lambda function for use in a groupby, which counts the total number of failed grades (grades below 6) for each store. However I cannot seem to figure it out.
It seems that there ...
14
votes
1
answer
409
views
Why does a deducing-'this' lambda require `this` to be a reference or capturing variables by reference?
Why does this code output garbage on GCC, like there is UB?
...
2
votes
0
answers
63
views
Rust lambda parameter passing [duplicate]
I just learned that in rust if you want to pass a reference in lambda:
...
1
vote
1
answer
107
views
Diff btw "Invoke( lambda )" and directly calling a lambda when we use Google Mock EXPECT_CALL
Since I learnt to use Google Test/Mock framework, I allways used the form to setup an expectation as following:
...
0
votes
1
answer
126
views
Python lambda returns 0 [closed]
Is there a simple way to return 0 with a lambda function using and and or operators?
For ...
0
votes
0
answers
153
views
Connection Pooling Challenges with MongoDB and AWS Lambda
I'm facing an issue related to MongoDB connections while sending push notifications to users three times a day — morning, noon, and evening.
I have a Lambda-based service that uses SQS and MongoDB. A ...
1
vote
2
answers
152
views
Trying to split parameter pack into two smaller packs using an index sequence and nested lambdas leads to weird compiler behaviors
So I was trying to come up with a way to split a given parameter pack args... into two separate packs args1... and ...
0
votes
1
answer
72
views
How can I pass the input parameter of the AWS Step Function StartExecutionCommand into the event of the first lambdaInvoke state using sst?
I've been facing an issue deploying AWS Lambda Step Functions with sst. I created this minimal GitHub Project to demonstrate the issue. It's not clear to me if this is a bug in the SST implementation ...
0
votes
1
answer
108
views
Image uploaded to AWS S3 getting 404 error
This is my aws config code
...
3
votes
3
answers
251
views
Receiving a lambda through auto&&
If I assign a lambda in C++ with this:
auto&& mylambda = [&](int someparam)
{
some_function();
return 42;
};
Is this wrong? I know that this ...
0
votes
1
answer
193
views
Why is a lambda expression not just the syntactic sugar of a functor?
Consider the following code:
int main() {
int n = 0;
return [n] { return n; }(); // ok
}
According to https://cppinsights.io, the code above will be ...
-3
votes
1
answer
111
views
Excel - Dynamic array FILTER to return ARRAY for Stock Portfolio Cost Tracking
I'm updating a tracking spreadsheet for a stock portfolio and would like to dynamically pull the holdings of the portfolio at specific time periods so that I can view the holdings at any point in time,...
0
votes
2
answers
145
views
Why can a const object call a non-const member function? [duplicate]
Consider the following code:
int main() {
auto const fn = [] mutable {};
fn(); // ok, why?
}
As per the latest C++ standard draft [expr.prim.lambda.closure]...
-2
votes
1
answer
101
views
Is it legal to declare a lambda after the last return in a C# function? [duplicate]
I was looking through the code of AutoMapper ASP.NET Core dependency injection, and in the AddAutoMapperClasses, I saw that they declared a lambda expression after ...
0
votes
2
answers
78
views
EF Core Fluent API to get inheritance properties
How to use EF Core Fluent API to get inheritance properties?
I have a base class and 2 inherited children classes:
...
-2
votes
1
answer
68
views
Linq: Select all items in 1 list where they almost match an item in another list [closed]
I have a list of Objects which have a location [Rect].
I then select from this list, all Rects that fall inside a 'Column' (Left>x1 && Right<x2)
What I need to to now is find all Rects ...
2
votes
1
answer
123
views
What is an efficient alternative to creating dozens of ActionListener implementations in Java?
I'm designing a P2P messaging application using Swing, and have been running into serious issues when it comes to organizing my GUI component ActionListeners. Each <...
0
votes
0
answers
135
views
How do I pass custom headers (X-Content-Type-Options) from AWS Lambda through API Gateway using Lambda Proxy Integration?
I'm working with AWS Lambda function that serves as the backend for an API Gateway endpoint using Lambda Proxy Integration. My Lambda handler is structured like this:
...
-3
votes
1
answer
56
views
Saving unwanted date in database through aws lambda
I am working on lambda project; I am fetching data from a SQL Server database and passing it to an API, and then that data is saved to another SQL Server database table through AWS lambda.
The issue ...
1
vote
1
answer
57
views
Lambda renders stream output to client - how to stop?
I'm streaming a remote pdf to an S3 bucket, but the binary is rendering on the client. Any idea how I modify this code so it doesn't display the pdf on the client?
...
0
votes
1
answer
142
views
1
vote
1
answer
65
views
How to use lambda expressions inside append directly
Apply a lambda function while appending to a list pretty much asks exactly what I want, and the solution there is fine, but I wanted to know if there was a way to directly get the result of a lambda ...
1
vote
1
answer
93
views
Lambda init capture for constness
In this example;
const int x = 10;
auto y = [x=x]() {++x;};
When using init capture in a lambda, does it drop the const qualifier of the captured variable? Here ...
4
votes
1
answer
164
views
Why does a recursive lambda with deduced return type not work?
int main() {
auto fn = []<typename T>(this auto&& self, T n) {
if (n > 0) {
self(n - 1);
}
};
fn(3);
}
...