Skip to main content
The 2024 Developer Survey results are live! See the results

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.)

5 votes
1 answer
76 views

Inaccurate compile-time computation of Fibonacci sequence in a recursive lambda

Below is a recursive lambda expression that can compute the values of Fibonacci sequence both in runtime and during constant evaluation: auto fib = [](this auto && f, auto && p) { ...
276 votes
8 answers
165k views

Is it possible to type hint a lambda function?

Currently, in Python, a function's parameters and return types can be type hinted as follows: def func(var1: str, var2: str) -> int: return var1.index(var2) Which indicates that the function ...
0 votes
0 answers
19 views

Read Large JSON File and Flatten Lambda

I have a lambda function that reads in a json file and flattens it so that I can convert it to parquet and it'll be easier to read the data. The issue I'm having is that some of the files are too ...
0 votes
0 answers
14 views

AWS Lambda python log file is not created

I have a Python AWS lambda with a logger that generates two different log files: LOG = f"/tmp/{uuid.uuid1()}_log.log" SLOW_LOG = f"/tmp/{uuid.uuid1()}_slow.log" logging....
1 vote
1 answer
2k views

Serverless AWS Access-Control-Allow-Headers in preflight response

For some reasom this error appears from nowhere: has been blocked by CORS policy: Request header field x-company-id is not allowed by Access-Control-Allow-Headers in preflight response. Here is my ...
19 votes
8 answers
12k views

Why would one write a C++ lambda with a name so it can be called from somewhere?

Why would one write a C++ lambda with a name so it can be called from somewhere? Would that not defeat the very purpose of a lambda? Is it better to write a function instead there? If not, why? Would ...
5 votes
3 answers
1k views

Java8 How to convert 3-level nested list into nested HashMap using stream and lambda

I'm trying to convert a 3 level nested list into Nested HashMap. The function declaration for the same is: Map<Key1, Map<Key2, List<String>>> transformToMap (List<Obj1> ...
-2 votes
0 answers
62 views

Why is static lambda constructed more than once in cpp? [duplicate]

Run this code: #include <iostream> void Func(size_t i) { static auto lambda = [&i]() { std::cout << i << std::endl; }; lambda(); } int main() { for (...
19 votes
4 answers
90k views

Java 8: How to write lambda stream to work with JSONArray? [duplicate]

I'm very new to Java 8 lambdas and stuff. I want to write a lambda function that takes a JSONArray, goes over its JSONObjects and creates a list of values of certain field. For example, a function ...
0 votes
2 answers
195 views

Predicates and functions

public static void main(String[] args) { List<String> strings = Arrays.asList("a", "b", "c", "d"); strings.stream() .filter(s -> ...
0 votes
0 answers
88 views

Does the C++ standard library have function types that are non-copy-constructible?

I want to pass a bunch of lambdas around without having to make copies. This is the declaration of one of the lambdas [ promise = std::move(promise), namedSeries = std::move(namedSeries) ] ...
2 votes
2 answers
1k views

How does lambda function work with reduce function in python?

I'm trying to understand the following code: >>> print(reduce(lambda x, y: x + y, [1,2,3,4,5])) 15 What is x and y? Which is the accumulator here? Does the accumulator always has to be the ...
10 votes
3 answers
3k views

lambda function of another function but force fixed argument

I just switched to Python from Matlab, and I want to use lambda function to map function f1(x,y) with multiple arguments to one argument function f2(x) for optimization. I want that when I map the ...
-2 votes
2 answers
69 views

Clarity on Java Lambda Syntax [duplicate]

From my understanding, this is a single statement in Java: while((x % p == 0l) && (x > p)) x /= p; If that is the case, why is this a syntax error: final AtomicLong subtotal = new ...
1866 votes
4 answers
122k views

Is there a reason for C#'s reuse of the variable in a foreach?

When using lambda expressions or anonymous methods in C#, we have to be wary of the access to modified closure pitfall. For example: foreach (var s in strings) { query = query.Where(i => i.Prop ...

15 30 50 per page
1
2 3 4 5
2016