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,117
questions
0
votes
1
answer
12
views
Ternary operator not working inside Lambda function Ruby
I am trying to write a Lambda function in Ruby, to calculate the nth Fibonacci number.
fib = -> (n) { n in [1, 2] ? 1 : fib.[n - 1] + fib.[n - 2] }
This gives me the error,
./fib.rb:3: warning: ...
0
votes
3
answers
66
views
building generic property selector / setter in C# if you only know the type at runtime
I'm working with API that want expressions as parameters to identitfy/modify properties on an object. This works fine if I know the type at compile Time. E.g. the APi requires an Expression<Func<...
0
votes
2
answers
71
views
What does "lambda x: x-0 and x-1" mean? [duplicate]
What does the expression do?
my_tuple = (0, 1, 2, 3, 4, 5)
foo = list(filter(lambda x: x-0 and x-1, my_tuple))
print(foo)
What output is to be expected from above equation?
0
votes
0
answers
7
views
Trigger Lambda function every 15 minutes to process Kinesis data by device ID, calculate average, and store in DB
I'm working on a serverless architecture using AWS Kinesis Data Streams and Lambda functions. I want to achieve the following:
Read data from the Kinesis stream in 15-minute blocks, starting from
00:...
-1
votes
1
answer
57
views
LINQ query where clause in list
I am trying to limit the data returned via a repository using the where clause based on a list of values.
I have a PurchaseOrders entity where I want to return all purchase orders that have an ...
1
vote
1
answer
90
views
how to convert lambda function to another one taking tuple of parameters
I need to create a wrapper for lambda function that would take a tuple of parameters of the original lambda function and use its implementation. I'm using C++23 compiler. This is the function I came ...
1
vote
0
answers
36
views
"Leaked in-place lambda" warning after an upgrade to Kotlin 2.0
Consider the following Kotlin code which overloads Reader.useLines(). The 1st extension merely invokes Reader.useLines() and has an exactly the same contract, the 2nd one filters the line sequence ...
3
votes
0
answers
60
views
For function definition, what is the difference between using partial application, a lamba expression or put the arguments next to the name? [duplicate]
What are the differences between the three syntaxes
funName l = map fun l
funName = \ l -> map fun l
funName = map fun
In general it does the same thing however in some cases it differs.
The ...
33
votes
6
answers
3k
views
If a lambda is declared inside a default argument, is it different for each call site?
#include <iostream>
int foo(int x = [](){ static int x = 0; return ++x; }()) {
return x;
};
int main() {
std::cout << foo() << foo(); // prints "12", not "11&...
-2
votes
1
answer
41
views
In Kotlin, is it possible to change the reference in a closure?
The idea is that you pass a lambda to a class and you want to change the implementation after it is passed to the class, but the class does not expose any way to update the lambda's implementation.
As ...
0
votes
0
answers
31
views
How can I sort a dictionary with in the dictionary by the keys of the second dictionary in python? [duplicate]
I have a dictionary as follows:
dict_1 ={'Spain':{'wins':1,'loses':0,'draws':2,'goal_difference':2, 'points':3},'Portugal':{'wins':3,'loses:1,'draws':1,'goal_difference':0,'points':4},'Morocco':{'wins'...
3
votes
0
answers
60
views
How come I can capture an object being constructed in the lambda doing the construction? [duplicate]
Consider the following code:
int x = [&x](){
std::cout << "Inside lambda, x is " << x << '\n';
x = 5;
return 23;
}();
std::cout << "x is " &...
0
votes
1
answer
46
views
Why does Lambda work differently in VSCode and Jupyter Notebook? (python3)
Why doesn't python Lambda work in VSCode? How is VSCode different from Jupyter Notebook?
from Effective Computation in Physics book there is this Lambda example:
(lambda x, y=10: 2*x + y)(42)
...
0
votes
0
answers
66
views
How does the lambda work? How does it know to call the functional interface? I want details because nothing I've seen explains it well [duplicate]
This is in a javafx program and it runs.
button.setOnAction(_ ->{
int side = 0;
Random rand = new Random();
side = rand.nextInt(2);
if(side == 0){
//code here
else{
...
1
vote
0
answers
16
views
how this parameter inside lambda expression is initialized during runtime?
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketHttpHeaders;
...