Skip to main content
388 votes
8 answers
98k views

Recently I started playing around with Python and I came around something peculiar in the way closures work. Consider the following code: adders = [None, None, None, None] for i in [0, 1, 2, 3]: ...
Boaz's user avatar
  • 26.4k
239 votes
9 answers
117k views

I'm trying to create functions inside of a loop: functions = [] for i in range(3): def f(): return i functions.append(f) Alternatively, with lambda: functions = [] for i in range(3):...
sharvey's user avatar
  • 8,245
1778 votes
11 answers
716k views

What is a C++ lambda expression? Why does C++ have them, what problems do they solve that were not solvable prior to their addition? And how can I benifit from using them? Please provide an example or ...
Sarfaraz Nawaz's user avatar
986 votes
26 answers
597k views

I'm trying to figure out Python lambdas. Is lambda one of those "interesting" language items that in real life should be forgotten? I'm sure there are some edge cases where it might be ...
meade's user avatar
  • 23.4k
370 votes
12 answers
314k views

Is it possible to pass a lambda function as a function pointer? If so, I must be doing something incorrectly because I am getting a compile error. Consider the following example using DecisionFn = ...
Cory Kramer's user avatar
515 votes
9 answers
158k views

With () => {} and function () {} we are getting two very similar ways to write functions in ES6. In other languages lambda functions often distinguish themselves by being anonymous, but in ...
lyschoening's user avatar
  • 18.8k
609 votes
23 answers
298k views

Is there a better way to get the Property name when passed in via a lambda expression? Here is what i currently have. eg. GetSortingInfo<User>(u => u.UserId); It worked by casting it as a ...
Schotime's user avatar
  • 16.1k
1874 votes
4 answers
131k views

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 ...
StriplingWarrior's user avatar
173 votes
14 answers
117k views

In JDK 8 with lambda b93 there was a class java.util.stream.Streams.zip in b93 which could be used to zip streams (this is illustrated in the tutorial Exploring Java8 Lambdas. Part 1 by Dhananjay Nene)...
artella's user avatar
  • 5,128
336 votes
10 answers
167k views

I have two expressions of type Expression<Func<T, bool>> and I want to take the OR, AND, or NOT of these and get a new expression of the same type. Expression<Func<T, bool>> ...
BjartN's user avatar
  • 5,557
1160 votes
12 answers
320k views

I understand lambdas and the Func and Action delegates. But expressions stump me. In what circumstances would you use an Expression<Func<T>> rather than a plain old Func<T>?
Richard Nagle's user avatar
398 votes
15 answers
216k views

I'm playing with lambdas in Java 8 and I came across warning local variables referenced from a lambda expression must be final or effectively final. I know that when I use variables inside anonymous ...
alex's user avatar
  • 11.5k
851 votes
24 answers
414k views

For a person without a comp-sci background, what is a lambda in the world of Computer Science?
Brian Warshaw's user avatar
676 votes
19 answers
417k views

Using reflection, how can I get all types that implement an interface with C# 3.0/.NET 3.5 with the least code, and minimizing iterations? This is what I want to re-write: foreach (Type t in this....
juan's user avatar
  • 82.3k
1168 votes
19 answers
962k views

I have a list that I want to filter by an attribute of the items. Which of the following is preferred (readability, performance, other reasons)? xs = [x for x in xs if x.attribute == value] xs = ...
Agos's user avatar
  • 19.6k

15 30 50 per page
1
2 3 4 5
260